package handlers import ( "net/http" "time" "github.com/gin-gonic/gin" ) // RunNotificationsNow triggers the scanner on demand (UI-test + backfill). // Optional ?date=YYYY-MM-DD lets the teacher replay a past day's send. // Idempotent — already-logged combos are skipped. func (h *Handler) RunNotificationsNow(c *gin.Context) { uid := getUserID(c) if uid == "" { respondError(c, http.StatusUnauthorized, "User not authenticated") return } runDate := time.Now() if param := c.Query("date"); param != "" { d, err := time.Parse("2006-01-02", param) if err != nil { respondError(c, http.StatusBadRequest, "date must be YYYY-MM-DD") return } runDate = d } res, err := h.notificationService.RunForDate(c.Request.Context(), runDate) if err != nil { respondError(c, http.StatusInternalServerError, "Run failed: "+err.Error()) return } respondSuccess(c, res) } // ListEventNotifications returns the notification_log rows for one event so // the DayDetail UI can show "Erinnerung verschickt am …". func (h *Handler) ListEventNotifications(c *gin.Context) { uid := getUserID(c) if uid == "" { respondError(c, http.StatusUnauthorized, "User not authenticated") return } rows, err := h.notificationService.ListLog(c.Request.Context(), c.Param("id"), uid) if err != nil { respondError(c, http.StatusInternalServerError, err.Error()) return } respondSuccess(c, rows) }