init push
This commit is contained in:
45
internal/domain/icao/model.go
Normal file
45
internal/domain/icao/model.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package icao
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
"wucher/internal/domain/federal_state"
|
||||
"wucher/internal/domain/land"
|
||||
"wucher/internal/shared/pkg/uuidv7"
|
||||
)
|
||||
|
||||
type ICAO struct {
|
||||
ID []byte `gorm:"type:binary(16);primaryKey;column:id"`
|
||||
FederalStateID []byte `gorm:"type:binary(16);index;column:federal_state_id"`
|
||||
LandID []byte `gorm:"type:binary(16);index;column:land_id"`
|
||||
ICAOCode string `gorm:"type:varchar(16);not null;column:icao_code"`
|
||||
Name string `gorm:"type:varchar(150);not null;column: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"`
|
||||
|
||||
FederalState *federal_state.FederalState `gorm:"foreignKey:FederalStateID;references:ID"`
|
||||
Land *land.Land `gorm:"foreignKey:LandID;references:ID"`
|
||||
|
||||
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 (ICAO) TableName() string { return "icaos" }
|
||||
|
||||
func (i *ICAO) BeforeCreate(tx *gorm.DB) error {
|
||||
if len(i.ID) == 0 {
|
||||
i.ID = uuidv7.MustBytes()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
37
internal/domain/icao/model_test.go
Normal file
37
internal/domain/icao/model_test.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package icao
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func TestICAOTableName(t *testing.T) {
|
||||
var m ICAO
|
||||
if got := m.TableName(); got != "icaos" {
|
||||
t.Fatalf("expected table name icaos, got %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestICAOBeforeCreate(t *testing.T) {
|
||||
t.Run("generates id when empty", func(t *testing.T) {
|
||||
m := &ICAO{}
|
||||
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 := &ICAO{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/icao/repository.go
Normal file
11
internal/domain/icao/repository.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package icao
|
||||
|
||||
import "context"
|
||||
|
||||
type Repository interface {
|
||||
Create(ctx context.Context, row *ICAO) error
|
||||
Update(ctx context.Context, row *ICAO) error
|
||||
Delete(ctx context.Context, id []byte, deletedBy []byte) error
|
||||
GetByID(ctx context.Context, id []byte) (*ICAO, error)
|
||||
List(ctx context.Context, filter, sort string, limit, offset int) ([]ICAO, int64, error)
|
||||
}
|
||||
11
internal/domain/icao/service.go
Normal file
11
internal/domain/icao/service.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package icao
|
||||
|
||||
import "context"
|
||||
|
||||
type Service interface {
|
||||
Create(ctx context.Context, row *ICAO) error
|
||||
Update(ctx context.Context, row *ICAO) error
|
||||
Delete(ctx context.Context, id []byte, deletedBy []byte) error
|
||||
GetByID(ctx context.Context, id []byte) (*ICAO, error)
|
||||
List(ctx context.Context, filter, sort string, limit, offset int) ([]ICAO, int64, error)
|
||||
}
|
||||
Reference in New Issue
Block a user