feat: add api
docker-publish / publish (push) Failing after 14m14s

This commit is contained in:
Nuxgrid
2026-07-27 16:06:19 +02:00
parent 8397a4470f
commit 6b4274d12b
46 changed files with 3922 additions and 0 deletions
+60
View File
@@ -0,0 +1,60 @@
package sav
import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/omnex/control-plane/api/internal/auth"
)
type Handler struct {
store Store
}
// NewHandler crée un nouveau Handler.
func NewHandler(store Store) *Handler {
return &Handler{store: store}
}
type contactSupport struct {
Username string `json:"username"`
Telegram string `json:"telegram"`
Sujet string `json:"sujet"`
Message string `json:"message"`
}
func (h *Handler) CallSupport(c *gin.Context) {
var req contactSupport
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "requête invalide"})
return
}
contact, err := h.store.ContactSupportByUser(req.Username, req.Telegram, req.Sujet, req.Message)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "erreur serveur"})
return
}
c.JSON(http.StatusCreated, gin.H{"success": "message envoyé", "contact": contact})
}
func (h *Handler) GetMessage(c *gin.Context) {
p := auth.PrincipalFrom(c)
if p == nil {
c.JSON(http.StatusUnauthorized, gin.H{"error": "non authentifié"})
return
}
if p.Role != "admin" {
c.JSON(http.StatusUnauthorized, gin.H{"error": "role non correcte"})
return
}
getMessage, err := h.store.GetMessage()
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "erreur serveur"})
return
}
c.JSON(http.StatusCreated, gin.H{"messages": getMessage})
}