crud

package
v0.6.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 24, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CRUDCreateRequest

type CRUDCreateRequest[M CRUDModel] interface {
	ToModel() M
}

type CRUDListFilter

type CRUDListFilter interface {
	GetOffset() int
	GetLimit() int
}

type CRUDListFilterRequest

type CRUDListFilterRequest[F CRUDListFilter] interface {
	ToFilter() F
}

type CRUDModel

type CRUDModel interface {
	GetID() uint
}

type CRUDRepository

type CRUDRepository[M CRUDModel, F any] interface {
	GetDB() *gorm.DB
	Create(item M) (createdItem *M, err error)
	Update(id uint, item M) (*M, error)
	Get(id uint) (item *M, err error)
	GetMany(filter F) (items []M, err error)
	GetTotal(filter F) (count int64, err error)
	Delete(id uint) (err error)
}

type CRUDService

type CRUDService[M CRUDModel, F any] interface {
	GetRepo() CRUDRepository[M, F]
	Create(item M) (createdItem *M, err error)
	Update(id uint, item M) (*M, error)
	Get(id uint) (item *M, err error)
	GetManyWithTotal(filter F) (items []M, total int64, err error)
	Delete(id uint) (err error)
}

type CRUDUpdateRequest

type CRUDUpdateRequest[M CRUDModel] interface {
	ToModel() M
}

type CreateResponse

type CreateResponse[M CRUDModel] GetResponse[M]

type GetResponse

type GetResponse[M CRUDModel] struct {
	Data M
}

type Handler

type Handler[
	M CRUDModel,
	F CRUDListFilter,
	CR CRUDCreateRequest[M],
	UR CRUDUpdateRequest[M],
	LFR CRUDListFilterRequest[F],
] struct {
	// contains filtered or unexported fields
}

func NewHandler

func NewHandler[
	M CRUDModel,
	F CRUDListFilter,
	CR CRUDCreateRequest[M],
	UR CRUDUpdateRequest[M],
	LFR CRUDListFilterRequest[F],
](service CRUDService[M, F]) *Handler[M, F, CR, UR, LFR]

func (*Handler[M, F, CR, UR, LFR]) CreateItem

func (h *Handler[M, F, CR, UR, LFR]) CreateItem(c echo.Context) error

func (*Handler[M, F, CR, UR, LFR]) DeleteItem

func (h *Handler[M, F, CR, UR, LFR]) DeleteItem(c echo.Context) error

func (*Handler[M, F, CR, UR, LFR]) GetItem

func (h *Handler[M, F, CR, UR, LFR]) GetItem(c echo.Context) error

func (*Handler[M, F, CR, UR, LFR]) GetList

func (h *Handler[M, F, CR, UR, LFR]) GetList(c echo.Context) error

func (*Handler[M, F, CR, UR, LFR]) GetService

func (h *Handler[M, F, CR, UR, LFR]) GetService() CRUDService[M, F]

func (*Handler[M, F, CR, UR, LFR]) UpdateItem

func (h *Handler[M, F, CR, UR, LFR]) UpdateItem(c echo.Context) error

type ListFilter

type ListFilter struct {
	Offset int
	Limit  int
}

func (ListFilter) GetLimit

func (f ListFilter) GetLimit() int

func (ListFilter) GetOffset

func (f ListFilter) GetOffset() int

type ListResponse

type ListResponse[M CRUDModel] struct {
	Data   []M
	Offset int
	Limit  int
	Total  int64
}

type ListScopeFunc

type ListScopeFunc[F CRUDListFilter] func(F) func(db *gorm.DB) *gorm.DB

type Model

type Model struct {
	gorm.Model
}

func (Model) GetID

func (m Model) GetID() uint

type Repository

type Repository[M CRUDModel, F CRUDListFilter] struct {
	// contains filtered or unexported fields
}

func NewRepository

func NewRepository[M CRUDModel, F CRUDListFilter](
	db *gorm.DB,
	listScope *ListScopeFunc[F],
	listOrder any,
) *Repository[M, F]

func (*Repository[M, F]) Create

func (r *Repository[M, F]) Create(item M) (createdItem *M, err error)

func (*Repository[M, F]) Delete

func (r *Repository[M, F]) Delete(id uint) (err error)

func (*Repository[M, F]) Get

func (r *Repository[M, F]) Get(id uint) (item *M, err error)

func (*Repository[M, F]) GetDB

func (r *Repository[M, F]) GetDB() *gorm.DB

func (*Repository[M, F]) GetMany

func (r *Repository[M, F]) GetMany(filter F) (items []M, err error)

func (*Repository[M, F]) GetTotal

func (r *Repository[M, F]) GetTotal(filter F) (count int64, err error)

func (*Repository[M, F]) Paginate

func (r *Repository[M, F]) Paginate(offset, limit int) func(db *gorm.DB) *gorm.DB

func (*Repository[M, F]) Update

func (r *Repository[M, F]) Update(id uint, item M) (*M, error)

type Service

type Service[M CRUDModel, F CRUDListFilter] struct {
	// contains filtered or unexported fields
}

func NewService

func NewService[M CRUDModel, F CRUDListFilter](repo CRUDRepository[M, F]) *Service[M, F]

func (*Service[M, F]) Create

func (s *Service[M, F]) Create(item M) (*M, error)

func (*Service[M, F]) Delete

func (s *Service[M, F]) Delete(id uint) (err error)

func (*Service[M, F]) Get

func (s *Service[M, F]) Get(id uint) (*M, error)

func (*Service[M, F]) GetManyWithTotal

func (s *Service[M, F]) GetManyWithTotal(filter F) (items []M, total int64, err error)

func (*Service[M, F]) GetRepo

func (s *Service[M, F]) GetRepo() CRUDRepository[M, F]

func (*Service[M, F]) Update

func (s *Service[M, F]) Update(id uint, item M) (*M, error)

type UpdateResponse

type UpdateResponse[M CRUDModel] GetResponse[M]

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL