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
@@ -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)}
}