-
Notifications
You must be signed in to change notification settings - Fork 0
Add friends likes #1
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
Conversation
| @Service | ||
| public class UserService { | ||
|
|
||
| protected static UserStorage users = Storages.getUerStorage(); |
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.
Не стоит вручную создавать объекты, Spring сам умеет внедрять необходимые зависимости
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.
Исправлено.
| */ | ||
| public User updateUser(User updUser) { | ||
| Integer id = updUser.getId(); | ||
| User user = new User(users.getUserById(id)); |
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.
Не обязательно при обновлении делать копию объекта, можно работать с текущим. В будущем, когда будет работа с бд и транзакциями, будет гораздо удобнее работать с объектом полученным из бд
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.
Убрал копирование при обновлении. Получается, что исправляем сразу объект в хранилище (даже put(...) не нужен).
| public class FilmController { | ||
|
|
||
| @Autowired | ||
| FilmService service; |
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.
Можно сделать private final
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.
исправлено.
| public class UserController { | ||
|
|
||
| @Autowired | ||
| UserService service; |
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.
Также можно сделать private final
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.
Исправлено.
|
|
||
| public Collection<Film> findPopularFilms(int count) { | ||
| List<Film> popularFilms = new ArrayList<>(); | ||
| popularFilms = films.findAllFilms().stream() |
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.
Не самы лучший подход. Например, если пользователь запросит топ 10 фильмов, то из хранилища будут извлечены все имеющиеся. Лучше фильтровать на уровне хранилища, от туда должны приходить только необходимые данные
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.
Реализовал обновляемый рейтинг в хранилище и выдачу заданного числа самых популярных фильмов.
| */ | ||
| public T addNew(T element) throws ValidationException { | ||
| // Проверяем существование полльзователя для исключения дублирования | ||
| if (storage.containsValue(element)) { |
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.
(Предложение)По идее, проверка должна происходить на уровне сервиса через Storage отдельным методом. Методы в хранилище должны быть простыми и работать с уже готовыми данными
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.
Перенес проверки в сервис.
|
|
||
| Integer id = element.getId(); | ||
| // проверяем необходимые условия | ||
| if (!storage.containsKey(id)) { |
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.
(Предложение) Аналогично, было бы логичнее проверку на наличие вынести в сервис
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.
Перенес проверки в сервис.
| /** | ||
| * Утилитарный класс для определения реализаций хранилищ данных | ||
| */ | ||
| public final class Storages { |
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.
Фабрика в данном проекте особа не нужна, Spring сам управляет бинами
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.
Удалил классы: Storages.java, StorageData, InMemoryAbstractStorage.java
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.
StorageData.java пришлось восстановить, так как в противном случае Lombok менял число аргументов в стандартных конструкторах классов модели ..
Спринт №11 итоговый проект.