handler

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound     = domain.ErrNotFound
	ErrUnauthorized = domain.ErrUnauthorized
)

Re-export domain errors for backward compatibility. Prefer using domain.ErrNotFound and domain.ErrUnauthorized in use cases; handlers can use either handler or domain for errors.Is.

Functions

This section is empty.

Types

type BaseHandler added in v0.3.0

type BaseHandler struct {
}

func (*BaseHandler) BuildPaginationResponse added in v0.3.0

func (c *BaseHandler) BuildPaginationResponse(data []interface{}, pageNumber, pageSize int, total int64) response.SimplePaginationResponse

BuildPaginationResponse builds a paginated response from data. total is the total number of items; hasNext is true when (pageNumber * pageSize) < total.

func (*BaseHandler) CheckUserHasRole added in v0.3.0

func (c *BaseHandler) CheckUserHasRole(userRoles []string, requiredRoles []string) bool

CheckUserHasRole checks if the user has any of the required roles.

func (*BaseHandler) GetCurrentUserID added in v0.3.0

func (c *BaseHandler) GetCurrentUserID(ctx *gin.Context) (string, bool)

GetCurrentUserID extracts user ID from context (set by auth middleware).

func (*BaseHandler) GetIDFromParam added in v0.3.0

func (c *BaseHandler) GetIDFromParam(ctx *gin.Context, paramName string, serviceCode string) (string, bool)

GetIDFromParam extracts ID from URL parameter, validates it, and returns error response if missing

func (*BaseHandler) GetIDFromRequestOrParam added in v0.3.0

func (c *BaseHandler) GetIDFromRequestOrParam(ctx *gin.Context, reqID string, paramName string, serviceCode string) (string, bool)

GetIDFromRequestOrParam extracts ID from request body or URL parameter

func (*BaseHandler) HandleServiceError added in v0.3.0

func (c *BaseHandler) HandleServiceError(ctx *gin.Context, serviceCode string, err error, notFoundMessages ...string) bool

HandleServiceError handles service errors with appropriate HTTP status codes. It checks for sentinel errors (ErrNotFound, ErrUnauthorized) via errors.Is, then falls back to notFoundMessages and legacy string matching for backward compatibility.

func (*BaseHandler) HandleValidationError added in v0.3.0

func (c *BaseHandler) HandleValidationError(ctx *gin.Context, serviceCode string, err error)

HandleValidationError handles validation errors and returns Laravel-style response

func (*BaseHandler) NormalizePagination added in v0.3.0

func (c *BaseHandler) NormalizePagination(pageNumber, pageSize int) (int, int)

NormalizePagination normalizes pagination parameters with defaults and limits (uses response.DefaultPageNumber, DefaultPageSize, MaxPageSize).

func (*BaseHandler) ValidateReqParams added in v0.3.0

func (c *BaseHandler) ValidateReqParams(ctx *gin.Context, requestParams interface{}) error

Jump to

Keyboard shortcuts

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