[feature/backend] update put /users/me endpoint, allow setting username and display name
This commit is contained in:
parent
1526c27b49
commit
79912925db
4 changed files with 46 additions and 3 deletions
|
@ -40,6 +40,25 @@ func (s *serviceImpl) UpdateUser(ctx context.Context, userID int, input *types.U
|
|||
// Start building the update
|
||||
update := s.client.User.UpdateOneID(userID)
|
||||
|
||||
// Update username if provided
|
||||
if input.Username != "" {
|
||||
// Check if username is already taken
|
||||
exists, err := s.client.User.Query().
|
||||
Where(user.And(
|
||||
user.UsernameEQ(input.Username),
|
||||
user.IDNEQ(userID),
|
||||
)).
|
||||
Exist(ctx)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Failed to check username availability")
|
||||
return nil, fmt.Errorf("failed to check username availability: %w", err)
|
||||
}
|
||||
if exists {
|
||||
return nil, fmt.Errorf("username already taken")
|
||||
}
|
||||
update.SetUsername(input.Username)
|
||||
}
|
||||
|
||||
// Update email if provided
|
||||
if input.Email != "" {
|
||||
update.SetEmail(input.Email)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue