From f50af7950d4af55e9e8c1294aeaa0960a837f11b Mon Sep 17 00:00:00 2001 From: Kirill <117719052+KirillFirsof@users.noreply.github.com> Date: Wed, 5 Jun 2024 17:27:30 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=BD=D0=BE=20=D0=BA=D0=B0=D1=80=D0=BE?= =?UTF-8?q?=D1=87=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82=20?= =?UTF-8?q?=D0=BD=D0=BE=20=D0=B4=D0=BE=D0=B4=D0=B5=D0=BB=D0=B0=D1=8E=20?= =?UTF-8?q?=D0=BF=D0=BE=D1=82=D0=BE=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../demo/films/api/FilmController.java | 16 +++++++++++++- .../demo/films/service/FilmService.java | 8 +++++++ .../main/resources/templates/film-edit.html | 21 ++++++++++--------- .../src/main/resources/templates/film.html | 8 +++---- 4 files changed, 38 insertions(+), 15 deletions(-) diff --git a/Laba5.1/src/main/java/com/example/demo/films/api/FilmController.java b/Laba5.1/src/main/java/com/example/demo/films/api/FilmController.java index cdf5861..25ca8fa 100644 --- a/Laba5.1/src/main/java/com/example/demo/films/api/FilmController.java +++ b/Laba5.1/src/main/java/com/example/demo/films/api/FilmController.java @@ -13,6 +13,9 @@ import org.springframework.web.bind.annotation.RequestMapping; import com.example.demo.core.configuration.Constants; import com.example.demo.films.model.FilmEntity; import com.example.demo.films.service.FilmService; +import com.example.demo.genres.api.GenreDto; +import com.example.demo.genres.model.GenreEntity; +import com.example.demo.genres.service.GenreService; import jakarta.validation.Valid; @@ -24,10 +27,12 @@ public class FilmController { private static final String FILM_EDIT_VIEW = "film-edit"; private static final String FILM_ATTRIBUTE = "film"; + private final GenreService genreService; private final FilmService filmService; private final ModelMapper modelMapper; - public FilmController(FilmService filmService, ModelMapper modelMapper) { + public FilmController(GenreService genreService, FilmService filmService, ModelMapper modelMapper) { + this.genreService = genreService; this.filmService = filmService; this.modelMapper = modelMapper; } @@ -36,6 +41,10 @@ public class FilmController { return modelMapper.map(entity, FilmDto.class); } + private GenreDto toGenreDto(GenreEntity entity) { + return modelMapper.map(entity, GenreDto.class); + } + private FilmEntity toEntity(FilmDto dto) { return modelMapper.map(dto, FilmEntity.class); } @@ -53,6 +62,11 @@ public class FilmController { @GetMapping("/edit/") public String create(Model model) { model.addAttribute(FILM_ATTRIBUTE, new FilmDto()); + model.addAttribute( + "genres", + genreService.getAll().stream() + .map(this::toGenreDto) + .toList()); return FILM_EDIT_VIEW; } diff --git a/Laba5.1/src/main/java/com/example/demo/films/service/FilmService.java b/Laba5.1/src/main/java/com/example/demo/films/service/FilmService.java index 036ae18..275253b 100644 --- a/Laba5.1/src/main/java/com/example/demo/films/service/FilmService.java +++ b/Laba5.1/src/main/java/com/example/demo/films/service/FilmService.java @@ -58,6 +58,14 @@ public class FilmService { return repository.save(entity); } + @Transactional + public List createAll(long userId, List entities) { + if (entities == null || entities.isEmpty()) { + throw new IllegalArgumentException("Films list is null or empty"); + } + return StreamSupport.stream(repository.saveAll(entities).spliterator(), false).toList(); + } + @Transactional public FilmEntity update(Long id, FilmEntity entity) { final FilmEntity existsEntity = get(id); diff --git a/Laba5.1/src/main/resources/templates/film-edit.html b/Laba5.1/src/main/resources/templates/film-edit.html index 65d4fdc..3504912 100644 --- a/Laba5.1/src/main/resources/templates/film-edit.html +++ b/Laba5.1/src/main/resources/templates/film-edit.html @@ -2,7 +2,7 @@ - Редакторовать фильм + Редакторовать тип заказа @@ -12,19 +12,20 @@ -
- - -
-
- +
+
+ +
+
Отмена diff --git a/Laba5.1/src/main/resources/templates/film.html b/Laba5.1/src/main/resources/templates/film.html index e1acd02..9056764 100644 --- a/Laba5.1/src/main/resources/templates/film.html +++ b/Laba5.1/src/main/resources/templates/film.html @@ -2,7 +2,7 @@ - Фильмы + Жанры фильмов @@ -10,16 +10,16 @@

Данные отсутствуют

-

Фильмы

+

Жанры фильмов

- +
IDФильмЖанр фильма