init push

This commit is contained in:
2026-07-16 22:16:45 +07:00
commit 8b068bdb10
1021 changed files with 332816 additions and 0 deletions

View 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
}

View 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)
}

View 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
}