handlers

package
v0.0.0-...-2a7283e Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultPageLimit = datastore.DefaultPageLimit
	ErrMsgDatastore  = "datastore is required"
	ErrMsgAuth       = "auth service is required"
	ErrMsgUnauth     = "Unauthorized"
	ErrMsgLimiter    = "rate limiter is required"
)

Constants for pagination and error messages

Variables

This section is empty.

Functions

This section is empty.

Types

type ApplicationHandler

type ApplicationHandler struct {
	*Handler
}

ApplicationHandler handles HTTP requests related to applications.

func NewApplicationHandler

func NewApplicationHandler(options ...HandlerOption) (*ApplicationHandler, error)

NewApplicationHandler creates a new ApplicationHandler with the provided options. It requires both a datastore and an authentication service to function properly.

func (*ApplicationHandler) CreateApplication

func (h *ApplicationHandler) CreateApplication(ctx *gin.Context)

CreateApplication creates a new application for the currently logged-in user respecting their rate limit for maximum number of applications

func (*ApplicationHandler) DeleteApplication

func (h *ApplicationHandler) DeleteApplication(ctx *gin.Context)

DeleteApplication deletes an application owned by the currently logged-in user

func (*ApplicationHandler) GetMyApplications

func (h *ApplicationHandler) GetMyApplications(ctx *gin.Context)

GetMyApplications returns all applications for the currently logged-in user

func (*ApplicationHandler) UpdateApplication

func (h *ApplicationHandler) UpdateApplication(ctx *gin.Context)

UpdateApplication updates an existing application belonging to the currently logged-in user

type ConfigHandler

type ConfigHandler struct {
	*Handler
}

ConfigHandler handles HTTP requests related to config.

func NewConfigHandler

func NewConfigHandler(options ...HandlerOption) (*ConfigHandler, error)

NewConfigHandler creates a new ConfigHandler with the provided options. It requires both a datastore and an authentication service to function properly.

func (*ConfigHandler) GetConfig

func (h *ConfigHandler) GetConfig(ctx *gin.Context)

type Handler

type Handler struct {
	Store   datastore.Datastore
	Auth    *authz.Service
	Limiter *ratelimit.RateLimit
}

Handler is a base handler that provides common functionality for all HTTP handlers.

func NewHandler

func NewHandler(options ...HandlerOption) (*Handler, error)

NewHandler creates a new Handler with the provided options. It requires both a datastore and an authentication service to function properly.

func (*Handler) GetAuthenticatedUser

func (h *Handler) GetAuthenticatedUser(ctx *gin.Context) (*model.User, bool)

GetAuthenticatedUser retrieves the authenticated user from the context

func (*Handler) RespondWithData

func (h *Handler) RespondWithData(ctx *gin.Context, data interface{}, pagination *datastore.CursorPagination)

RespondWithData sends a JSON success response with the given data

func (*Handler) RespondWithError

func (h *Handler) RespondWithError(ctx *gin.Context, statusCode int, errorMessage string)

RespondWithError sends a JSON error response with the given status code and message

type HandlerOption

type HandlerOption func(*Handler)

HandlerOption defines a functional option for configuring a Handler

func WithAuthService

func WithAuthService(auth *authz.Service) HandlerOption

WithAuthService sets the authentication service for the Handler

func WithDatastore

func WithDatastore(store datastore.Datastore) HandlerOption

WithDatastore sets the datastore for the Handler

func WithRatelimiter

func WithRatelimiter(limiter *ratelimit.RateLimit) HandlerOption

WithRatelimiter sets the rate limiter for the Handler

type UserHandler

type UserHandler struct {
	*Handler
}

UserHandler handles HTTP requests related to users.

func NewUserHandler

func NewUserHandler(options ...HandlerOption) (*UserHandler, error)

NewUserHandler creates a new UserHandler with the provided options. It requires both a datastore and an authentication service to function properly.

func (*UserHandler) GetCurrentRoles

func (h *UserHandler) GetCurrentRoles(ctx *gin.Context)

GetCurrentRoles returns the roles for the logged-in user

func (*UserHandler) GetCurrentUser

func (h *UserHandler) GetCurrentUser(ctx *gin.Context)

GetCurrentUser returns the currently logged-in user

func (*UserHandler) ListAll

func (h *UserHandler) ListAll(ctx *gin.Context)

ListAll returns a paginated list of all users

Jump to

Keyboard shortcuts

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