Fix model issues.
This commit is contained in:
@@ -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"`
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
<input type="hidden" name="csrf_token" value="{{ .CSRFToken }}">
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="recipient_id" class="form-label">Recipient User ID</label>
|
||||
<input type="number" class="form-control" name="recipient_id" value="{{ with .Form }}{{ .RecipientID }}{{ end }}" required>
|
||||
<label for="recipientId" class="form-label">Recipient User ID</label>
|
||||
<input type="number" class="form-control" name="recipientId" value="{{ with .Form }}{{ .RecipientID }}{{ end }}" required>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
|
||||
Reference in New Issue
Block a user