Still working through messages and notifications.
This commit is contained in:
@@ -7,8 +7,8 @@ import (
|
|||||||
type Message = models.Message
|
type Message = models.Message
|
||||||
|
|
||||||
type CreateMessageInput struct {
|
type CreateMessageInput struct {
|
||||||
RecipientID int64 `form:"to" binding:"required,username"`
|
RecipientID int64 `form:"to" binding:"required,numeric"`
|
||||||
Subject string `form:"subject" binding:"required,max=200"`
|
Subject string `form:"recipient_id" binding:"required,max=200"`
|
||||||
Body string `form:"body" binding:"required"`
|
Body string `form:"body" binding:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,10 +7,10 @@ package accountMessageHandler
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
templateHandlers "synlotto-website/internal/handlers/template"
|
||||||
templateHelpers "synlotto-website/internal/helpers/template"
|
templateHelpers "synlotto-website/internal/helpers/template"
|
||||||
|
|
||||||
"synlotto-website/internal/logging"
|
"synlotto-website/internal/logging"
|
||||||
"synlotto-website/internal/models"
|
|
||||||
"synlotto-website/internal/platform/bootstrap"
|
"synlotto-website/internal/platform/bootstrap"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@@ -31,7 +31,9 @@ func (h *AccountMessageHandlers) ArchivedList(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
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 != "" {
|
if f := sm.PopString(c.Request.Context(), "flash"); f != "" {
|
||||||
ctx["Flash"] = f
|
ctx["Flash"] = f
|
||||||
}
|
}
|
||||||
@@ -39,10 +41,7 @@ func (h *AccountMessageHandlers) ArchivedList(c *gin.Context) {
|
|||||||
ctx["Title"] = "Archived Messages"
|
ctx["Title"] = "Archived Messages"
|
||||||
ctx["Messages"] = msgs
|
ctx["Messages"] = msgs
|
||||||
|
|
||||||
tmpl := templateHelpers.LoadTemplateFiles(
|
tmpl := templateHelpers.LoadTemplateFiles("layout.html", "web/templates/account/messages/archived.html")
|
||||||
"layout.html",
|
|
||||||
"web/templates/account/messages/archived.html",
|
|
||||||
)
|
|
||||||
|
|
||||||
c.Status(http.StatusOK)
|
c.Status(http.StatusOK)
|
||||||
if err := tmpl.ExecuteTemplate(c.Writer, "layout", ctx); err != nil {
|
if err := tmpl.ExecuteTemplate(c.Writer, "layout", ctx); err != nil {
|
||||||
|
|||||||
@@ -7,10 +7,10 @@ package accountMessageHandler
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
templateHandlers "synlotto-website/internal/handlers/template"
|
||||||
templateHelpers "synlotto-website/internal/helpers/template"
|
templateHelpers "synlotto-website/internal/helpers/template"
|
||||||
|
|
||||||
"synlotto-website/internal/logging"
|
"synlotto-website/internal/logging"
|
||||||
"synlotto-website/internal/models"
|
|
||||||
"synlotto-website/internal/platform/bootstrap"
|
"synlotto-website/internal/platform/bootstrap"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@@ -33,8 +33,8 @@ func (h *AccountMessageHandlers) List(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build template context just like LoginGet
|
data := templateHandlers.BuildTemplateData(app, c.Writer, c.Request)
|
||||||
ctx := templateHelpers.TemplateContext(c.Writer, c.Request, models.TemplateData{})
|
ctx := templateHelpers.TemplateContext(c.Writer, c.Request, data)
|
||||||
|
|
||||||
if f := sm.PopString(c.Request.Context(), "flash"); f != "" {
|
if f := sm.PopString(c.Request.Context(), "flash"); f != "" {
|
||||||
ctx["Flash"] = f
|
ctx["Flash"] = f
|
||||||
@@ -73,7 +73,9 @@ func (h *AccountMessageHandlers) ReadGet(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
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 != "" {
|
if f := sm.PopString(c.Request.Context(), "flash"); f != "" {
|
||||||
ctx["Flash"] = f
|
ctx["Flash"] = f
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
domain "synlotto-website/internal/domain/messages"
|
domain "synlotto-website/internal/domain/messages"
|
||||||
|
templateHandlers "synlotto-website/internal/handlers/template"
|
||||||
templateHelpers "synlotto-website/internal/helpers/template"
|
templateHelpers "synlotto-website/internal/helpers/template"
|
||||||
|
|
||||||
"synlotto-website/internal/logging"
|
"synlotto-website/internal/logging"
|
||||||
@@ -18,23 +19,22 @@ import (
|
|||||||
"github.com/justinas/nosurf"
|
"github.com/justinas/nosurf"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GET /account/messages/add
|
// GET /account/messages/send
|
||||||
// Renders: web/templates/account/messages/send.html
|
// Renders: web/templates/account/messages/send.html
|
||||||
func (h *AccountMessageHandlers) AddGet(c *gin.Context) {
|
func (h *AccountMessageHandlers) SendGet(c *gin.Context) {
|
||||||
app := c.MustGet("app").(*bootstrap.App)
|
app := c.MustGet("app").(*bootstrap.App)
|
||||||
sm := app.SessionManager
|
sm := app.SessionManager
|
||||||
|
|
||||||
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 != "" {
|
if f := sm.PopString(c.Request.Context(), "flash"); f != "" {
|
||||||
ctx["Flash"] = f
|
ctx["Flash"] = f
|
||||||
}
|
}
|
||||||
ctx["CSRFToken"] = nosurf.Token(c.Request)
|
ctx["CSRFToken"] = nosurf.Token(c.Request)
|
||||||
ctx["Title"] = "Send Message"
|
ctx["Title"] = "Send Message"
|
||||||
|
|
||||||
tmpl := templateHelpers.LoadTemplateFiles(
|
tmpl := templateHelpers.LoadTemplateFiles("layout.html", "web/templates/account/messages/send.html")
|
||||||
"layout.html",
|
|
||||||
"web/templates/account/messages/send.html",
|
|
||||||
)
|
|
||||||
|
|
||||||
c.Status(http.StatusOK)
|
c.Status(http.StatusOK)
|
||||||
if err := tmpl.ExecuteTemplate(c.Writer, "layout", ctx); err != nil {
|
if err := tmpl.ExecuteTemplate(c.Writer, "layout", ctx); err != nil {
|
||||||
@@ -43,8 +43,8 @@ func (h *AccountMessageHandlers) AddGet(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// POST /account/messages/add
|
// POST /account/messages/send
|
||||||
func (h *AccountMessageHandlers) AddPost(c *gin.Context) {
|
func (h *AccountMessageHandlers) SendPost(c *gin.Context) {
|
||||||
app := c.MustGet("app").(*bootstrap.App)
|
app := c.MustGet("app").(*bootstrap.App)
|
||||||
sm := app.SessionManager
|
sm := app.SessionManager
|
||||||
|
|
||||||
|
|||||||
@@ -38,8 +38,8 @@ func List(c *gin.Context) {
|
|||||||
|
|
||||||
rows, err := app.DB.QueryContext(c.Request.Context(), `
|
rows, err := app.DB.QueryContext(c.Request.Context(), `
|
||||||
SELECT id, numbers, game, price, purchased_at, created_at
|
SELECT id, numbers, game, price, purchased_at, created_at
|
||||||
FROM tickets
|
FROM my_tickets
|
||||||
WHERE user_id = ?
|
WHERE userId = ?
|
||||||
ORDER BY purchased_at DESC, id DESC
|
ORDER BY purchased_at DESC, id DESC
|
||||||
`, userID)
|
`, userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -66,8 +66,8 @@ func RegisterAccountRoutes(app *bootstrap.App) {
|
|||||||
messages.Use(middleware.AuthMiddleware(), middleware.RequireAuth())
|
messages.Use(middleware.AuthMiddleware(), middleware.RequireAuth())
|
||||||
{
|
{
|
||||||
messages.GET("/", msgH.List)
|
messages.GET("/", msgH.List)
|
||||||
messages.GET("/add", msgH.AddGet)
|
messages.GET("/send", msgH.SendGet)
|
||||||
messages.POST("/add", msgH.AddPost)
|
messages.POST("/send", msgH.SendPost)
|
||||||
messages.GET("/archived", msgH.ArchivedList) // renders archived.html
|
messages.GET("/archived", msgH.ArchivedList) // renders archived.html
|
||||||
messages.GET("/:id", msgH.ReadGet) // renders read.html
|
messages.GET("/:id", msgH.ReadGet) // renders read.html
|
||||||
}
|
}
|
||||||
|
|||||||
15
internal/models/message.go
Normal file
15
internal/models/message.go
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
|
type Message struct {
|
||||||
|
ID int
|
||||||
|
SenderId int
|
||||||
|
RecipientId int
|
||||||
|
Subject string
|
||||||
|
Body string
|
||||||
|
IsRead bool
|
||||||
|
IsArchived bool
|
||||||
|
CreatedAt time.Time
|
||||||
|
ArchivedAt *time.Time
|
||||||
|
}
|
||||||
12
internal/models/notification.go
Normal file
12
internal/models/notification.go
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
|
type Notification struct {
|
||||||
|
ID int
|
||||||
|
UserId int
|
||||||
|
Title string
|
||||||
|
Body string
|
||||||
|
IsRead bool
|
||||||
|
CreatedAt time.Time
|
||||||
|
}
|
||||||
@@ -13,26 +13,3 @@ type User struct {
|
|||||||
CreatedAt time.Time
|
CreatedAt time.Time
|
||||||
UpdatedAt time.Time
|
UpdatedAt time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToDo: should be in a notification model?
|
|
||||||
type Notification struct {
|
|
||||||
ID int
|
|
||||||
UserId int
|
|
||||||
Title string
|
|
||||||
Body string
|
|
||||||
IsRead bool
|
|
||||||
CreatedAt time.Time
|
|
||||||
}
|
|
||||||
|
|
||||||
// ToDo: should be in a message model?
|
|
||||||
type Message struct {
|
|
||||||
ID int
|
|
||||||
SenderId int
|
|
||||||
RecipientId int
|
|
||||||
Subject string
|
|
||||||
Body string
|
|
||||||
IsRead bool
|
|
||||||
IsArchived bool
|
|
||||||
CreatedAt time.Time
|
|
||||||
ArchivedAt *time.Time
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -37,14 +37,15 @@ func New(db *sql.DB, opts ...func(*Service)) *Service {
|
|||||||
// Ensure *Service satisfies the domain interface.
|
// Ensure *Service satisfies the domain interface.
|
||||||
var _ domain.MessageService = (*Service)(nil)
|
var _ domain.MessageService = (*Service)(nil)
|
||||||
|
|
||||||
|
// ToDo: Needs a userId on table or rename the recipiant id.. but then again dont want to expose userids to users for sending.
|
||||||
func (s *Service) ListInbox(userID int64) ([]domain.Message, error) {
|
func (s *Service) ListInbox(userID int64) ([]domain.Message, error) {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), s.Timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), s.Timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
q := `
|
q := `
|
||||||
SELECT id, from_email, to_email, subject, body, is_read, is_archived, created_at
|
SELECT id, senderId, recipientId, subject, message, is_read, is_archived, created_at
|
||||||
FROM users_messages
|
FROM users_messages
|
||||||
WHERE user_id = ? AND is_archived = FALSE
|
WHERE recipientId = ? AND is_archived = FALSE
|
||||||
ORDER BY created_at DESC`
|
ORDER BY created_at DESC`
|
||||||
q = s.bind(q)
|
q = s.bind(q)
|
||||||
|
|
||||||
@@ -57,7 +58,7 @@ func (s *Service) ListInbox(userID int64) ([]domain.Message, error) {
|
|||||||
var out []domain.Message
|
var out []domain.Message
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var m domain.Message
|
var m domain.Message
|
||||||
if err := rows.Scan(&m.ID, &m.From, &m.To, &m.Subject, &m.Body, &m.IsRead, &m.IsArchived, &m.CreatedAt); err != nil {
|
if err := rows.Scan(&m.ID, &m.SenderId, &m.RecipientId, &m.Subject, &m.Body, &m.IsRead, &m.IsArchived, &m.CreatedAt); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
out = append(out, m)
|
out = append(out, m)
|
||||||
@@ -71,9 +72,9 @@ func (s *Service) ListArchived(userID int64) ([]domain.Message, error) {
|
|||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
q := `
|
q := `
|
||||||
SELECT id, from_email, to_email, subject, body, is_read, is_archived, created_at
|
SELECT id, senderId, recipientId, subject, message, is_read, is_archived, created_at
|
||||||
FROM users_messages
|
FROM users_messages
|
||||||
WHERE user_id = ? AND is_archived = TRUE
|
WHERE recipientId = ? AND is_archived = TRUE
|
||||||
ORDER BY created_at DESC`
|
ORDER BY created_at DESC`
|
||||||
q = s.bind(q)
|
q = s.bind(q)
|
||||||
|
|
||||||
@@ -86,7 +87,7 @@ func (s *Service) ListArchived(userID int64) ([]domain.Message, error) {
|
|||||||
var out []domain.Message
|
var out []domain.Message
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var m domain.Message
|
var m domain.Message
|
||||||
if err := rows.Scan(&m.ID, &m.From, &m.To, &m.Subject, &m.Body, &m.IsRead, &m.IsArchived, &m.CreatedAt); err != nil {
|
if err := rows.Scan(&m.ID, &m.SenderId, &m.RecipientId, &m.Subject, &m.Body, &m.IsRead, &m.IsArchived, &m.CreatedAt); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
out = append(out, m)
|
out = append(out, m)
|
||||||
@@ -99,14 +100,14 @@ func (s *Service) GetByID(userID, id int64) (*domain.Message, error) {
|
|||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
q := `
|
q := `
|
||||||
SELECT id, from_email, to_email, subject, body, is_read, is_archived, created_at
|
SELECT id, senderId, recipientId, subject, message, is_read, is_archived, created_at
|
||||||
FROM users_messages
|
FROM users_messages
|
||||||
WHERE user_id = ? AND id = ?`
|
WHERE recipientId = ? AND id = ?`
|
||||||
q = s.bind(q)
|
q = s.bind(q)
|
||||||
|
|
||||||
var m domain.Message
|
var m domain.Message
|
||||||
err := s.DB.QueryRowContext(ctx, q, userID, id).
|
err := s.DB.QueryRowContext(ctx, q, userID, id).
|
||||||
Scan(&m.ID, &m.From, &m.To, &m.Subject, &m.Body, &m.IsRead, &m.IsArchived, &m.CreatedAt)
|
Scan(&m.ID, &m.SenderId, &m.RecipientId, &m.Subject, &m.Body, &m.IsRead, &m.IsArchived, &m.CreatedAt)
|
||||||
if errors.Is(err, sql.ErrNoRows) {
|
if errors.Is(err, sql.ErrNoRows) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
@@ -123,19 +124,19 @@ func (s *Service) Create(userID int64, in domain.CreateMessageInput) (int64, err
|
|||||||
switch s.Dialect {
|
switch s.Dialect {
|
||||||
case "postgres":
|
case "postgres":
|
||||||
const q = `
|
const q = `
|
||||||
INSERT INTO messages (user_id, from_email, to_email, subject, body, is_read, is_archived, created_at)
|
INSERT INTO messages (id, senderId, recipientId, subject, message, is_read, is_archived, created_at)
|
||||||
VALUES ($1, $2, $3, $4, $5, FALSE, FALSE, NOW())
|
VALUES ($1, $2, $3, $4, $5, FALSE, FALSE, NOW())
|
||||||
RETURNING id`
|
RETURNING id`
|
||||||
var id int64
|
var id int64
|
||||||
if err := s.DB.QueryRowContext(ctx, q, userID, "", in.To, in.Subject, in.Body).Scan(&id); err != nil {
|
if err := s.DB.QueryRowContext(ctx, q, userID, "", in.RecipientID, in.Subject, in.Body).Scan(&id); err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
return id, nil
|
return id, nil
|
||||||
default: // mysql/sqlite
|
default: // mysql/sqlite
|
||||||
const q = `
|
const q = `
|
||||||
INSERT INTO messages (user_id, from_email, to_email, subject, body, is_read, is_archived, created_at)
|
INSERT INTO messages (id, senderId, recipientId, subject, message is_read, is_archived, created_at)
|
||||||
VALUES (?, ?, ?, ?, ?, FALSE, FALSE, CURRENT_TIMESTAMP)`
|
VALUES (?, ?, ?, ?, ?, FALSE, FALSE, CURRENT_TIMESTAMP)`
|
||||||
res, err := s.DB.ExecContext(ctx, q, userID, "", in.To, in.Subject, in.Body)
|
res, err := s.DB.ExecContext(ctx, q, userID, "", in.RecipientID, in.Subject, in.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ func (s *Service) List(userID int64) ([]domain.Notification, error) {
|
|||||||
const q = `
|
const q = `
|
||||||
SELECT id, title, body, is_read, created_at
|
SELECT id, title, body, is_read, created_at
|
||||||
FROM notifications
|
FROM notifications
|
||||||
WHERE user_id = ?
|
WHERE userId = ?
|
||||||
ORDER BY created_at DESC`
|
ORDER BY created_at DESC`
|
||||||
|
|
||||||
rows, err := s.DB.QueryContext(ctx, q, userID)
|
rows, err := s.DB.QueryContext(ctx, q, userID)
|
||||||
@@ -69,7 +69,7 @@ func (s *Service) GetByID(userID, id int64) (*domain.Notification, error) {
|
|||||||
const q = `
|
const q = `
|
||||||
SELECT id, title, body, is_read, created_at
|
SELECT id, title, body, is_read, created_at
|
||||||
FROM notifications
|
FROM notifications
|
||||||
WHERE user_id = ? AND id = ?`
|
WHERE userId = ? AND id = ?`
|
||||||
|
|
||||||
var n domain.Notification
|
var n domain.Notification
|
||||||
err := s.DB.QueryRowContext(ctx, q, userID, id).
|
err := s.DB.QueryRowContext(ctx, q, userID, id).
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ func GetRecentMessages(db *sql.DB, userID int, limit int) []models.Message {
|
|||||||
&m.SenderId,
|
&m.SenderId,
|
||||||
&m.RecipientId,
|
&m.RecipientId,
|
||||||
&m.Subject,
|
&m.Subject,
|
||||||
&m.Message,
|
&m.Body,
|
||||||
&m.IsRead,
|
&m.IsRead,
|
||||||
&m.CreatedAt,
|
&m.CreatedAt,
|
||||||
)
|
)
|
||||||
@@ -55,7 +55,7 @@ func GetMessageByID(db *sql.DB, userID, messageID int) (*models.Message, error)
|
|||||||
`, messageID, userID)
|
`, messageID, userID)
|
||||||
|
|
||||||
var m models.Message
|
var m models.Message
|
||||||
err := row.Scan(&m.ID, &m.SenderId, &m.RecipientId, &m.Subject, &m.Message, &m.IsRead, &m.CreatedAt)
|
err := row.Scan(&m.ID, &m.SenderId, &m.RecipientId, &m.Subject, &m.Body, &m.IsRead, &m.CreatedAt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -81,7 +81,7 @@ func GetArchivedMessages(db *sql.DB, userID int, page, perPage int) []models.Mes
|
|||||||
var m models.Message
|
var m models.Message
|
||||||
err := rows.Scan(
|
err := rows.Scan(
|
||||||
&m.ID, &m.SenderId, &m.RecipientId,
|
&m.ID, &m.SenderId, &m.RecipientId,
|
||||||
&m.Subject, &m.Message, &m.IsRead,
|
&m.Subject, &m.Body, &m.IsRead,
|
||||||
&m.CreatedAt, &m.ArchivedAt,
|
&m.CreatedAt, &m.ArchivedAt,
|
||||||
)
|
)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@@ -110,7 +110,7 @@ func GetInboxMessages(db *sql.DB, userID int, page, perPage int) []models.Messag
|
|||||||
var m models.Message
|
var m models.Message
|
||||||
err := rows.Scan(
|
err := rows.Scan(
|
||||||
&m.ID, &m.SenderId, &m.RecipientId,
|
&m.ID, &m.SenderId, &m.RecipientId,
|
||||||
&m.Subject, &m.Message, &m.IsRead, &m.CreatedAt,
|
&m.Subject, &m.Body, &m.IsRead, &m.CreatedAt,
|
||||||
)
|
)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
messages = append(messages, m)
|
messages = append(messages, m)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ func GetNotificationByID(db *sql.DB, userID, notificationID int) (*models.Notifi
|
|||||||
`, notificationID, userID)
|
`, notificationID, userID)
|
||||||
|
|
||||||
var n models.Notification
|
var n models.Notification
|
||||||
err := row.Scan(&n.ID, &n.UserId, &n.Subject, &n.Body, &n.IsRead)
|
err := row.Scan(&n.ID, &n.UserId, &n.Title, &n.Body, &n.IsRead)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -27,7 +27,7 @@ func GetNotificationCount(db *sql.DB, userID int) int {
|
|||||||
var count int
|
var count int
|
||||||
err := db.QueryRow(`
|
err := db.QueryRow(`
|
||||||
SELECT COUNT(*) FROM users_notification
|
SELECT COUNT(*) FROM users_notification
|
||||||
WHERE user_id = ? AND is_read = FALSE`, userID).Scan(&count)
|
WHERE userId = ? AND is_read = FALSE`, userID).Scan(&count)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("⚠️ Failed to count notifications:", err)
|
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(`
|
rows, err := db.Query(`
|
||||||
SELECT id, subject, body, is_read, created_at
|
SELECT id, subject, body, is_read, created_at
|
||||||
FROM users_notification
|
FROM users_notification
|
||||||
WHERE user_id = ?
|
WHERE userId = ?
|
||||||
ORDER BY created_at DESC
|
ORDER BY created_at DESC
|
||||||
LIMIT ?`, userID, limit)
|
LIMIT ?`, userID, limit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -54,7 +54,7 @@ func GetRecentNotifications(db *sql.DB, userID int, limit int) []models.Notifica
|
|||||||
|
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var n models.Notification
|
var n models.Notification
|
||||||
if err := rows.Scan(&n.ID, &n.Subject, &n.Body, &n.IsRead, &n.CreatedAt); err == nil {
|
if err := rows.Scan(&n.ID, &n.Title, &n.Body, &n.IsRead, &n.CreatedAt); err == nil {
|
||||||
notifications = append(notifications, n)
|
notifications = append(notifications, n)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,20 +7,27 @@
|
|||||||
<div class="card mb-3">
|
<div class="card mb-3">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<h5 class="card-title">{{ .Subject }}</h5>
|
<h5 class="card-title">{{ .Subject }}</h5>
|
||||||
<p class="card-text">{{ .Message }}</p>
|
<p class="card-text">{{ .Body }}</p>
|
||||||
<p class="card-text">
|
<p class="card-text">
|
||||||
<small class="text-muted">Archived: {{ .ArchivedAt.Format "02 Jan 2006 15:04" }}</small>
|
<small class="text-muted">
|
||||||
|
Archived:
|
||||||
|
{{ if .ArchivedAt.Valid }}
|
||||||
|
{{ .ArchivedAt.Time.Format "02 Jan 2006 15:04" }}
|
||||||
|
{{ else }}
|
||||||
|
—
|
||||||
|
{{ end }}
|
||||||
|
</small>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<form method="POST" action="/account/messages/restore" class="m-0">
|
<form method="POST" action="/account/messages/restore" class="m-0">
|
||||||
{{ $.CSRFField }}
|
<input type="hidden" name="csrf_token" value="{{ $.CSRFToken }}">
|
||||||
<input type="hidden" name="id" value="{{ .ID }}">
|
<input type="hidden" name="id" value="{{ .ID }}">
|
||||||
<button type="submit" class="btn btn-sm btn-outline-success">Restore</button>
|
<button type="submit" class="btn btn-sm btn-outline-success">Restore</button>
|
||||||
</form>
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
<!-- Pagination Controls -->
|
<!-- Pagination Controls (keep if your funcs exist) -->
|
||||||
<nav>
|
<nav>
|
||||||
<ul class="pagination">
|
<ul class="pagination">
|
||||||
{{ if gt .Page 1 }}
|
{{ if gt .Page 1 }}
|
||||||
|
|||||||
@@ -1,25 +1,25 @@
|
|||||||
{{ define "content" }}
|
{{ define "content" }}
|
||||||
<!-- Todo lists messages but doesn't show which ones have been read and unread-->
|
|
||||||
<div class="container py-5">
|
<div class="container py-5">
|
||||||
<h2>Your Inbox</h2>
|
<h2>Your Inbox</h2>
|
||||||
|
|
||||||
{{ if .Messages }}
|
{{ if .Messages }}
|
||||||
<ul class="list-group mb-4">
|
<ul class="list-group mb-4">
|
||||||
{{ range .Messages }}
|
{{ range .Messages }}
|
||||||
<li class="list-group-item d-flex justify-content-between align-items-center">
|
<li class="list-group-item d-flex justify-content-between align-items-center">
|
||||||
<div>
|
<div>
|
||||||
<a href="/account/messages/read?id={{ .ID }}" class="fw-bold text-dark">{{ .Subject }}</a>
|
<a href="/account/messages/{{ .ID }}" class="fw-bold text-dark">{{ .Subject }}</a><br>
|
||||||
<br>
|
|
||||||
<small class="text-muted">{{ .CreatedAt.Format "02 Jan 2006 15:04" }}</small>
|
<small class="text-muted">{{ .CreatedAt.Format "02 Jan 2006 15:04" }}</small>
|
||||||
</div>
|
</div>
|
||||||
<form method="POST" action="/account/messages/archive?id={{ .ID }}" class="m-0">
|
<form method="POST" action="/account/messages/archive" class="m-0">
|
||||||
{{ $.CSRFField }}
|
<input type="hidden" name="csrf_token" value="{{ $.CSRFToken }}">
|
||||||
<input type="hidden" name="id" value="{{ .ID }}">
|
<input type="hidden" name="id" value="{{ .ID }}">
|
||||||
<button type="submit" class="btn btn-sm btn-outline-secondary">Archive</button>
|
<button type="submit" class="btn btn-sm btn-outline-secondary">Archive</button>
|
||||||
</form>
|
</form>
|
||||||
</li>
|
</li>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</ul>
|
</ul>
|
||||||
<!-- Pagination -->
|
|
||||||
|
<!-- (Optional) Pagination if you have helpers wired -->
|
||||||
<nav>
|
<nav>
|
||||||
<ul class="pagination">
|
<ul class="pagination">
|
||||||
{{ if gt .CurrentPage 1 }}
|
{{ if gt .CurrentPage 1 }}
|
||||||
@@ -41,10 +41,8 @@
|
|||||||
{{ end }}
|
{{ end }}
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
|
|
||||||
{{ else }}
|
{{ else }}
|
||||||
<div class="alert alert-info">No messages found.</div>
|
<div class="alert alert-info text-center">No messages found.</div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
<div class="mt-3">
|
<div class="mt-3">
|
||||||
|
|||||||
@@ -4,8 +4,15 @@
|
|||||||
<h2>{{ .Message.Subject }}</h2>
|
<h2>{{ .Message.Subject }}</h2>
|
||||||
<p class="text-muted">Received: {{ .Message.CreatedAt.Format "02 Jan 2006 15:04" }}</p>
|
<p class="text-muted">Received: {{ .Message.CreatedAt.Format "02 Jan 2006 15:04" }}</p>
|
||||||
<hr>
|
<hr>
|
||||||
<p>{{ .Message.Message }}</p>
|
<p>{{ .Message.Body }}</p>
|
||||||
<a href="/account/messages" class="btn btn-secondary mt-4">Back to Inbox</a> <a href="/account/messages/archive?id={{ .Message.ID }}" class="btn btn-outline-danger mt-3">Archive</a>
|
|
||||||
|
<form method="POST" action="/account/messages/archive" class="d-inline">
|
||||||
|
<input type="hidden" name="csrf_token" value="{{ $.CSRFToken }}">
|
||||||
|
<input type="hidden" name="id" value="{{ .Message.ID }}">
|
||||||
|
<button type="submit" class="btn btn-outline-danger mt-3">Archive</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<a href="/account/messages" class="btn btn-secondary mt-3">Back to Inbox</a>
|
||||||
{{ else }}
|
{{ else }}
|
||||||
<div class="alert alert-danger text-center">
|
<div class="alert alert-danger text-center">
|
||||||
Message not found or access denied.
|
Message not found or access denied.
|
||||||
|
|||||||
@@ -1,24 +1,32 @@
|
|||||||
{{ define "content" }}
|
{{ define "content" }}
|
||||||
<div class="container py-5">
|
<div class="container py-5">
|
||||||
<h2>Send a Message</h2>
|
<h2>Send a Message</h2>
|
||||||
|
|
||||||
{{ if .Flash }}
|
{{ if .Flash }}
|
||||||
<div class="alert alert-info">{{ .Flash }}</div>
|
<div class="alert alert-info">{{ .Flash }}</div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
{{ if .Error }}
|
||||||
|
<div class="alert alert-danger">{{ .Error }}</div>
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
<form method="POST" action="/account/messages/send">
|
<form method="POST" action="/account/messages/send">
|
||||||
{{ .CSRFField }}
|
<input type="hidden" name="csrf_token" value="{{ .CSRFToken }}">
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="recipient_id" class="form-label">Recipient User ID</label>
|
<label for="recipient_id" class="form-label">Recipient User ID</label>
|
||||||
<input type="number" class="form-control" name="recipient_id" required>
|
<input type="number" class="form-control" name="recipient_id" value="{{ with .Form }}{{ .RecipientID }}{{ end }}" required>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="subject" class="form-label">Subject</label>
|
<label for="subject" class="form-label">Subject</label>
|
||||||
<input type="text" class="form-control" name="subject" required>
|
<input type="text" class="form-control" name="subject" value="{{ with .Form }}{{ .Subject }}{{ end }}" required>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="message" class="form-label">Message</label>
|
<label for="body" class="form-label">Message</label>
|
||||||
<textarea class="form-control" name="message" rows="5" required></textarea>
|
<textarea class="form-control" name="body" rows="5" required>{{ with .Form }}{{ .Body }}{{ end }}</textarea>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button type="submit" class="btn btn-primary">Send</button>
|
<button type="submit" class="btn btn-primary">Send</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
<a href="/legal/terms">Terms & Conditions</a> |
|
<a href="/legal/terms">Terms & Conditions</a> |
|
||||||
<a href="/contact">Contact Us</a>
|
<a href="/contact">Contact Us</a>
|
||||||
<br>
|
<br>
|
||||||
The content and operations of this website have not been approved or endorsed by {{ $lotteryOperator }} or the {{ $commisionName }}.
|
|
||||||
</small>
|
</small>
|
||||||
</footer>
|
</footer>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
Reference in New Issue
Block a user