Switch from net/http to gin-gonic web framework

- Added gin-gonic v1.10.0 dependency
- Refactored router.go: clean route groups with middleware chains
- Refactored all handlers to use gin.Context instead of http.ResponseWriter/*http.Request
- Simplified response helpers (JSON, Error, Success, Created, NoContent)
- Clean auth middleware using Gin's c.Set() for context
- Cleaner route definitions with path parameters (e.g., /domains/:name/users/:id)
- Admin routes moved to /api/admin group with RequireAdmin middleware
This commit is contained in:
Christoph Haas 2026-03-22 23:28:28 +01:00
parent 68285d861a
commit 2834657125
13 changed files with 474 additions and 812 deletions

View file

@ -4,6 +4,7 @@ import (
"log"
"net/http"
"github.com/gin-gonic/gin"
"github.com/imc-vibe/backend/internal/mail"
)
@ -13,48 +14,33 @@ 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
}
func (h *QueueHandler) List(c *gin.Context) {
entries, err := mail.GetQueue()
if err != nil {
log.Printf("Queue error: %v", err)
Error(w, http.StatusServiceUnavailable, "failed to get queue: "+err.Error())
Error(c, http.StatusServiceUnavailable, "failed to get queue: "+err.Error())
return
}
Success(w, entries)
Success(c, 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)
func (h *QueueHandler) Requeue(c *gin.Context) {
id := c.Param("id")
if err := mail.RequeueMail(id); err != nil {
Error(w, http.StatusInternalServerError, "failed to requeue mail")
Error(c, http.StatusInternalServerError, "failed to requeue mail")
return
}
Success(w, map[string]string{"message": "mail requeued"})
Success(c, 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)
func (h *QueueHandler) Delete(c *gin.Context) {
id := c.Param("id")
if err := mail.DeleteFromQueue(id); err != nil {
Error(w, http.StatusInternalServerError, "failed to delete from queue")
Error(c, http.StatusInternalServerError, "failed to delete from queue")
return
}
NoContent(w)
NoContent(c)
}