61 lines
1.8 KiB
Go
61 lines
1.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"
|
|
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
|
|
}
|
|
|
|
// 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
|
|
}
|
|
}
|