init push
This commit is contained in:
34
internal/domain/land/model.go
Normal file
34
internal/domain/land/model.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package land
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
"wucher/internal/shared/pkg/uuidv7"
|
||||
)
|
||||
|
||||
type Land struct {
|
||||
ID []byte `gorm:"type:binary(16);primaryKey;column:id"`
|
||||
Name string `gorm:"type:varchar(128);not null;column:name"`
|
||||
Note string `gorm:"type:text;column:note"`
|
||||
LandISOCode string `gorm:"type:varchar(8);not null;default:'';uniqueIndex:uq_lands_land_iso_code;column:land_iso_code"`
|
||||
BMDExportID *string `gorm:"type:varchar(10);column:bmd_export_id"`
|
||||
SortKey *int `gorm:"column:sortkey"`
|
||||
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 (Land) TableName() string { return "lands" }
|
||||
|
||||
func (l *Land) BeforeCreate(tx *gorm.DB) error {
|
||||
if len(l.ID) == 0 {
|
||||
l.ID = uuidv7.MustBytes()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
37
internal/domain/land/model_test.go
Normal file
37
internal/domain/land/model_test.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package land
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func TestLandTableName(t *testing.T) {
|
||||
var m Land
|
||||
if got := m.TableName(); got != "lands" {
|
||||
t.Fatalf("expected table name lands, got %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLandBeforeCreate(t *testing.T) {
|
||||
t.Run("generates id when empty", func(t *testing.T) {
|
||||
m := &Land{}
|
||||
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 := &Land{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/land/repository.go
Normal file
11
internal/domain/land/repository.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package land
|
||||
|
||||
import "context"
|
||||
|
||||
type Repository interface {
|
||||
Create(ctx context.Context, row *Land) error
|
||||
Update(ctx context.Context, row *Land) error
|
||||
Delete(ctx context.Context, id []byte, deletedBy []byte) error
|
||||
GetByID(ctx context.Context, id []byte) (*Land, error)
|
||||
List(ctx context.Context, filter, sort string, limit, offset int) ([]Land, int64, error)
|
||||
}
|
||||
11
internal/domain/land/service.go
Normal file
11
internal/domain/land/service.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package land
|
||||
|
||||
import "context"
|
||||
|
||||
type Service interface {
|
||||
Create(ctx context.Context, row *Land) error
|
||||
Update(ctx context.Context, row *Land) error
|
||||
Delete(ctx context.Context, id []byte, deletedBy []byte) error
|
||||
GetByID(ctx context.Context, id []byte) (*Land, error)
|
||||
List(ctx context.Context, filter, sort string, limit, offset int) ([]Land, int64, error)
|
||||
}
|
||||
Reference in New Issue
Block a user