Documentation
¶
Index ¶
- type BaseModel
- type BaseTimestamps
- type Model
- type ModelApproveStatusSetter
- type ModelCreateTimeSetter
- type ModelIDFieldGetter
- type ModelIDSetter
- type ModelUpdateTimeSetter
- type Option
- type Options
- type Repository
- func (r *Repository[T, TID]) Count(ctx context.Context, qops ...Option) (count int64, err error)
- func (r *Repository[T, TID]) Create(ctx context.Context, obj *T, opts ...Option) (TID, error)
- func (r *Repository[T, TID]) Delete(ctx context.Context, id TID, opts ...Option) error
- func (r *Repository[T, TID]) FetchList(ctx context.Context, qops ...Option) (list []*T, err error)
- func (r *Repository[T, TID]) Get(ctx context.Context, id TID, qops ...Option) (*T, error)
- func (r *Repository[T, TID]) Update(ctx context.Context, id TID, obj *T, opts ...Option) error
- type RepositoryApproveIface
- type RepositoryApprover
- type RepositoryIface
- type RepositoryIfaceWithApprove
- type Usecase
- func (u *Usecase[T, TID]) Count(ctx context.Context, qops ...Option) (int64, error)
- func (u *Usecase[T, TID]) Create(ctx context.Context, obj *T, opts ...Option) (id TID, err error)
- func (u *Usecase[T, TID]) Delete(ctx context.Context, id TID, opts ...Option) error
- func (u *Usecase[T, TID]) FetchList(ctx context.Context, qops ...Option) ([]*T, error)
- func (u *Usecase[T, TID]) Get(ctx context.Context, id TID, qops ...Option) (*T, error)
- func (u *Usecase[T, TID]) Update(ctx context.Context, id TID, obj *T, opts ...Option) error
- type UsecaseApproveIface
- type UsecaseApprover
- type UsecaseIface
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseModel ¶ added in v0.4.0
type BaseModel[TID comparable] struct { ID TID `gorm:"primaryKey" db:"id"` }
BaseModel is a convenience embed for domain models used with Repository[T, TID] and Usecase[T, TID]. It provides GetID (value receiver, satisfies Model[TID] constraint) and SetID implementations.
Usage:
type MyModel struct {
generated.BaseModel[uint64]
Name string
}
type BaseTimestamps ¶ added in v0.4.0
type BaseTimestamps struct {
CreatedAt time.Time `db:"created_at"`
UpdatedAt time.Time `db:"updated_at"`
}
BaseTimestamps is a convenience embed providing SetCreatedAt and SetUpdatedAt.
Usage:
type MyModel struct {
generated.BaseModel[uint64]
generated.BaseTimestamps
gorm.DeletedAt
}
func (*BaseTimestamps) SetCreatedAt ¶ added in v0.4.0
func (m *BaseTimestamps) SetCreatedAt(t time.Time)
SetCreatedAt sets the creation timestamp.
func (*BaseTimestamps) SetUpdatedAt ¶ added in v0.4.0
func (m *BaseTimestamps) SetUpdatedAt(t time.Time)
SetUpdatedAt sets the update timestamp.
type Model ¶ added in v0.4.0
type Model[TID comparable] interface { GetID() TID }
Model is the compile-time constraint for types used with Repository[T, TID] and Usecase[T, TID]. T must expose its primary key via a value receiver so that T itself (not *T) satisfies the constraint.
type ModelApproveStatusSetter ¶
type ModelApproveStatusSetter interface {
SetApproveStatus(status pkgModels.ApproveStatus)
}
ModelApproveStatusSetter defines an interface for models that support an approval workflow.
type ModelCreateTimeSetter ¶
ModelCreateTimeSetter defines an interface for models that can set their creation time.
type ModelIDFieldGetter ¶
type ModelIDFieldGetter interface {
GetIDField() string
}
ModelIDFieldGetter defines an interface for models that can override the primary key column name.
type ModelIDSetter ¶
type ModelIDSetter[TID any] interface { SetID(id TID) }
ModelIDSetter defines an interface for models that can set their primary key.
type ModelUpdateTimeSetter ¶
ModelUpdateTimeSetter defines an interface for models that can set their update time.
type Repository ¶
type Repository[T Model[TID], TID comparable] struct { repository.Repository // contains filtered or unexported fields }
func NewRepository ¶
func NewRepository[T Model[TID], TID comparable]() *Repository[T, TID]
NewRepository creates a new repository instance
func (*Repository[T, TID]) Create ¶
func (r *Repository[T, TID]) Create(ctx context.Context, obj *T, opts ...Option) (TID, error)
Create creates a new campaign
func (*Repository[T, TID]) Delete ¶
func (r *Repository[T, TID]) Delete(ctx context.Context, id TID, opts ...Option) error
Delete deletes a campaign by ID
func (*Repository[T, TID]) FetchList ¶
func (r *Repository[T, TID]) FetchList(ctx context.Context, qops ...Option) (list []*T, err error)
FetchList returns a list of campaigns
type RepositoryApproveIface ¶
type RepositoryApprover ¶
type RepositoryApprover[T any, TID any] struct { repository.Repository IDName string StatusName string }
RepositoryApprover provides methods to approve or reject entities
type RepositoryIface ¶
type RepositoryIface[T Model[TID], TID comparable] interface { Get(ctx context.Context, id TID, qops ...Option) (*T, error) FetchList(ctx context.Context, qops ...Option) ([]*T, error) Count(ctx context.Context, qops ...Option) (int64, error) Create(ctx context.Context, obj *T, opts ...Option) (TID, error) Update(ctx context.Context, id TID, obj *T, opts ...Option) error Delete(ctx context.Context, id TID, opts ...Option) error }
type RepositoryIfaceWithApprove ¶
type RepositoryIfaceWithApprove[T Model[TID], TID comparable] interface { RepositoryIface[T, TID] RepositoryApproveIface[TID] }
type Usecase ¶
type Usecase[T Model[TID], TID comparable] struct { Repo RepositoryIface[T, TID] // Repository interface for data access operations }
Usecase provides a generic business logic layer with ACL (Access Control List) support for CRUD operations on entities of type T with ID type TID.
func (*Usecase[T, TID]) Count ¶
Count returns the total number of entities with ACL permission check. Only counts entities the user has permission to list.
func (*Usecase[T, TID]) Create ¶
Create creates a new entity with ACL permission check. Sets the initial approval status to Pending before delegating to the repository. Returns the ID of the created entity if successful.
func (*Usecase[T, TID]) Delete ¶
Delete removes an entity with ACL permission check. Fetches the existing entity first to verify delete permissions.
func (*Usecase[T, TID]) FetchList ¶
FetchList retrieves a list of entities with ACL permission checks. Validates both general list access and individual object access permissions.
type UsecaseApproveIface ¶
type UsecaseApprover ¶
type UsecaseApprover[T Model[TID], TID comparable] struct { Repo RepositoryIfaceWithApprove[T, TID] }
UsecaseApprover provides approve/reject usecase methods
type UsecaseIface ¶
type UsecaseIface[T Model[TID], TID comparable] interface { Get(ctx context.Context, id TID, qops ...Option) (*T, error) FetchList(ctx context.Context, qops ...Option) ([]*T, error) Count(ctx context.Context, qops ...Option) (int64, error) Create(ctx context.Context, obj *T, opts ...Option) (TID, error) Update(ctx context.Context, id TID, obj *T, opts ...Option) error Delete(ctx context.Context, id TID, opts ...Option) error }