init push
This commit is contained in:
36
internal/domain/hospital/model.go
Normal file
36
internal/domain/hospital/model.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package hospital
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
"wucher/internal/shared/pkg/uuidv7"
|
||||
)
|
||||
|
||||
type Hospital struct {
|
||||
ID []byte `gorm:"type:binary(16);primaryKey;column:id"`
|
||||
Name string `gorm:"type:varchar(128);not null;column:hospital_name"`
|
||||
SortKey *int `gorm:"column:sortkey"`
|
||||
Address string `gorm:"type:varchar(256);column:address"`
|
||||
LandlineNumber string `gorm:"type:varchar(20);column:landline_number"`
|
||||
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 (Hospital) TableName() string { return "no_icao_codes" }
|
||||
|
||||
func (h *Hospital) BeforeCreate(tx *gorm.DB) error {
|
||||
if len(h.ID) == 0 {
|
||||
h.ID = uuidv7.MustBytes()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
37
internal/domain/hospital/model_test.go
Normal file
37
internal/domain/hospital/model_test.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package hospital
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func TestHospitalTableName(t *testing.T) {
|
||||
var m Hospital
|
||||
if got := m.TableName(); got != "no_icao_codes" {
|
||||
t.Fatalf("expected table name no_icao_codes, got %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHospitalBeforeCreate(t *testing.T) {
|
||||
t.Run("generates id when empty", func(t *testing.T) {
|
||||
m := &Hospital{}
|
||||
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 := &Hospital{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")
|
||||
}
|
||||
})
|
||||
}
|
||||
11
internal/domain/hospital/repository.go
Normal file
11
internal/domain/hospital/repository.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package hospital
|
||||
|
||||
import "context"
|
||||
|
||||
type Repository interface {
|
||||
Create(ctx context.Context, hospital *Hospital) error
|
||||
Update(ctx context.Context, hospital *Hospital) error
|
||||
Delete(ctx context.Context, id []byte, deletedBy []byte) error
|
||||
GetByID(ctx context.Context, id []byte) (*Hospital, error)
|
||||
List(ctx context.Context, filter, sort string, limit, offset int) ([]Hospital, int64, error)
|
||||
}
|
||||
11
internal/domain/hospital/service.go
Normal file
11
internal/domain/hospital/service.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package hospital
|
||||
|
||||
import "context"
|
||||
|
||||
type Service interface {
|
||||
Create(ctx context.Context, hospital *Hospital) error
|
||||
Update(ctx context.Context, hospital *Hospital) error
|
||||
Delete(ctx context.Context, id []byte, deletedBy []byte) error
|
||||
GetByID(ctx context.Context, id []byte) (*Hospital, error)
|
||||
List(ctx context.Context, filter, sort string, limit, offset int) ([]Hospital, int64, error)
|
||||
}
|
||||
Reference in New Issue
Block a user