feat: add profile route and ui
This commit is contained in:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user