Files
website/internal/http/routes/accountroutes.go

82 lines
2.8 KiB
Go

// Package routes
// Path: /internal/http/routes
// File: accountroutes.go
//
// Purpose
// Defines all /account route groups including:
//
// - Public authentication pages (login, signup)
// - Protected session actions (logout)
// - Auth-protected ticket management pages
//
// Responsibilities (as implemented here)
// 1) PublicOnly guard on login/signup pages
// 2) RequireAuth guard on logout and tickets pages
// 3) Clean REST path structure for tickets ("/account/tickets")
//
// Notes
// - AuthMiddleware must come before RequireAuth
// - Ticket routes rely on authenticated user context
package routes
import (
accountHandlers "synlotto-website/internal/handlers/account"
accountMessageHandlers "synlotto-website/internal/handlers/account/messages"
accountNotificationHandlers "synlotto-website/internal/handlers/account/notifications"
accountTicketHandlers "synlotto-website/internal/handlers/account/tickets"
"synlotto-website/internal/http/middleware"
"synlotto-website/internal/platform/bootstrap"
)
func RegisterAccountRoutes(app *bootstrap.App) {
r := app.Router
// Public account pages
acc := r.Group("/account")
acc.Use(middleware.PublicOnly())
{
acc.GET("/login", accountHandlers.LoginGet)
acc.POST("/login", accountHandlers.LoginPost)
acc.GET("/signup", accountHandlers.SignupGet)
acc.POST("/signup", accountHandlers.SignupPost)
}
// Auth-required account actions
accAuth := r.Group("/account")
accAuth.Use(middleware.AuthMiddleware(), middleware.RequireAuth())
{
accAuth.POST("/logout", accountHandlers.Logout)
accAuth.GET("/logout", accountHandlers.Logout) // optional
}
// Messages (auth-required)
messages := r.Group("/account/messages")
messages.Use(middleware.AuthMiddleware(), middleware.RequireAuth())
{
messages.GET("/", accountMessageHandlers.List)
messages.GET("/add", accountMessageHandlers.AddGet)
messages.POST("/add", accountMessageHandlers.AddPost)
messages.GET("/archived", accountMessageHandlers.ArchivedList) // renders archived.html
messages.GET("/:id", accountMessageHandlers.ReadGet) // renders read.html
}
// Notifications (auth-required)
notifications := r.Group("/account/notifications")
notifications.Use(middleware.AuthMiddleware(), middleware.RequireAuth())
{
notifications.GET("/", accountNotificationHandlers.List)
notifications.GET("/:id", accountNotificationHandlers.ReadGet) // renders read.html
}
// Tickets (auth-required)
tickets := r.Group("/account/tickets")
tickets.Use(middleware.AuthMiddleware(), middleware.RequireAuth())
{
tickets.GET("/", accountTicketHandlers.List) // GET /account/tickets
tickets.GET("/add", accountTicketHandlers.AddGet) // GET /account/tickets/add
tickets.POST("/add", accountTicketHandlers.AddPost) // POST /account/tickets/add
}
}