controllers

package
v0.4.11 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2025 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleError

func HandleError(ctx *gin.Context, err error)

func HandleRequestWithBody

func HandleRequestWithBody[T, R any](ctx *gin.Context, handler func(context.Context, *T) (R, error), successStatus int)

func SwaggerFileHandler added in v0.3.5

func SwaggerFileHandler(c *gin.Context)

func WithRecovery

func WithRecovery(ctx *gin.Context, handler func())

Types

type BaseController

type BaseController[T entities.Entity, CreateR request.Request[T], UpdateR request.Request[T], Resp any] struct {
	Service *services.BaseService[T, CreateR]
	// contains filtered or unexported fields
}

func NewBaseController

func NewBaseController[T entities.Entity, CreateR request.Request[T], UpdateR request.Request[T], Resp any](
	service *services.BaseService[T, CreateR],
) *BaseController[T, CreateR, UpdateR, Resp]

func (*BaseController[T, CreateR, UpdateR, Resp]) Create

func (bc *BaseController[T, CreateR, UpdateR, Resp]) Create(req CreateRequest[T, CreateR])

func (*BaseController[T, CreateR, UpdateR, Resp]) Delete

func (bc *BaseController[T, CreateR, UpdateR, Resp]) Delete(reqCtx DeleteRequest[T])

func (*BaseController[T, CreateR, UpdateR, Resp]) GetByParams

func (bc *BaseController[T, CreateR, UpdateR, Resp]) GetByParams(req GetRequest[T])

func (*BaseController[T, CreateR, UpdateR, Resp]) GetConditionMap

func (bc *BaseController[T, CreateR, UpdateR, Resp]) GetConditionMap() filter.ConditionsMap

Оптимизированный метод получения conditionMap

func (*BaseController[T, CreateR, UpdateR, Resp]) GetQueryFields

func (bc *BaseController[T, CreateR, UpdateR, Resp]) GetQueryFields(
	ctx *gin.Context,
	conditions ...filter.ConditionsMap,
)

func (*BaseController[T, CreateR, UpdateR, Resp]) List

func (bc *BaseController[T, CreateR, UpdateR, Resp]) List(req GetListRequest[T])

func (*BaseController[T, CreateR, UpdateR, Resp]) Update

func (bc *BaseController[T, CreateR, UpdateR, Resp]) Update(req UpdateRequest[T, UpdateR])

type CacheFunc added in v0.3.5

type CacheFunc[T entities.Entity] func(map[string]interface{}, func() (*T, error)) (*T, error)

type CacheListFunc added in v0.3.5

type CacheListFunc[T entities.Entity] func(map[string]interface{}, func() ([]*T, error)) ([]*T, error)

type CreateRequest added in v0.3.5

type CreateRequest[T any, CreateR any] struct {
	RequestContext
	BeforeCreate func(CreateR) error
	AfterCreate  func(*T) error
	ServiceFunc  func(context.Context, CreateR) (*T, error)
}

type DeleteRequest added in v0.4.3

type DeleteRequest[T entities.Entity] struct {
	RequestContext
	ServiceFunc interface{}
}

type GetFunc added in v0.3.5

type GetFunc[T entities.Entity] func(context.Context, filter.ConditionsMap, ...string) (*T, error)

type GetListFunc added in v0.3.5

type GetListFunc[T entities.Entity] func(context.Context, *db_utils.QueryOptions) ([]*T, error)

type GetListRequest added in v0.3.5

type GetListRequest[T entities.Entity] struct {
	RequestContext
	CacheFunc CacheListFunc[T]
	GetFunc   GetListFunc[T]
}

type GetRequest added in v0.3.5

type GetRequest[T entities.Entity] struct {
	RequestContext
	CacheFunc CacheFunc[T]
	GetFunc   GetFunc[T]
}

type RequestContext added in v0.3.5

type RequestContext struct {
	Ctx                *gin.Context
	QueryConditions    filter.ConditionsMap
	PreloadConditions  []preload.PreloadCondition
	CustomResponseType any
	SuccessMessage     string
	SuppressResponse   bool
	Function           func(context.Context)
	NotNeedAllRequired bool
}

type UpdateRequest added in v0.3.5

type UpdateRequest[T entities.Entity, UpdateR request.Request[T]] struct {
	RequestContext
	BeforeUpdate func(*UpdateR) error
	AfterUpdate  func(*T) error
	ServiceFunc  func(context.Context, filter.ConditionsMap, []string, interface{ ToEntity() (*T, error) }) (*T, error)
}

Jump to

Keyboard shortcuts

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