package handlers import ( "log" "net/http" "github.com/imc-vibe/backend/internal/mail" ) type QueueHandler struct{} func NewQueueHandler() *QueueHandler { return &QueueHandler{} } func (h *QueueHandler) List(w http.ResponseWriter, r *http.Request) { if r.Method != http.MethodGet { Error(w, http.StatusMethodNotAllowed, "method not allowed") return } entries, err := mail.GetQueue() if err != nil { log.Printf("Queue error: %v", err) Error(w, http.StatusServiceUnavailable, "failed to get queue: "+err.Error()) return } Success(w, entries) } func (h *QueueHandler) Requeue(w http.ResponseWriter, r *http.Request) { if r.Method != http.MethodPost { Error(w, http.StatusMethodNotAllowed, "method not allowed") return } id := extractID(r.URL.Path) if err := mail.RequeueMail(id); err != nil { Error(w, http.StatusInternalServerError, "failed to requeue mail") return } Success(w, map[string]string{"message": "mail requeued"}) } func (h *QueueHandler) Delete(w http.ResponseWriter, r *http.Request) { if r.Method != http.MethodDelete { Error(w, http.StatusMethodNotAllowed, "method not allowed") return } id := extractID(r.URL.Path) if err := mail.DeleteFromQueue(id); err != nil { Error(w, http.StatusInternalServerError, "failed to delete from queue") return } NoContent(w) }