feat: add profile route and ui
ci-api / test (push) Failing after 34m42s
ci-web / test (push) Failing after 24m16s

This commit is contained in:
Nuxgrid
2026-07-28 22:00:46 +02:00
parent cb651a04e2
commit ef280799c1
10 changed files with 297 additions and 4 deletions
+4
View File
@@ -16,6 +16,7 @@ import (
"github.com/omnex/control-plane/api/internal/demos"
"github.com/omnex/control-plane/api/internal/k8s"
"github.com/omnex/control-plane/api/internal/leads"
"github.com/omnex/control-plane/api/internal/profile"
"github.com/omnex/control-plane/api/internal/router"
"github.com/omnex/control-plane/api/internal/sav"
"github.com/omnex/control-plane/api/internal/session"
@@ -69,6 +70,7 @@ func main() {
var demoPool demos.Pool
var codeStore sub.Store
var contactStore sav.Store
var profileStore profile.Store
if cfg.DatabaseURL != "" {
gdb, err := db.Open(cfg.DatabaseURL)
if err != nil {
@@ -88,6 +90,7 @@ func main() {
demoStore = demos.NewGormStore(gdb)
demoPool = demos.NewGormPool(gdb)
contactStore = sav.NewGormStore(gdb)
profileStore = profile.NewGormStore(gdb)
log.Printf("persistance: PostgreSQL (GORM)")
} else {
userStore = seedMemUsers()
@@ -126,6 +129,7 @@ func main() {
DemosH: demos.NewHandler(demoSvc, helmProv),
SubH: sub.NewHandler(codeStore),
ContactH: sav.NewHandler(contactStore),
ProfileH: profile.NewHandler(profileStore),
}
r := router.New(deps)
@@ -5,6 +5,7 @@ import "time"
type User struct {
ID string `gorm:"type:uuid;primaryKey" json:"id"`
Username string `gorm:"uniqueIndex;size:64;not null" json:"username"`
Telegram *string `gorm:"size:120;not null" json:"telegram"`
PasswordHash string `gorm:"not null" json:"-"`
Role Role `gorm:"size:20;not null" json:"role"`
TypeAbo string `gorm:"type:varchar(35);default:demo" json:"type_abonnement"`
@@ -2,7 +2,6 @@ package leads
import (
"html"
"log"
"net/http"
"strings"
@@ -27,7 +26,6 @@ type createRequest struct {
// Les entrées sont nettoyées (trim + échappement HTML) avant stockage.
func (h *Handler) Create(c *gin.Context) {
var req createRequest
log.Printf("request-debug: %s", req)
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "requête invalide"})
return
@@ -0,0 +1,36 @@
package profile
import (
"github.com/omnex/control-plane/api/internal/auth"
"gorm.io/gorm"
)
// GormStore : Store adossé à PostgreSQL via GORM.
type GormStore struct {
db *gorm.DB
}
func NewGormStore(db *gorm.DB) *GormStore {
return &GormStore{db: db}
}
type Store interface {
UpdateUsername(id, newUsername string) (auth.User, error)
}
func (s *GormStore) UpdateUsername(id, newUsername string) (auth.User, error) {
result := s.db.Model(&auth.User{}).
Where("id = ?", id).
Update("username", newUsername)
if result.Error != nil {
return auth.User{}, result.Error
}
var user auth.User
if err := s.db.First(&user, "id = ?", id).Error; err != nil {
return auth.User{}, err
}
return user, nil
}
@@ -0,0 +1,42 @@
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)
}
+16
View File
@@ -0,0 +1,16 @@
package profile
import (
"sync"
"github.com/omnex/control-plane/api/internal/auth"
)
type MemStore struct {
mu sync.RWMutex
items map[string]auth.User
}
func NewMemStore() *MemStore {
return &MemStore{items: make(map[string]auth.User)}
}
+3 -1
View File
@@ -11,6 +11,7 @@ import (
"github.com/omnex/control-plane/api/internal/demos"
"github.com/omnex/control-plane/api/internal/httpx"
"github.com/omnex/control-plane/api/internal/leads"
"github.com/omnex/control-plane/api/internal/profile"
"github.com/omnex/control-plane/api/internal/sav"
"github.com/omnex/control-plane/api/internal/session"
"github.com/omnex/control-plane/api/internal/sub"
@@ -26,6 +27,7 @@ type Deps struct {
DemosH *demos.Handler
SubH *sub.Handler
ContactH *sav.Handler
ProfileH *profile.Handler
}
// New construit l'engine Gin avec toute la chaîne de sécurité.
@@ -61,6 +63,7 @@ func New(d Deps) *gin.Engine {
client.GET("/leads", d.LeadsH.List)
client.PATCH("/leads/:id/status", d.LeadsH.SetStatus)
client.POST("/subscription", d.SubH.AddCode)
client.POST("/profile/username", d.ProfileH.UpdateUsernameById)
}
// Espace admin : provisioning des démos (admin uniquement).
@@ -77,7 +80,6 @@ func New(d Deps) *gin.Engine {
admin.DELETE("/demos/:id", d.DemosH.Delete)
admin.POST("/demos/:id/extend", d.DemosH.Extend)
admin.POST("/demos/details", d.DemosH.ListDetails)
}
}