Files
omnex/control-plane/api/internal/profile/handler.go
T
Nuxgrid ef280799c1
ci-api / test (push) Failing after 34m42s
ci-web / test (push) Failing after 24m16s
feat: add profile route and ui
2026-07-28 22:00:46 +02:00

43 lines
786 B
Go

package profile
import (
"net/http"
"github.com/gin-gonic/gin"
)
type Handler struct {
store Store
}
func NewHandler(store Store) *Handler {
return &Handler{store: store}
}
type newUsername struct {
Username string `json:"username" binding:"required,min=2,max=120"`
}
func (h *Handler) UpdateUsernameById(c *gin.Context) {
var u newUsername
if err := c.ShouldBindJSON(&u); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "requête invalide"})
return
}
id, ok := c.MustGet("id").(string)
if !ok {
c.JSON(http.StatusUnauthorized, gin.H{"error": "id invalide"})
return
}
user, err := h.store.UpdateUsername(id, u.Username)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "erreur serveur"})
return
}
c.JSON(http.StatusOK, user)
}