init push
This commit is contained in:
52
internal/domain/health_insurance_companies/model.go
Normal file
52
internal/domain/health_insurance_companies/model.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package health_insurance_companies
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
"wucher/internal/shared/pkg/uuidv7"
|
||||
)
|
||||
|
||||
type HealthInsuranceCompany struct {
|
||||
ID []byte `gorm:"type:binary(16);primaryKey;column:id"`
|
||||
Name string `gorm:"type:varchar(128);not null;column:name"`
|
||||
SortKey *int `gorm:"column:sortkey"`
|
||||
LandID []byte `gorm:"type:binary(16);index;column:land_id"`
|
||||
State string `gorm:"type:varchar(128);column:state"`
|
||||
Address string `gorm:"type:varchar(256);column:address"`
|
||||
MobileNumber string `gorm:"type:varchar(20);column:mobile_number"`
|
||||
Email string `gorm:"type:varchar(128);column:email"`
|
||||
Note string `gorm:"type:text;column:note"`
|
||||
IsActive bool `gorm:"type:tinyint(1);index;not null;default:1;column:is_active"`
|
||||
CreatedAt time.Time `gorm:"column:created_at"`
|
||||
CreatedBy []byte `gorm:"type:binary(16);column:created_by"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at"`
|
||||
UpdatedBy []byte `gorm:"type:binary(16);column:updated_by"`
|
||||
DeletedAt *time.Time `gorm:"column:deleted_at"`
|
||||
DeletedBy []byte `gorm:"type:binary(16);column:deleted_by"`
|
||||
}
|
||||
|
||||
func (HealthInsuranceCompany) TableName() string { return "health_insurance_companies" }
|
||||
|
||||
type StateDetail struct {
|
||||
LandID string
|
||||
FederalStateID string
|
||||
FederalState string
|
||||
LandName string
|
||||
LandISOCode string
|
||||
}
|
||||
|
||||
// LandDetail is used to enrich health insurance company responses from land_id.
|
||||
type LandDetail struct {
|
||||
LandID string
|
||||
LandName string
|
||||
LandISOCode string
|
||||
}
|
||||
|
||||
func (h *HealthInsuranceCompany) BeforeCreate(tx *gorm.DB) error {
|
||||
if len(h.ID) == 0 {
|
||||
h.ID = uuidv7.MustBytes()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
37
internal/domain/health_insurance_companies/model_test.go
Normal file
37
internal/domain/health_insurance_companies/model_test.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package health_insurance_companies
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func TestHealthInsuranceCompanyTableName(t *testing.T) {
|
||||
var m HealthInsuranceCompany
|
||||
if got := m.TableName(); got != "health_insurance_companies" {
|
||||
t.Fatalf("expected table name health_insurance_companies, got %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHealthInsuranceCompanyBeforeCreate(t *testing.T) {
|
||||
t.Run("generates id when empty", func(t *testing.T) {
|
||||
m := &HealthInsuranceCompany{}
|
||||
if err := m.BeforeCreate(&gorm.DB{}); err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if len(m.ID) == 0 {
|
||||
t.Fatalf("expected id to be generated")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("keeps existing id", func(t *testing.T) {
|
||||
existing := []byte("already-set-id")
|
||||
m := &HealthInsuranceCompany{ID: append([]byte(nil), existing...)}
|
||||
if err := m.BeforeCreate(&gorm.DB{}); err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if string(m.ID) != string(existing) {
|
||||
t.Fatalf("expected existing id to stay unchanged")
|
||||
}
|
||||
})
|
||||
}
|
||||
13
internal/domain/health_insurance_companies/repository.go
Normal file
13
internal/domain/health_insurance_companies/repository.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package health_insurance_companies
|
||||
|
||||
import "context"
|
||||
|
||||
type Repository interface {
|
||||
Create(ctx context.Context, row *HealthInsuranceCompany) error
|
||||
Update(ctx context.Context, row *HealthInsuranceCompany) error
|
||||
Delete(ctx context.Context, id []byte, deletedBy []byte) error
|
||||
GetByID(ctx context.Context, id []byte) (*HealthInsuranceCompany, error)
|
||||
List(ctx context.Context, filter, sort string, limit, offset int) ([]HealthInsuranceCompany, int64, error)
|
||||
ResolveStateDetails(ctx context.Context, stateNames []string) (map[string]StateDetail, error)
|
||||
ResolveLandDetails(ctx context.Context, landIDs []string) (map[string]LandDetail, error)
|
||||
}
|
||||
13
internal/domain/health_insurance_companies/service.go
Normal file
13
internal/domain/health_insurance_companies/service.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package health_insurance_companies
|
||||
|
||||
import "context"
|
||||
|
||||
type Service interface {
|
||||
Create(ctx context.Context, row *HealthInsuranceCompany) error
|
||||
Update(ctx context.Context, row *HealthInsuranceCompany) error
|
||||
Delete(ctx context.Context, id []byte, deletedBy []byte) error
|
||||
GetByID(ctx context.Context, id []byte) (*HealthInsuranceCompany, error)
|
||||
List(ctx context.Context, filter, sort string, limit, offset int) ([]HealthInsuranceCompany, int64, error)
|
||||
ResolveStateDetails(ctx context.Context, stateNames []string) (map[string]StateDetail, error)
|
||||
ResolveLandDetails(ctx context.Context, landIDs []string) (map[string]LandDetail, error)
|
||||
}
|
||||
Reference in New Issue
Block a user