From a7a5169c6718edf875f2b243ee0a9e9451fe236a Mon Sep 17 00:00:00 2001 From: H3ALY Date: Thu, 30 Oct 2025 22:19:48 +0000 Subject: [PATCH] Fix model issues. --- internal/domain/messages/domain.go | 4 ++-- internal/handlers/account/messages/send.go | 5 ++--- internal/platform/services/notifications/service.go | 5 +++-- internal/storage/notifications/read.go | 4 ++-- web/templates/account/messages/send.html | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/internal/domain/messages/domain.go b/internal/domain/messages/domain.go index db2c436..9a5cf6f 100644 --- a/internal/domain/messages/domain.go +++ b/internal/domain/messages/domain.go @@ -7,8 +7,8 @@ import ( type Message = models.Message type CreateMessageInput struct { - RecipientID int64 `form:"to" binding:"required,numeric"` - Subject string `form:"recipient_id" binding:"required,max=200"` + RecipientID int64 `form:"recipientId" binding:"required,numeric"` + Subject string `form:"subject" binding:"required,max=200"` Body string `form:"body" binding:"required"` } diff --git a/internal/handlers/account/messages/send.go b/internal/handlers/account/messages/send.go index 4e54431..8810a43 100644 --- a/internal/handlers/account/messages/send.go +++ b/internal/handlers/account/messages/send.go @@ -53,7 +53,8 @@ func (h *AccountMessageHandlers) SendPost(c *gin.Context) { var in domain.CreateMessageInput if err := c.ShouldBind(&in); err != nil { // Re-render form with validation errors - ctx := templateHelpers.TemplateContext(c.Writer, c.Request, models.TemplateData{}) + data := templateHandlers.BuildTemplateData(app, c.Writer, c.Request) + ctx := templateHelpers.TemplateContext(c.Writer, c.Request, data) if f := sm.PopString(c.Request.Context(), "flash"); f != "" { ctx["Flash"] = f } @@ -98,8 +99,6 @@ func (h *AccountMessageHandlers) SendPost(c *gin.Context) { return } - // Optional: set a flash message for success (since you already PopString elsewhere) - // If you're using scs/v2, Put is available: sm.Put(c.Request.Context(), "flash", "Message sent!") // Redirect back to inbox diff --git a/internal/platform/services/notifications/service.go b/internal/platform/services/notifications/service.go index b0130c3..a1c07fb 100644 --- a/internal/platform/services/notifications/service.go +++ b/internal/platform/services/notifications/service.go @@ -35,14 +35,15 @@ func New(db *sql.DB, opts ...func(*Service)) *Service { func WithTimeout(d time.Duration) func(*Service) { return func(s *Service) { s.Timeout = d } } // List returns newest-first notifications for a user. +// ToDo:table is users_notification, where as messages is plural, this table seems oto use user_id reather than userId need to unify. Do i want to prefix with users/user func (s *Service) List(userID int64) ([]domain.Notification, error) { ctx, cancel := context.WithTimeout(context.Background(), s.Timeout) defer cancel() const q = ` SELECT id, title, body, is_read, created_at -FROM notifications -WHERE userId = ? +FROM users_notification +WHERE user_Id = ? ORDER BY created_at DESC` rows, err := s.DB.QueryContext(ctx, q, userID) diff --git a/internal/storage/notifications/read.go b/internal/storage/notifications/read.go index 98ac87d..ed522bc 100644 --- a/internal/storage/notifications/read.go +++ b/internal/storage/notifications/read.go @@ -27,7 +27,7 @@ func GetNotificationCount(db *sql.DB, userID int) int { var count int err := db.QueryRow(` SELECT COUNT(*) FROM users_notification - WHERE userId = ? AND is_read = FALSE`, userID).Scan(&count) + WHERE user_Id = ? AND is_read = FALSE`, userID).Scan(&count) if err != nil { log.Println("⚠️ Failed to count notifications:", err) @@ -41,7 +41,7 @@ func GetRecentNotifications(db *sql.DB, userID int, limit int) []models.Notifica rows, err := db.Query(` SELECT id, subject, body, is_read, created_at FROM users_notification - WHERE userId = ? + WHERE user_Id = ? ORDER BY created_at DESC LIMIT ?`, userID, limit) if err != nil { diff --git a/web/templates/account/messages/send.html b/web/templates/account/messages/send.html index a6c7f5a..92e76ad 100644 --- a/web/templates/account/messages/send.html +++ b/web/templates/account/messages/send.html @@ -13,8 +13,8 @@
- - + +