controllers

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetIDParam

func GetIDParam(ctx *gin.Context) uint

func GetPaginationParams

func GetPaginationParams(ctx *gin.Context) *db_utils.Pagination

func GetParam

func GetParam(ctx *gin.Context, param string) string

func GetQueryParams

func GetQueryParams(ctx *gin.Context, params map[string]bool) map[string]string

func HandleError

func HandleError(c *gin.Context, statusCode int, err error)

func HandleIDBasedRequest

func HandleIDBasedRequest(ctx *gin.Context, action func(id uint) (response.Response, error))

func HandleRequestWithBody

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

func WithRecovery

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

Types

type BaseController

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

func NewBaseController

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

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

func (bc *BaseController[T, CreateR, UpdateR, E]) Create(
	ctx *gin.Context,
	successMessage string,
	beforeCreate func(*CreateR) error,
	afterCreate func(*T) error,
	serviceFunc func(CreateR) (*T, error),
)

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

func (bc *BaseController[T, CreateR, UpdateR, E]) Delete(ctx *gin.Context, message string, dopAction func(id uint) error)

func (*BaseController[T, CreateR, UpdateR, E]) Get

func (bc *BaseController[T, CreateR, UpdateR, E]) Get(
	ctx *gin.Context,
	successMessage string,
	queryParams map[string]bool,
	cacheFunc func(map[string]interface{}, func() (*T, error)) (*T, error),
	serviceFunc func(uint) (*T, error),
)

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

func (bc *BaseController[T, CreateR, UpdateR, E]) GetByParams(
	ctx *gin.Context,
	successMessage string,
	queryConditions db_utils.ConditionsMap,
	preloadConditions []db_utils.PreloadCondition,
	cacheFunc func(map[string]interface{}, func() (*T, error)) (*T, error),
	serviceFunc func(db_utils.ConditionsMap, ...string) (*T, error),
)

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

func (bc *BaseController[T, CreateR, UpdateR, E]) GetConditionMap() db_utils.ConditionsMap

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

func (bc *BaseController[T, CreateR, UpdateR, E]) GetQueryFields(
	ctx *gin.Context,
)

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

func (bc *BaseController[T, CreateR, UpdateR, E]) List(
	ctx *gin.Context,
	successMessage string,
	queryConditions db_utils.ConditionsMap,
	preloadConditions []db_utils.PreloadCondition,
	cacheFunc func(map[string]interface{}, func() ([]*T, error)) ([]*T, error),
	serviceFunc func(*db_utils.QueryOptions) ([]*T, error),
)

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

func (bc *BaseController[T, CreateR, UpdateR, E]) Update(
	ctx *gin.Context,
	successMessage string,
	beforeCreate func(*UpdateR) error,
	afterCreate func(*T) error,
)

Jump to

Keyboard shortcuts

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