imc-vibe/backend/internal/api/handlers/queue.go
2026-03-21 22:41:23 +01:00

58 lines
1.2 KiB
Go

package handlers
import (
"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 {
Error(w, http.StatusInternalServerError, "failed to get queue")
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)
}