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ФильмЖанр фильма