added filter by city

This commit is contained in:
SlimusMinus
2026-08-05 00:52:00 +03:00
parent 458ef136d3
commit e7dfef7327
10 changed files with 469 additions and 234 deletions

View File

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