59 lines
1.6 KiB
Go
59 lines
1.6 KiB
Go
// internal/handlers/account/notifications/read.go
|
|
package accountNotificationHandler
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
templateHelpers "synlotto-website/internal/helpers/template"
|
|
"synlotto-website/internal/logging"
|
|
"synlotto-website/internal/models"
|
|
"synlotto-website/internal/platform/bootstrap"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/justinas/nosurf"
|
|
)
|
|
|
|
// ToDo: functional also in messages needs to come out
|
|
func parseIDParam(c *gin.Context, name string) (int64, error) {
|
|
// typical atoi wrapper
|
|
// (implement: strconv.ParseInt(c.Param(name), 10, 64))
|
|
return atoi64(c.Param(name))
|
|
}
|
|
|
|
func (h *AccountNotificationHandlers) ReadGet(c *gin.Context) {
|
|
app := c.MustGet("app").(*bootstrap.App)
|
|
sm := app.SessionManager
|
|
|
|
userID := mustUserID(c)
|
|
id, err := parseIDParam(c, "id")
|
|
if err != nil {
|
|
c.AbortWithStatus(http.StatusNotFound)
|
|
return
|
|
}
|
|
|
|
n, err := h.Svc.GetByID(userID, id)
|
|
if err != nil || n == nil {
|
|
c.AbortWithStatus(http.StatusNotFound)
|
|
return
|
|
}
|
|
|
|
ctx := templateHelpers.TemplateContext(c.Writer, c.Request, models.TemplateData{})
|
|
if f := sm.PopString(c.Request.Context(), "flash"); f != "" {
|
|
ctx["Flash"] = f
|
|
}
|
|
ctx["CSRFToken"] = nosurf.Token(c.Request)
|
|
ctx["Title"] = n.Title // or Subject/Heading depending on your struct
|
|
ctx["Notification"] = n
|
|
|
|
tmpl := templateHelpers.LoadTemplateFiles(
|
|
"layout.html",
|
|
"web/templates/account/notifications/read.html",
|
|
)
|
|
|
|
c.Status(http.StatusOK)
|
|
if err := tmpl.ExecuteTemplate(c.Writer, "layout", ctx); err != nil {
|
|
logging.Info("❌ Template render error: %v", err)
|
|
c.String(http.StatusInternalServerError, "Error rendering notification")
|
|
}
|
|
}
|