init push
This commit is contained in:
32
internal/domain/other_person/model.go
Normal file
32
internal/domain/other_person/model.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package otherperson
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
"wucher/internal/shared/pkg/uuidv7"
|
||||
)
|
||||
|
||||
type OtherPerson struct {
|
||||
ID []byte `gorm:"type:binary(16);primaryKey;column:id"`
|
||||
Name string `gorm:"type:varchar(191);column:name"`
|
||||
MobilePhone string `gorm:"type:varchar(64);column:mobile_phone"`
|
||||
Email string `gorm:"type:varchar(191);column:email"`
|
||||
|
||||
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;index"`
|
||||
DeletedBy []byte `gorm:"type:binary(16);column:deleted_by"`
|
||||
}
|
||||
|
||||
func (OtherPerson) TableName() string { return "other_people" }
|
||||
|
||||
func (p *OtherPerson) BeforeCreate(_ *gorm.DB) error {
|
||||
if len(p.ID) == 0 {
|
||||
p.ID = uuidv7.MustBytes()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
13
internal/domain/other_person/repository.go
Normal file
13
internal/domain/other_person/repository.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package otherperson
|
||||
|
||||
import "context"
|
||||
|
||||
type Repository interface {
|
||||
Upsert(ctx context.Context, p *OtherPerson) error
|
||||
Create(ctx context.Context, p *OtherPerson) error
|
||||
Update(ctx context.Context, p *OtherPerson) error
|
||||
Delete(ctx context.Context, id, deletedBy []byte) error
|
||||
GetByID(ctx context.Context, id []byte) (*OtherPerson, error)
|
||||
FindByIdentity(ctx context.Context, name, phone, email string) (*OtherPerson, error)
|
||||
Search(ctx context.Context, q string, limit, offset int) ([]OtherPerson, int64, error)
|
||||
}
|
||||
23
internal/domain/other_person/service.go
Normal file
23
internal/domain/other_person/service.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package otherperson
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
)
|
||||
|
||||
// Sentinel errors returned by the service so the transport layer can map them to the
|
||||
// right HTTP status without depending on GORM internals.
|
||||
var (
|
||||
ErrNameRequired = errors.New("name is required")
|
||||
ErrNotFound = errors.New("other person not found")
|
||||
ErrDuplicate = errors.New("another other person with the same name, mobile phone and email already exists")
|
||||
)
|
||||
|
||||
type Service interface {
|
||||
Create(ctx context.Context, p *OtherPerson) error
|
||||
Update(ctx context.Context, p *OtherPerson) error
|
||||
Delete(ctx context.Context, id, actor []byte) error
|
||||
GetByID(ctx context.Context, id []byte) (*OtherPerson, error)
|
||||
Search(ctx context.Context, q string, limit, offset int) ([]OtherPerson, int64, error)
|
||||
Upsert(ctx context.Context, p *OtherPerson) error
|
||||
}
|
||||
Reference in New Issue
Block a user