Refactoring for Gin, NoSurf and SCS continues.
This commit is contained in:
@@ -8,10 +8,13 @@ import (
|
||||
templateHandlers "synlotto-website/internal/handlers/template"
|
||||
httpHelpers "synlotto-website/internal/helpers/http"
|
||||
securityHelpers "synlotto-website/internal/helpers/security"
|
||||
|
||||
// ToDo multi storage references need handler?
|
||||
templateHelpers "synlotto-website/internal/helpers/template"
|
||||
messagesStorage "synlotto-website/internal/storage/messages"
|
||||
storage "synlotto-website/internal/storage/messages"
|
||||
|
||||
"synlotto-website/internal/helpers"
|
||||
storage "synlotto-website/internal/storage/mysql"
|
||||
)
|
||||
|
||||
func MessagesInboxHandler(db *sql.DB) http.HandlerFunc {
|
||||
@@ -28,13 +31,13 @@ func MessagesInboxHandler(db *sql.DB) http.HandlerFunc {
|
||||
}
|
||||
perPage := 10
|
||||
|
||||
totalCount := storage.GetInboxMessageCount(db, userID)
|
||||
totalCount := messagesStorage.GetInboxMessageCount(db, userID)
|
||||
totalPages := (totalCount + perPage - 1) / perPage
|
||||
if totalPages == 0 {
|
||||
totalPages = 1
|
||||
}
|
||||
|
||||
messages := storage.GetInboxMessages(db, userID, page, perPage)
|
||||
messages := messagesStorage.GetInboxMessages(db, userID, page, perPage)
|
||||
|
||||
data := templateHandlers.BuildTemplateData(db, w, r)
|
||||
context := templateHelpers.TemplateContext(w, r, data)
|
||||
@@ -92,7 +95,7 @@ func ArchiveMessageHandler(db *sql.DB) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
err := storage.ArchiveMessage(db, userID, id)
|
||||
err := messagesStorage.ArchiveMessage(db, userID, id)
|
||||
if err != nil {
|
||||
templateHelpers.SetFlash(w, r, "Failed to archive message.")
|
||||
} else {
|
||||
@@ -117,7 +120,7 @@ func ArchivedMessagesHandler(db *sql.DB) http.HandlerFunc {
|
||||
}
|
||||
perPage := 10
|
||||
|
||||
messages := storage.GetArchivedMessages(db, userID, page, perPage)
|
||||
messages := messagesStorage.GetArchivedMessages(db, userID, page, perPage)
|
||||
hasMore := len(messages) == perPage
|
||||
|
||||
data := templateHandlers.BuildTemplateData(db, w, r)
|
||||
@@ -153,7 +156,7 @@ func SendMessageHandler(db *sql.DB) http.HandlerFunc {
|
||||
subject := r.FormValue("subject")
|
||||
body := r.FormValue("message")
|
||||
|
||||
if err := storage.SendMessage(db, senderID, recipientID, subject, body); err != nil {
|
||||
if err := messagesStorage.SendMessage(db, senderID, recipientID, subject, body); err != nil {
|
||||
templateHelpers.SetFlash(w, r, "Failed to send message.")
|
||||
} else {
|
||||
templateHelpers.SetFlash(w, r, "Message sent.")
|
||||
|
||||
Reference in New Issue
Block a user