Documentation ¶
Index ¶
- func GetLastItemID[T PageItem](items []T) int
- func GinParentVerifier(parentDao ParentDao) gin.HandlerFunc
- type Controller
- func (c *Controller[M, S, R]) Create(ctx *gin.Context, req R) (*S, error)
- func (c *Controller[M, S, R]) Delete(ctx *gin.Context, p ResourceParam) error
- func (c *Controller[M, S, R]) List(ctx *gin.Context, p ListParam) (*ListResponse[S], error)
- func (c *Controller[M, S, R]) Retrieve(ctx *gin.Context, p ResourceParam) (*S, error)
- func (c *Controller[M, S, R]) Update(ctx *gin.Context, p ResourceParam, req R) error
- type Dao
- func (db *Dao[M]) BulkCreate(ctx context.Context, m []M) error
- func (db *Dao[M]) Create(ctx context.Context, m M) (*M, error)
- func (db *Dao[M]) Delete(ctx context.Context, id int) error
- func (db *Dao[M]) Get(ctx context.Context, id int) (*M, error)
- func (db *Dao[M]) List(ctx context.Context, page pgdb.Page, creatorID int) (res []M, total int64, err error)
- func (db *Dao[M]) Update(ctx context.Context, id int, m M) (*M, error)
- type DaoI
- type ListParam
- type ListResponse
- type Model
- type ModelWithCreator
- type NestedBulkCreateRequest
- type NestedController
- func (c *NestedController[M, S, R]) BulkCreate(ctx *gin.Context, p NestedParam, reqs NestedBulkCreateRequest[M, R]) (*S, error)
- func (c *NestedController[M, S, R]) Create(ctx *gin.Context, p NestedParam, req R) (*S, error)
- func (c *NestedController[M, S, R]) Delete(ctx *gin.Context, p NestedResourceParam) error
- func (c *NestedController[M, S, R]) List(ctx *gin.Context, p NestedParam) (*ListResponse[S], error)
- func (c *NestedController[M, S, R]) Retrieve(ctx *gin.Context, p NestedResourceParam) (*S, error)
- func (c *NestedController[M, S, R]) Update(ctx *gin.Context, p NestedResourceParam, req R) error
- type NestedModel
- type NestedParam
- type NestedResRequest
- type NestedResourceParam
- type PageItem
- type ParentDao
- type Request
- type ResourceParam
- type Response
- type Service
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetLastItemID ¶
func GinParentVerifier ¶
func GinParentVerifier(parentDao ParentDao) gin.HandlerFunc
Types ¶
type Controller ¶
func (*Controller[M, S, R]) List ¶
func (c *Controller[M, S, R]) List(ctx *gin.Context, p ListParam) (*ListResponse[S], error)
type ListResponse ¶
type ModelWithCreator ¶
type NestedBulkCreateRequest ¶
type NestedBulkCreateRequest[M NestedModel[M], R NestedResRequest[M]] []R
type NestedController ¶
type NestedController[M NestedModel[M], S Response[M], R NestedResRequest[M]] struct { Svc Service[M] }
NestedController represents crud controller taking model, request and response object as type param. Response object dependency could be eliminated if model has a method to convert to response but that would move the contract definition to model, which is avoided here. Path is expected to be in format /parent/:parentID/child/:id with exact param names
func (*NestedController[M, S, R]) BulkCreate ¶
func (*NestedController[M, S, R]) List ¶
func (c *NestedController[M, S, R]) List(ctx *gin.Context, p NestedParam) (*ListResponse[S], error)
type NestedParam ¶
type NestedParam struct { ParentID int `uri:"parentID" binding:"required"` ListParam }
type NestedResRequest ¶
type NestedResRequest[M NestedModel[M]] interface { ToModel(*gin.Context) M }
type NestedResourceParam ¶
type NestedResourceParam struct { ID int `uri:"id" binding:"required"` ParentID int `uri:"parentID" binding:"required"` }
NestedResourceParam is used to bind nested uri like /parent/:parentID/child/:id first param is expected to be named "parentID" and second as "id"
type ResourceParam ¶
type ResourceParam struct {
ID int `uri:"parentID" binding:"required"`
}
type Service ¶
type Service[M any] interface { Get(ctx context.Context, id int) (*M, error) Create(ctx context.Context, m M) (*M, error) Update(ctx context.Context, id int, m M) (*M, error) Delete(ctx context.Context, id int) error List(ctx context.Context, page pgdb.Page, creatorID int) (res []M, total int64, err error) BulkCreate(ctx context.Context, m []M) error }
Click to show internal directories.
Click to hide internal directories.