psygrow-api

module
v0.0.0-...-c020414 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 7, 2025 License: MIT

README

# PsyGrow API - Model Improvements

Changes Implemented

1. Enumerations for Fixed Values

Created constants for fixed values to avoid using strings directly:

  • RepasseModel: RepasseModelClinicPays, RepasseModelProfessionalPays
  • RepasseType: RepasseTypePercent, RepasseTypeFixed
  • AppointmentStatus: AppointmentStatusScheduled, AppointmentStatusDone, etc.
  • PaymentMethod: PaymentMethodPix, PaymentMethodCash, etc.
  • RepasseStatus: RepasseStatusPending, RepasseStatusPaid, etc.

2. Improved Data Validation

Added validation using the go-playground/validator library:

  • String length validations for fields like Name, ServiceTitle
  • Validation for RepasseValue based on RepasseType (percentages between 0-100%)
  • Required field validations
  • Custom validation functions for complex validations

3. Database Indices

Added indices for frequently queried fields:

  • UserID, CostCenterID, PatientID, Status, etc.

4. Explicit Entity Relationships

Improved entity relationships with explicit references:

CostCenterID uuid.UUID  `gorm:"type:uuid;not null;index" validate:"required"`
CostCenter   CostCenter `gorm:"foreignKey:CostCenterID"`

5. Monetary Values

Replaced float64 with int64 for monetary values:

  • Values are stored as cents (e.g., $10.50 = 1050)
  • Percentages are stored as basis points (e.g., 10.50% = 1050)

6. Descriptive Boolean Field Names

Made boolean field names more descriptive:

  • ActiveIsActive
  • ClinicReceivesDoesClinicReceive

7. Improved Documentation

Added detailed documentation comments to structs and fields.

8. Transaction Support Framework

Created a transaction helper framework to support transactions for related operations.

Next Steps

To fully implement these changes, the following additional steps are needed:

1. Update DTOs

Update the DTOs to match the model changes:

  • Change float64 to int64 for monetary values
  • Update field names to match the model changes
  • Add validation tags to DTOs

2. Update Handlers

Update the handlers to use the new model features:

  • Use constants instead of string literals
  • Validate models before saving
  • Use the transaction helper for operations involving multiple tables

3. Update Repositories

Update the repositories to support transactions:

  • Add transaction-aware methods to repository interfaces
  • Implement these methods in repository implementations

4. Update Migrations

Update database migrations to reflect the model changes:

  • Add indices for frequently queried fields
  • Change column types for monetary values
  • Rename boolean fields

5. Testing

Test the changes to ensure they work as expected:

  • Unit tests for validation logic
  • Integration tests for database operations
  • End-to-end tests for API endpoints

Directories

Path Synopsis
Package docs GENERATED BY SWAG; DO NOT EDIT This file was generated by swaggo/swag
Package docs GENERATED BY SWAG; DO NOT EDIT This file was generated by swaggo/swag
src
cmd/api command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL