Documentation
¶
Overview ¶
Package handler contains HTTP request handlers for the web application.
Index ¶
- Constants
- func FrontendBackendProxyRewrite(prefix string) echo.MiddlewareFunc
- func RegisterRoutes(e *echo.Echo, handlers *Handlers) error
- type AuthHandler
- func (h *AuthHandler) AuthState(c echo.Context) error
- func (h *AuthHandler) Login(c echo.Context) error
- func (h *AuthHandler) LoginAPI(c echo.Context) error
- func (h *AuthHandler) Logout(c echo.Context) error
- func (h *AuthHandler) LogoutAPI(c echo.Context) error
- func (h *AuthHandler) Register(c echo.Context) error
- func (h *AuthHandler) RegisterAPI(c echo.Context) error
- type FrontendHandler
- type Handlers
- type HomeHandler
- type LoginRequest
- type ManagedUserUpdateRequest
- type RegisterRequest
- type UserHandler
- func (h *UserHandler) CreateUserAPI(c echo.Context) error
- func (h *UserHandler) DeactivateUserAPI(c echo.Context) error
- func (h *UserHandler) DeleteUserAPI(c echo.Context) error
- func (h *UserHandler) GetUserAPI(c echo.Context) error
- func (h *UserHandler) ListUsersAPI(c echo.Context) error
- func (h *UserHandler) UpdateUserAPI(c echo.Context) error
- func (h *UserHandler) UserCountAPI(c echo.Context) error
Constants ¶
const ( RouteHome = "/" RouteLogin = "/auth/login" RouteRegister = "/auth/register" RouteLogout = "/auth/logout" RouteProfile = "/profile" RouteAPIAuthState = "/api/auth/state" RouteAPIAuthLogin = "/api/auth/login" RouteAPIAuthRegister = "/api/auth/register" RouteAPIAuthLogout = "/api/auth/logout" )
Route constants
const ( MsgLoginSuccess = "Login successful" MsgLogoutSuccess = "Logout successful" MsgRegisterSuccess = "Registration successful" MsgUserCreateSuccess = "User created successfully" MsgUserUpdateSuccess = "User updated successfully" MsgUserDeactivateSuccess = "User deactivated successfully" MsgUserDeleteSuccess = "User deleted successfully" )
Response messages
Variables ¶
This section is empty.
Functions ¶
func FrontendBackendProxyRewrite ¶
func FrontendBackendProxyRewrite(prefix string) echo.MiddlewareFunc
FrontendBackendProxyRewrite strips the baked Astro backend proxy prefix so shipped assets can keep using the same /_backend/* contract they use in local frontend development.
Types ¶
type AuthHandler ¶
type AuthHandler struct {
// contains filtered or unexported fields
}
AuthHandler handles authentication-related requests
func NewAuthHandler ¶
func NewAuthHandler(s *store.Store, authService *middleware.SessionAuthService) *AuthHandler
NewAuthHandler creates a new AuthHandler
func (*AuthHandler) AuthState ¶
func (h *AuthHandler) AuthState(c echo.Context) error
AuthState returns the current session state for frontend bootstrap.
func (*AuthHandler) Login ¶
func (h *AuthHandler) Login(c echo.Context) error
Login handles user login
func (*AuthHandler) LoginAPI ¶
func (h *AuthHandler) LoginAPI(c echo.Context) error
LoginAPI authenticates a user and returns JSON instead of redirects.
func (*AuthHandler) Logout ¶
func (h *AuthHandler) Logout(c echo.Context) error
Logout handles user logout
func (*AuthHandler) LogoutAPI ¶
func (h *AuthHandler) LogoutAPI(c echo.Context) error
LogoutAPI destroys the current session and returns JSON.
func (*AuthHandler) Register ¶
func (h *AuthHandler) Register(c echo.Context) error
Register handles user registration
func (*AuthHandler) RegisterAPI ¶
func (h *AuthHandler) RegisterAPI(c echo.Context) error
RegisterAPI creates a user, starts a session, and returns JSON.
type FrontendHandler ¶
type FrontendHandler struct {
// contains filtered or unexported fields
}
FrontendHandler serves the embedded Astro build output for shipped browser routes.
func NewFrontendHandler ¶
func NewFrontendHandler(distFS fs.FS) *FrontendHandler
NewFrontendHandler creates a frontend handler backed by the embedded dist filesystem.
func (*FrontendHandler) Asset ¶
func (h *FrontendHandler) Asset(c echo.Context) error
Asset serves built frontend assets such as /_astro/* files.
func (*FrontendHandler) Page ¶
func (h *FrontendHandler) Page(name string) echo.HandlerFunc
Page serves a built HTML page from the embedded frontend dist.
type Handlers ¶
type Handlers struct {
Home *HomeHandler
User *UserHandler
Auth *AuthHandler
}
Handlers holds all the application handlers.
func NewHandlers ¶
func NewHandlers(s *store.Store, authService *middleware.SessionAuthService) *Handlers
NewHandlers creates a new handlers instance with the given store.
type HomeHandler ¶
type HomeHandler struct {
// contains filtered or unexported fields
}
HomeHandler handles requests for the home page and health checks.
func NewHomeHandler ¶
func NewHomeHandler(s *store.Store) *HomeHandler
NewHomeHandler creates a new HomeHandler instance.
type LoginRequest ¶
type LoginRequest struct {
Email string `json:"email" form:"email" validate:"required,email"`
Password string `json:"password" form:"password" validate:"required,min=1"`
}
LoginRequest represents a login request
type ManagedUserUpdateRequest ¶
type ManagedUserUpdateRequest struct {
Email string `json:"email" form:"email" validate:"required,email"`
Name string `json:"name" form:"name" validate:"required,min=2,max=100"`
Password string `json:"password,omitempty" form:"password" validate:"omitempty,password"`
ConfirmPassword string `json:"confirm_password,omitempty" form:"confirm_password"`
Bio string `json:"bio,omitempty" form:"bio" validate:"max=500"`
AvatarURL string `json:"avatar_url,omitempty" form:"avatar_url" validate:"omitempty,url"`
}
ManagedUserUpdateRequest represents the editable user fields from the CRUD form.
func (ManagedUserUpdateRequest) Validate ¶
func (r ManagedUserUpdateRequest) Validate() error
Validate implements custom validation for ManagedUserUpdateRequest.
type RegisterRequest ¶
type RegisterRequest struct {
Email string `json:"email" form:"email" validate:"required,email"`
Name string `json:"name" form:"name" validate:"required,min=2,max=100"`
Password string `json:"password" form:"password" validate:"required,password"`
ConfirmPassword string `json:"confirm_password" form:"confirm_password" validate:"required"`
Bio string `json:"bio,omitempty" form:"bio" validate:"max=500"`
AvatarURL string `json:"avatar_url,omitempty" form:"avatar_url" validate:"omitempty,url"`
}
RegisterRequest represents a registration request
func (RegisterRequest) Validate ¶
func (r RegisterRequest) Validate() error
Validate implements custom validation for RegisterRequest
type UserHandler ¶
type UserHandler struct {
// contains filtered or unexported fields
}
UserHandler handles all user-related HTTP requests including CRUD operations.
func NewUserHandler ¶
func NewUserHandler(s *store.Store, authService *middleware.SessionAuthService) *UserHandler
NewUserHandler creates a new UserHandler with the given store.
func (*UserHandler) CreateUserAPI ¶
func (h *UserHandler) CreateUserAPI(c echo.Context) error
CreateUserAPI creates a user and returns the created record as JSON.
func (*UserHandler) DeactivateUserAPI ¶
func (h *UserHandler) DeactivateUserAPI(c echo.Context) error
DeactivateUserAPI deactivates a user and returns the updated record as JSON.
func (*UserHandler) DeleteUserAPI ¶
func (h *UserHandler) DeleteUserAPI(c echo.Context) error
DeleteUserAPI deletes a user and returns a JSON acknowledgement.
func (*UserHandler) GetUserAPI ¶
func (h *UserHandler) GetUserAPI(c echo.Context) error
GetUserAPI returns a single user record as JSON for edit flows.
func (*UserHandler) ListUsersAPI ¶
func (h *UserHandler) ListUsersAPI(c echo.Context) error
ListUsersAPI returns the active user list as JSON.
func (*UserHandler) UpdateUserAPI ¶
func (h *UserHandler) UpdateUserAPI(c echo.Context) error
UpdateUserAPI updates a user and returns the updated record as JSON.
func (*UserHandler) UserCountAPI ¶
func (h *UserHandler) UserCountAPI(c echo.Context) error
UserCountAPI returns the count of active users as JSON.