first
This commit is contained in:
commit
f4be03ceba
1826 changed files with 830924 additions and 0 deletions
58
backend/internal/api/handlers/queue.go
Normal file
58
backend/internal/api/handlers/queue.go
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
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)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue