diff --git a/backend-old/internal/domain/models.go b/backend-old/internal/domain/models.go index bc47aed..f66d9b7 100644 --- a/backend-old/internal/domain/models.go +++ b/backend-old/internal/domain/models.go @@ -6,9 +6,13 @@ import ( "github.com/gofrs/uuid/v5" ) +// CompanyID and UserID are UUIDv7 identifiers for performance-friendly indexing. +type CompanyID = uuid.UUID +type UserID = uuid.UUID + // Tenant represents a B2B actor (pharmacy/distributor) in the marketplace. type Tenant struct { - ID uuid.UUID `db:"id" json:"id"` + ID CompanyID `db:"id" json:"id"` CNPJ string `db:"cnpj" json:"cnpj"` CorporateName string `db:"corporate_name" json:"corporate_name"` Category string `db:"category" json:"category"` // farmacia, distribuidora @@ -46,8 +50,8 @@ const ( // User represents an authenticated actor inside a company. type User struct { - ID uuid.UUID `db:"id" json:"id"` - CompanyID uuid.UUID `db:"company_id" json:"company_id"` + ID UserID `db:"id" json:"id"` + CompanyID CompanyID `db:"company_id" json:"company_id"` Role string `db:"role" json:"role"` Name string `db:"name" json:"name"` Username string `db:"username" json:"username"` @@ -67,7 +71,7 @@ type User struct { // UserFilter captures listing constraints. type UserFilter struct { - CompanyID *uuid.UUID + CompanyID *CompanyID Limit int Offset int } @@ -498,7 +502,7 @@ type Review struct { // CompanyRating exposes the aggregate score for a seller or pharmacy. type CompanyRating struct { - CompanyID uuid.UUID `json:"company_id"` + CompanyID CompanyID `json:"company_id"` AverageScore float64 `json:"average_score"` TotalReviews int64 `json:"total_reviews"` } @@ -530,7 +534,7 @@ type AdminDashboard struct { // CompanyDocument represents a KYC/KYB document (CNPJ card, Permit). type CompanyDocument struct { ID uuid.UUID `db:"id" json:"id"` - CompanyID uuid.UUID `db:"company_id" json:"company_id"` + CompanyID CompanyID `db:"company_id" json:"company_id"` Type string `db:"type" json:"type"` // CNPJ, PERMIT, IDENTITY URL string `db:"url" json:"url"` Status string `db:"status" json:"status"` // PENDING, APPROVED, REJECTED @@ -542,7 +546,7 @@ type CompanyDocument struct { // LedgerEntry represents an immutable financial record. type LedgerEntry struct { ID uuid.UUID `db:"id" json:"id"` - CompanyID uuid.UUID `db:"company_id" json:"company_id"` + CompanyID CompanyID `db:"company_id" json:"company_id"` AmountCents int64 `db:"amount_cents" json:"amount_cents"` Type string `db:"type" json:"type"` // SALE, FEE, WITHDRAWAL, REFUND Description string `db:"description" json:"description"` @@ -553,7 +557,7 @@ type LedgerEntry struct { // Withdrawal represents a payout request. type Withdrawal struct { ID uuid.UUID `db:"id" json:"id"` - CompanyID uuid.UUID `db:"company_id" json:"company_id"` + CompanyID CompanyID `db:"company_id" json:"company_id"` AmountCents int64 `db:"amount_cents" json:"amount_cents"` Status string `db:"status" json:"status"` // PENDING, APPROVED, PAID, REJECTED BankAccountInfo string `db:"bank_account_info" json:"bank_account_info"` diff --git a/backend-old/internal/repository/postgres/migrations/0001_init.sql b/backend-old/internal/repository/postgres/migrations/0001_init.sql index df08e3f..93720ad 100644 --- a/backend-old/internal/repository/postgres/migrations/0001_init.sql +++ b/backend-old/internal/repository/postgres/migrations/0001_init.sql @@ -16,7 +16,7 @@ CREATE TABLE IF NOT EXISTS companies ( CREATE TABLE IF NOT EXISTS users ( id UUID PRIMARY KEY, company_id UUID NOT NULL REFERENCES companies(id), - role TEXT NOT NULL, + role TEXT NOT NULL DEFAULT 'PHARMACY', name TEXT NOT NULL, email TEXT NOT NULL UNIQUE, password_hash TEXT NOT NULL,