handler

package
v0.0.0-...-9e6389f Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package handler contains HTTP request handlers for the web application.

Index

Constants

View Source
const (
	HtmxRequestHeader = "true"
	HtmxRequest       = "HX-Request"
	HtmxRedirect      = "HX-Redirect"
	HtmxTrigger       = "HX-Trigger"
	HtmxTarget        = "HX-Target"
	HtmxSwap          = "HX-Swap"

	ContentTypeJSON = "application/json"
)

HTTP Header constants

View Source
const (
	RouteHome     = "/"
	RouteLogin    = "/auth/login"
	RouteRegister = "/auth/register"
	RouteLogout   = "/auth/logout"
	RouteProfile  = "/profile"
)

Route constants

View Source
const (
	MsgLoginSuccess    = "Login successful"
	MsgLogoutSuccess   = "Logout successful"
	MsgRegisterSuccess = "Registration successful"
)

Response messages

Variables

This section is empty.

Functions

func RegisterRoutes

func RegisterRoutes(e *echo.Echo, handlers *Handlers) error

RegisterRoutes sets up all application routes.

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) Login

func (h *AuthHandler) Login(c echo.Context) error

Login handles user login

func (*AuthHandler) LoginPage

func (h *AuthHandler) LoginPage(c echo.Context) error

LoginPage renders the login page

func (*AuthHandler) Logout

func (h *AuthHandler) Logout(c echo.Context) error

Logout handles user logout

func (*AuthHandler) Profile

func (h *AuthHandler) Profile(c echo.Context) error

Profile handles user profile page

func (*AuthHandler) Register

func (h *AuthHandler) Register(c echo.Context) error

Register handles user registration

func (*AuthHandler) RegisterPage

func (h *AuthHandler) RegisterPage(c echo.Context) error

RegisterPage renders the registration page

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.

func (*HomeHandler) Demo

func (h *HomeHandler) Demo(c echo.Context) error

Demo provides a demonstration of HTMX functionality.

func (*HomeHandler) Health

func (h *HomeHandler) Health(c echo.Context) error

Health provides a comprehensive health check endpoint.

func (*HomeHandler) Home

func (h *HomeHandler) Home(c echo.Context) error

Home handles requests to the root path, returning either full page or partial content.

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 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) *UserHandler

NewUserHandler creates a new UserHandler with the given store.

func (*UserHandler) CreateUser

func (h *UserHandler) CreateUser(c echo.Context) error

CreateUser creates a new user.

func (*UserHandler) DeactivateUser

func (h *UserHandler) DeactivateUser(c echo.Context) error

DeactivateUser deactivates a user instead of deleting.

func (*UserHandler) DeleteUser

func (h *UserHandler) DeleteUser(c echo.Context) error

DeleteUser permanently deletes a user.

func (*UserHandler) EditUserForm

func (h *UserHandler) EditUserForm(c echo.Context) error

EditUserForm renders the user edit form with existing data.

func (*UserHandler) UpdateUser

func (h *UserHandler) UpdateUser(c echo.Context) error

UpdateUser updates an existing user.

func (*UserHandler) UserCount

func (h *UserHandler) UserCount(c echo.Context) error

UserCount returns the count of active users.

func (*UserHandler) UserForm

func (h *UserHandler) UserForm(c echo.Context) error

UserForm renders the user creation/edit form.

func (*UserHandler) UserList

func (h *UserHandler) UserList(c echo.Context) error

UserList returns the list of users as HTML fragment.

func (*UserHandler) Users

func (h *UserHandler) Users(c echo.Context) error

Users renders the main user management page.

Jump to

Keyboard shortcuts

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