Conversation
Добавлено логирование
Добавлено логирование и тесты
| throw new ValidationException("Фильм с id = " + newFilm.getId() + " не найден"); | ||
| } | ||
|
|
||
| private void filmValidation(Film film) { |
There was a problem hiding this comment.
Методы лучше называть с использованием глагола, т.к. по сути это некоторые действия. Т.е. здесь лучше
validateFilm(Film film)
| log.warn("Не указан id"); | ||
| throw new ValidationException("Id должен быть указан"); | ||
| } | ||
| if (films.containsKey(newFilm.getId())) { |
There was a problem hiding this comment.
Хотел бы предложить тебе методику написания метода с помощью так называемого раннего выхода (early return). Смысл в том, чтобы выходить из метода сразу при невыполнении условий, необходимых для успешного выполнения метода. Код будет более легким для чтения.
https://habr.com/ru/articles/348074/
Твой метод можно переписать
@PutMapping
public Film update(@Valid @RequestBody Film newFilm) {
if (newFilm.getId() == null) {
log.warn("Не указан id");
throw new ValidationException("Id должен быть указан");
}
if (!films.containsKey(newFilm.getId())) {
log.warn("Фильм с указанным id не найден");
throw new ValidationException("Фильм с id = " + newFilm.getId() + " не найден");
}
validateFilm(newFilm);
Film oldFilm = films.get(newFilm.getId());
oldFilm.setDescription(newFilm.getDescription());
oldFilm.setDuration(newFilm.getDuration());
oldFilm.setName(newFilm.getName());
oldFilm.setReleaseDate(newFilm.getReleaseDate());
log.info("Данные о фильме: {} обновлены", oldFilm);
return oldFilm;
}
VadimZharkov
suggested changes
Oct 19, 2025
VadimZharkov
left a comment
There was a problem hiding this comment.
Хорошая работа, все сделано верно. Оставил пару стилистических рекомендаций.
Исправлен нейминг валидирующих методов
Owner
Author
|
Благодарю за ревью. Такой подход и вправду делает кот читабельнее. |
VadimZharkov
approved these changes
Oct 19, 2025
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Реализована функциональность согласно ТЗ спринта 10.
Добавлены тесты валидаций и логирование.