Potion/internal/app/handlers/page_handler.go
Hayden Hargreaves 35bf69d79c (UI): Implemented the recipe view page!
This can be accessed from `/v1/web/recipe/:id`! Static implementation,
not yet wired to the DB. Working on that next!
2025-07-02 21:21:10 -07:00

76 lines
1.7 KiB
Go

package handlers
import (
"net/http"
"github.com/gin-gonic/gin"
domain "github.com/haydenhargreaves/Potion/internal/domain/server"
layouts "github.com/haydenhargreaves/Potion/internal/templates/layouts"
pages "github.com/haydenhargreaves/Potion/internal/templates/pages"
)
func LoginPage(ctx *gin.Context) {
title := "Potion - Login"
page := pages.LoginPage()
ctx.HTML(200, "", layouts.AppLayout(title, page))
}
func HomePage(ctx *gin.Context) {
title := "Potion - Home"
page := pages.HomePage()
ctx.HTML(200, "", layouts.AppLayout(title, page))
}
func FavoritesPage(ctx *gin.Context) {
title := "Potion - Favorites"
page := pages.FavoritesPage()
ctx.HTML(200, "", layouts.AppLayout(title, page))
}
func CreatePage(ctx *gin.Context) {
// If not logged in, direct to the login page
if !domain.IsLoggedIn(ctx) {
ctx.Redirect(http.StatusSeeOther, domain.WEB_LOGIN)
return
}
title := "Potion - Create"
page := pages.CreatePage()
ctx.HTML(200, "", layouts.AppLayout(title, page))
}
func ProfilePage(ctx *gin.Context) {
// If not logged in, direct to the login page
if !domain.IsLoggedIn(ctx) {
ctx.Redirect(http.StatusSeeOther, domain.WEB_LOGIN)
return
}
// Else, get the user data
deps := ctx.MustGet("deps").(*domain.InjectedDependencies)
user := deps.UserService.GetAuthenicatedUser(ctx)
title := "Potion - Profile"
page := pages.ProfilePage(user)
ctx.HTML(200, "", layouts.AppLayout(title, page))
}
func ListPage(ctx *gin.Context) {
title := "Potion - Shopping List"
page := pages.ListPage()
ctx.HTML(200, "", layouts.AppLayout(title, page))
}
func RecipePage(ctx *gin.Context) {
title := "Potion - View Recipe"
page := pages.RecipePage()
ctx.HTML(200, "", layouts.AppLayout(title, page))
}