47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
// Package accountMessageHandler
|
|
// Path: /internal/handlers/account/messages
|
|
// File: read.go
|
|
|
|
package accountMessageHandler
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// GET /account/messages
|
|
// Renders: web/templates/account/messages/index.html
|
|
func (h *AccountMessageHandlers) List(c *gin.Context) {
|
|
userID := mustUserID(c)
|
|
msgs, err := h.Svc.ListInbox(userID)
|
|
if err != nil {
|
|
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"error": "failed to load messages"})
|
|
return
|
|
}
|
|
c.HTML(http.StatusOK, "account/messages/index.html", gin.H{
|
|
"title": "Messages",
|
|
"messages": msgs,
|
|
})
|
|
}
|
|
|
|
// GET /account/messages/:id
|
|
// Renders: web/templates/account/messages/read.html
|
|
func (h *AccountMessageHandlers) ReadGet(c *gin.Context) {
|
|
userID := mustUserID(c)
|
|
id, err := parseIDParam(c, "id")
|
|
if err != nil {
|
|
c.AbortWithStatus(http.StatusNotFound)
|
|
return
|
|
}
|
|
msg, err := h.Svc.GetByID(userID, id)
|
|
if err != nil || msg == nil {
|
|
c.AbortWithStatus(http.StatusNotFound)
|
|
return
|
|
}
|
|
c.HTML(http.StatusOK, "account/messages/read.html", gin.H{
|
|
"title": msg.Subject,
|
|
"message": msg,
|
|
})
|
|
}
|