generated from yandex-praktikum/java-filmorate
-
Notifications
You must be signed in to change notification settings - Fork 0
Merge add-friends-likes #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
61debed
перенес операции с фильмами и юзерами в storage сервисы
zephyr0021 ca1c5cc
Добавил exception_handler а так же немного поменял архитектуру
zephyr0021 a4ce4a6
вынес логику по созданию/обновлению в UserService
zephyr0021 375849f
Добавил методы для добавления/удаления в друзья
zephyr0021 e438016
добавил методы для возврата списка друзей пользователя и возврата спи…
zephyr0021 93ed0bc
добавил метод для выставления лайка фильму
zephyr0021 ff14c04
Закончил все endpointы с фильмами и пользователями
zephyr0021 06b92ae
переделал все тесты с использованием мокирования
zephyr0021 0a6e124
написал тесты для FilmController
zephyr0021 e301329
написал тесты для UserController
zephyr0021 fcdb153
Добавил логирование запросов/ответов в формате JSON
zephyr0021 ff8cd8c
fix codestyle
zephyr0021 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/main/java/ru/yandex/practicum/filmorate/exception/NotFoundException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/main/java/ru/yandex/practicum/filmorate/exception/OtherException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package ru.yandex.practicum.filmorate.exception; | ||
|
|
||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| public class OtherException extends RuntimeException { | ||
| String name = "server error"; | ||
|
|
||
| public OtherException(String message) { | ||
| super(message); | ||
| } | ||
| } |
5 changes: 5 additions & 0 deletions
5
src/main/java/ru/yandex/practicum/filmorate/exception/ValidationException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/main/java/ru/yandex/practicum/filmorate/handler/ErrorHandler.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| package ru.yandex.practicum.filmorate.handler; | ||
|
|
||
|
|
||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.validation.FieldError; | ||
| import org.springframework.web.bind.MethodArgumentNotValidException; | ||
| import org.springframework.web.bind.annotation.ExceptionHandler; | ||
| import org.springframework.web.bind.annotation.ResponseStatus; | ||
| import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
| import ru.yandex.practicum.filmorate.exception.NotFoundException; | ||
| import ru.yandex.practicum.filmorate.exception.OtherException; | ||
| import ru.yandex.practicum.filmorate.exception.ValidationException; | ||
| import ru.yandex.practicum.filmorate.response.ErrorResponse; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Slf4j | ||
| @RestControllerAdvice | ||
| public class ErrorHandler { | ||
|
|
||
| @ExceptionHandler | ||
| @ResponseStatus(HttpStatus.NOT_FOUND) | ||
| public ErrorResponse handleNotFound(final NotFoundException e) { | ||
| return new ErrorResponse(e.getName(), e.getMessage()); | ||
| } | ||
|
|
||
| @ExceptionHandler(MethodArgumentNotValidException.class) | ||
| @ResponseStatus(HttpStatus.BAD_REQUEST) | ||
| public ErrorResponse handleValidationException(MethodArgumentNotValidException ex) { | ||
| List<String> errors = ex.getBindingResult().getFieldErrors().stream() | ||
| .map(FieldError::getDefaultMessage) | ||
| .toList(); | ||
| String message = String.join("\n", errors); | ||
| log.warn("Ошибка валидации: {}", errors); | ||
|
|
||
| return new ErrorResponse("validation error", message); | ||
| } | ||
|
|
||
| @ExceptionHandler | ||
| @ResponseStatus(HttpStatus.BAD_REQUEST) | ||
| public ErrorResponse handleValidationError(final ValidationException e) { | ||
| return new ErrorResponse(e.getName(), e.getMessage()); | ||
| } | ||
|
|
||
| @ExceptionHandler | ||
| @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) | ||
| public ErrorResponse handleInternalServerError(final OtherException e) { | ||
| return new ErrorResponse(e.getName(), e.getMessage()); | ||
| } | ||
|
|
||
| } |
25 changes: 0 additions & 25 deletions
25
src/main/java/ru/yandex/practicum/filmorate/handler/GlobalExceptionHandler.java
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/main/java/ru/yandex/practicum/filmorate/response/ErrorResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package ru.yandex.practicum.filmorate.response; | ||
|
|
||
|
|
||
| import lombok.Data; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Data | ||
| @RequiredArgsConstructor | ||
| public class ErrorResponse { | ||
| private final String error; | ||
| private final String message; | ||
| } |
10 changes: 10 additions & 0 deletions
10
src/main/java/ru/yandex/practicum/filmorate/response/SuccessResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package ru.yandex.practicum.filmorate.response; | ||
|
|
||
| import lombok.Data; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Data | ||
| @RequiredArgsConstructor | ||
| public class SuccessResponse { | ||
| private final String status = "success"; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
В целом, в контроллерах такого вида можно ничего не возвращать – void
отсутствие исключений может быть равно успешному вызову