Continued work around getting messages and notifications cleaned up since moving to MySQL and changing to Gin, SCS, NoSurf.
This commit is contained in:
44
internal/handlers/account/messages/send.go
Normal file
44
internal/handlers/account/messages/send.go
Normal file
@@ -0,0 +1,44 @@
|
||||
// Package accountMessageHandler
|
||||
// Path: /internal/handlers/account/messages
|
||||
// File: send.go
|
||||
|
||||
package accountMessageHandler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// GET /account/messages/add
|
||||
// Renders: web/templates/account/messages/send.html
|
||||
func (h *AccountMessageHandlers) AddGet(c *gin.Context) {
|
||||
c.HTML(http.StatusOK, "account/messages/send.html", gin.H{
|
||||
"title": "Send Message",
|
||||
})
|
||||
}
|
||||
|
||||
// POST /account/messages/add
|
||||
func (h *AccountMessageHandlers) AddPost(c *gin.Context) {
|
||||
userID := mustUserID(c)
|
||||
var in CreateMessageInput
|
||||
if err := c.ShouldBind(&in); err != nil {
|
||||
// Re-render form with validation errors
|
||||
c.HTML(http.StatusBadRequest, "account/messages/send.html", gin.H{
|
||||
"title": "Send Message",
|
||||
"error": "Please correct the errors below.",
|
||||
"form": in,
|
||||
})
|
||||
return
|
||||
}
|
||||
if _, err := h.Svc.Create(userID, in); err != nil {
|
||||
c.HTML(http.StatusInternalServerError, "account/messages/send.html", gin.H{
|
||||
"title": "Send Message",
|
||||
"error": "Could not send message.",
|
||||
"form": in,
|
||||
})
|
||||
return
|
||||
}
|
||||
// Redirect back to inbox
|
||||
c.Redirect(http.StatusSeeOther, "/account/messages")
|
||||
}
|
||||
Reference in New Issue
Block a user