92 lines
3.0 KiB
Go
92 lines
3.0 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 (
|
|
accountHandler "synlotto-website/internal/handlers/account"
|
|
accountMsgHandlers "synlotto-website/internal/handlers/account/messages"
|
|
accountNotificationHandler "synlotto-website/internal/handlers/account/notifications"
|
|
accountTicketHandler "synlotto-website/internal/handlers/account/tickets"
|
|
|
|
"synlotto-website/internal/http/middleware"
|
|
"synlotto-website/internal/platform/bootstrap"
|
|
)
|
|
|
|
func RegisterAccountRoutes(app *bootstrap.App) {
|
|
r := app.Router
|
|
|
|
// Instantiate handlers that have method receivers
|
|
messageSvc := app.Services.Messages
|
|
msgH := &accountMsgHandlers.AccountMessageHandlers{Svc: messageSvc}
|
|
|
|
notificationSvc := app.Services.Notifications
|
|
notifH := &accountNotificationHandler.AccountNotificationHandlers{Svc: notificationSvc}
|
|
|
|
// ticketSvc := app.Services.TicketService
|
|
// ticketH := &accountTickets.AccountTicketHandlers{Svc: ticketSvc}
|
|
|
|
// Public account pages
|
|
acc := r.Group("/account")
|
|
acc.Use(middleware.PublicOnly())
|
|
{
|
|
acc.GET("/login", accountHandler.LoginGet)
|
|
acc.POST("/login", accountHandler.LoginPost)
|
|
acc.GET("/signup", accountHandler.SignupGet)
|
|
acc.POST("/signup", accountHandler.SignupPost)
|
|
}
|
|
|
|
// Auth-required account actions
|
|
accAuth := r.Group("/account")
|
|
accAuth.Use(middleware.AuthMiddleware(), middleware.RequireAuth())
|
|
{
|
|
accAuth.POST("/logout", accountHandler.Logout)
|
|
accAuth.GET("/logout", accountHandler.Logout) // optional
|
|
}
|
|
|
|
// Messages (auth-required)
|
|
messages := r.Group("/account/messages")
|
|
messages.Use(middleware.AuthMiddleware(), middleware.RequireAuth())
|
|
{
|
|
messages.GET("/", msgH.List)
|
|
messages.GET("/add", msgH.AddGet)
|
|
messages.POST("/add", msgH.AddPost)
|
|
messages.GET("/archived", msgH.ArchivedList) // renders archived.html
|
|
messages.GET("/:id", msgH.ReadGet) // renders read.html
|
|
}
|
|
|
|
// Notifications (auth-required)
|
|
notifications := r.Group("/account/notifications")
|
|
notifications.Use(middleware.AuthMiddleware(), middleware.RequireAuth())
|
|
{
|
|
notifications.GET("/", notifH.List)
|
|
notifications.GET("/:id", notifH.ReadGet) // renders read.html
|
|
}
|
|
|
|
// Tickets (auth-required)
|
|
tickets := r.Group("/account/tickets")
|
|
tickets.Use(middleware.AuthMiddleware(), middleware.RequireAuth())
|
|
{
|
|
tickets.GET("/", accountTicketHandler.List) // GET /account/tickets
|
|
tickets.GET("/add", accountTicketHandler.AddGet) // GET /account/tickets/add
|
|
tickets.POST("/add", accountTicketHandler.AddPost) // POST /account/tickets/add
|
|
}
|
|
}
|