RLH-17 - Update Account APIs and implement rename

This commit is contained in:
2024-11-04 11:22:34 +01:00
parent a87c692a25
commit 5175cb89b5
6 changed files with 91 additions and 14 deletions

View File

@@ -4,9 +4,11 @@ import org.apache.coyote.BadRequestException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import wtf.beatrice.releasehive.config.InternalConfiguration;
import wtf.beatrice.releasehive.dtos.EditUsernameAccountDto;
import wtf.beatrice.releasehive.dtos.LoginUserDto;
import wtf.beatrice.releasehive.dtos.RegisterUserDto;
import wtf.beatrice.releasehive.models.User;
@@ -102,4 +104,15 @@ public class AccountServiceImpl implements AccountService {
.orElseThrow();
}
@Override
public String changeUsername(EditUsernameAccountDto editData) {
User user = userRepository
.findById(editData.getUuid())
.orElseThrow(() -> new UsernameNotFoundException("User not found"));
user.setUsername(editData.getUsername());
userRepository.save(user);
return user.getUsername();
}
}