init push
This commit is contained in:
38
internal/domain/facility/model.go
Normal file
38
internal/domain/facility/model.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package facility
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
"wucher/internal/shared/pkg/uuidv7"
|
||||
)
|
||||
|
||||
// Facility stores configurable HEMS / Dry Lease (and other) operational equipment rows.
|
||||
type Facility struct {
|
||||
ID []byte `gorm:"type:binary(16);primaryKey;column:id"`
|
||||
Category string `gorm:"type:varchar(64);index;not null;column:category"`
|
||||
Name string `gorm:"type:varchar(150);not null;column:name"`
|
||||
Type string `gorm:"type:varchar(100);not null;column:type"`
|
||||
SortKey *int `gorm:"column:sortkey"`
|
||||
Length string `gorm:"type:varchar(64);column:length"`
|
||||
Weight string `gorm:"type:varchar(64);column:weight"`
|
||||
Electric string `gorm:"type:varchar(255);not null;default:'';column:electric"`
|
||||
Note string `gorm:"type:text;column:note"`
|
||||
IsActive bool `gorm:"type:tinyint(1);index;not null;default:1;column:is_active"`
|
||||
CreatedBy []byte `gorm:"type:binary(16);column:created_by"`
|
||||
UpdatedBy []byte `gorm:"type:binary(16);column:updated_by"`
|
||||
DeletedBy []byte `gorm:"type:binary(16);column:deleted_by"`
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
DeletedAt *time.Time `gorm:"column:deleted_at;index"`
|
||||
}
|
||||
|
||||
func (Facility) TableName() string { return "facilities" }
|
||||
|
||||
func (f *Facility) BeforeCreate(tx *gorm.DB) error {
|
||||
if len(f.ID) == 0 {
|
||||
f.ID = uuidv7.MustBytes()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
11
internal/domain/facility/repository.go
Normal file
11
internal/domain/facility/repository.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package facility
|
||||
|
||||
import "context"
|
||||
|
||||
type Repository interface {
|
||||
Create(ctx context.Context, facility *Facility) error
|
||||
Update(ctx context.Context, facility *Facility) error
|
||||
Delete(ctx context.Context, id []byte, deletedBy []byte) error
|
||||
GetByID(ctx context.Context, id []byte) (*Facility, error)
|
||||
List(ctx context.Context, filter, category, sort string, limit, offset int) ([]Facility, int64, error)
|
||||
}
|
||||
11
internal/domain/facility/service.go
Normal file
11
internal/domain/facility/service.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package facility
|
||||
|
||||
import "context"
|
||||
|
||||
type Service interface {
|
||||
Create(ctx context.Context, facility *Facility) error
|
||||
Update(ctx context.Context, facility *Facility) error
|
||||
Delete(ctx context.Context, id []byte, deletedBy []byte) error
|
||||
GetByID(ctx context.Context, id []byte) (*Facility, error)
|
||||
List(ctx context.Context, filter, category, sort string, limit, offset int) ([]Facility, int64, error)
|
||||
}
|
||||
Reference in New Issue
Block a user