Continued work around getting messages and notifications cleaned up since moving to MySQL and changing to Gin, SCS, NoSurf.
This commit is contained in:
46
internal/handlers/account/messages/read.go
Normal file
46
internal/handlers/account/messages/read.go
Normal file
@@ -0,0 +1,46 @@
|
||||
// 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,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user