added filter by city
This commit is contained in:
@@ -22,27 +22,19 @@ public class UserService {
|
||||
private final UserRepository repository;
|
||||
private final FileStorageService fileStorageService;
|
||||
|
||||
public User getCurrentUser() {
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
public User getCurrentUser() {
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
|
||||
if (authentication == null || authentication.getPrincipal() == null) {
|
||||
throw new ApiException(
|
||||
ErrorCode.UNAUTHORIZED,
|
||||
"Пользователь не авторизован",
|
||||
HttpStatus.UNAUTHORIZED
|
||||
);
|
||||
if (authentication == null || authentication.getPrincipal() == null) {
|
||||
throw new ApiException(ErrorCode.UNAUTHORIZED, "Пользователь не авторизован", HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
|
||||
String login = (String) authentication.getPrincipal();
|
||||
|
||||
return repository.findByLogin(login)
|
||||
.orElseThrow(() -> new ApiException(ErrorCode.NOT_FOUND, "User not found", HttpStatus.NOT_FOUND));
|
||||
}
|
||||
|
||||
String login = (String) authentication.getPrincipal();
|
||||
|
||||
return repository.findByLogin(login)
|
||||
.orElseThrow(() -> new ApiException(
|
||||
ErrorCode.NOT_FOUND,
|
||||
"User not found",
|
||||
HttpStatus.NOT_FOUND
|
||||
));
|
||||
}
|
||||
|
||||
public UserResponseDto updateUser(Long id, UserUpdateDto dto) {
|
||||
User user = repository.findById(id)
|
||||
.orElseThrow(() -> new EntityNotFoundException("User not found"));
|
||||
@@ -73,10 +65,15 @@ public class UserService {
|
||||
repository.save(user);
|
||||
|
||||
UserResponseDto userResponseDto = getUserResponseDto(user);
|
||||
log.info("User updated: {}", userResponseDto);
|
||||
log.info("User updated: {}", userResponseDto.getLogin());
|
||||
return userResponseDto;
|
||||
}
|
||||
|
||||
public Long getUserIdByLogin(String login) {
|
||||
return repository.findUserByLogin(login)
|
||||
.orElseThrow(() -> new EntityNotFoundException("User not found"));
|
||||
}
|
||||
|
||||
private static UserResponseDto getUserResponseDto(User user) {
|
||||
return UserResponseDto.builder()
|
||||
.id(user.getId())
|
||||
@@ -89,8 +86,4 @@ public class UserService {
|
||||
.build();
|
||||
}
|
||||
|
||||
public Long getUserIdByLogin(String login) {
|
||||
return repository.findUserByLogin(login)
|
||||
.orElseThrow(() -> new EntityNotFoundException("User not found"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user