Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions db/migrations/00019_event_notifications_log.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
-- +goose Up
-- +goose StatementBegin
CREATE TABLE IF NOT EXISTS event_notifications_log
(
id_event_notifications_log SERIAL,
id_events INTEGER NOT NULL,
email VARCHAR(100) NOT NULL,
notification_type VARCHAR(50) NOT NULL, -- 'CREATED' | 'REMINDER_1H'
sent_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id_event_notifications_log),
CONSTRAINT fk_event_notifications_event FOREIGN KEY (id_events) REFERENCES events (id_events) ON DELETE CASCADE,
CONSTRAINT fk_event_notifications_user FOREIGN KEY (email) REFERENCES newf (email) ON DELETE CASCADE,
CONSTRAINT uq_event_notification_once UNIQUE (id_events, email, notification_type)
);
-- +goose StatementEnd

-- +goose Down
-- +goose StatementBegin
DROP TABLE IF EXISTS event_notifications_log;
-- +goose StatementEnd


16 changes: 13 additions & 3 deletions handlers/event/event_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@ import (

"github.com/gofiber/fiber/v2"
"github.com/plugimt/transat-backend/models"
"github.com/plugimt/transat-backend/services"
"github.com/plugimt/transat-backend/utils"
)

type EventHandler struct {
db *sql.DB
db *sql.DB
notifier *services.EventNotificationService
}

func NewEventHandler(db *sql.DB) *EventHandler {
func NewEventHandler(db *sql.DB, notifier *services.EventNotificationService) *EventHandler {
return &EventHandler{
db: db,
db: db,
notifier: notifier,
}
}

Expand Down Expand Up @@ -778,6 +781,13 @@ func (h *EventHandler) CreateEvent(c *fiber.Ctx) error {
utils.LogLineKeyValue(utils.LevelInfo, "Event ID", eventID)
utils.LogFooter()

// Fire-and-forget creation notification (non-blocking)
if h.notifier != nil {
go func(id int) {
_ = h.notifier.SendEventCreated(id)
}(eventID)
}

return c.Status(fiber.StatusCreated).JSON(fiber.Map{
"message": "Event created successfully",
"event": map[string]interface{}{
Expand Down
7 changes: 7 additions & 0 deletions i18n/active.de.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
[event.created]
title = "📅 Neues Ereignis erstellt"
message = "Das Ereignis '{{.Name}}' wurde für {{.StartTime}} erstellt."

[event.reminder]
title = "⏰ Ereignis beginnt in 1 Stunde"
message = "'{{.Name}}' beginnt in 1 Stunde."
[restaurant_notification]
title = "🍽️ NEUES MENÜ VERFÜGBAR!"
message = "Ein köstliches neues Menü erwartet Sie im RU! Entdecken Sie die Tagesgerichte und hinterlassen Sie Ihre Kommentare. Guten Appetit!"
Expand Down
8 changes: 8 additions & 0 deletions i18n/active.en.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ open_restaurant = "View menu"
download_app = "Download app"
open_profile = "Access my profile"

[event.created]
title = "📅 New event created"
message = "Event '{{.Name}}' created for {{.StartTime}}."

[event.reminder]
title = "⏰ Event starts in 1 hour"
message = "'{{.Name}}' starts in 1 hour."

[weather]
thunderstorm = "Thunderstorm"
drizzle = "Drizzle"
Expand Down
7 changes: 7 additions & 0 deletions i18n/active.es.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
[event.created]
title = "📅 Nuevo evento creado"
message = "El evento '{{.Name}}' se ha creado para {{.StartTime}}."

[event.reminder]
title = "⏰ El evento comienza en 1 hora"
message = "'{{.Name}}' comienza en 1 hora."
[email_verification]
title = "Tu código de verificación Transat"
subject = "🔐 Tu código de verificación Transat: {{.VerificationCode}}"
Expand Down
7 changes: 7 additions & 0 deletions i18n/active.fr.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
[event.created]
title = "📅 Nouvel évènement créé"
message = "L'évènement '{{.Name}}' est créé pour le {{.StartTime}}."

[event.reminder]
title = "⏰ L'évènement commence dans 1 heure"
Comment on lines +2 to +6
Copy link

Copilot AI Oct 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In modern French, 'événement' is the standard spelling (with 'é'), not 'évènement' (with 'è').

Suggested change
title = "📅 Nouvel évènement créé"
message = "L'évènement '{{.Name}}' est créé pour le {{.StartTime}}."
[event.reminder]
title = "⏰ L'évènement commence dans 1 heure"
title = "📅 Nouvel événement créé"
message = "L'événement '{{.Name}}' est créé pour le {{.StartTime}}."
[event.reminder]
title = "⏰ L'événement commence dans 1 heure"

Copilot uses AI. Check for mistakes.
message = "'{{.Name}}' commence dans 1 heure."
[email_verification]
title = "Ton code de vérification Transat"
subject = "🔐 Ton code de vérification Transat : {{.VerificationCode}}"
Expand Down
7 changes: 6 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func main() {
app.Use(utils.SentryHandler)

notificationService := services.NewNotificationService(db)
eventNotifier := services.NewEventNotificationService(db, notificationService)
translationService, err := services.NewTranslationService()
if err != nil {
log.Fatalf("💥 Failed to create Translation Service: %v", err)
Expand Down Expand Up @@ -100,7 +101,7 @@ func main() {

clubsHandler := club.NewclubHandler(db)

eventHandler := event.NewEventHandler(db)
eventHandler := event.NewEventHandler(db, eventNotifier)

appScheduler := scheduler.NewScheduler(restHandler)
appScheduler.StartAll()
Expand All @@ -109,6 +110,10 @@ func main() {
// Cron Jobs - Requires access to handlers/services
c := cron.New()

// Add periodic job to send 1-hour event reminders every 5 minutes
_, _ = c.AddFunc("CRON_TZ=Europe/Paris */5 * * * *", func() {
_ = eventNotifier.SendDueOneHourReminders()
})
c.Start()
defer c.Stop()

Expand Down
Loading