diff --git a/data.mv.db b/data.mv.db index 94f20c8..047e6f6 100644 Binary files a/data.mv.db and b/data.mv.db differ diff --git a/src/main/java/ru/ulstu/is/lab1/DataBase/controller/CollectionMvcController.java b/src/main/java/ru/ulstu/is/lab1/DataBase/controller/CollectionMvcController.java index 7129c6f..54505fa 100644 --- a/src/main/java/ru/ulstu/is/lab1/DataBase/controller/CollectionMvcController.java +++ b/src/main/java/ru/ulstu/is/lab1/DataBase/controller/CollectionMvcController.java @@ -6,9 +6,10 @@ import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.*; import ru.ulstu.is.lab1.DataBase.service.CollectionService; import ru.ulstu.is.lab1.DataBase.service.FilmService; -import ru.ulstu.is.lab1.DataBase.service.GenreService; +import ru.ulstu.is.lab1.DataBase.model.Film; import javax.validation.Valid; +import java.util.List; @Controller @RequestMapping("/collection") @@ -31,6 +32,23 @@ public class CollectionMvcController { return "collection"; } + @GetMapping("/films/{id}") + public String getFilmsFromCollection(@PathVariable Long id, Model model) { + List films = collectionService.getFilmsFromCollection(id); + model.addAttribute("films", films); + return "view-films"; + } + + @GetMapping("getFilms/{id}") + public String getFilms(@PathVariable Long id, Model model) { + model.addAttribute("films", + filmService.findAllFilms().stream() + .map(FilmDTO::new) + .toList()); + model.addAttribute("collectionId", id); + return "add-film"; + } + @GetMapping(value = {"/edit", "/edit/{id}"}) public String editCollection(@PathVariable(required = false) Long id, Model model) { @@ -66,17 +84,11 @@ public class CollectionMvcController { return "redirect:/collection"; } - @PostMapping(value = "/add_film/{id}/{filmId}") + @PostMapping(value = "/add_film/{id}") public String addFilm(@PathVariable(value = "id") Long id, - @PathVariable(value = "filmId") Long filmId) { - collectionService.addFilm(id, filmId); - return "redirect:/collection"; - } - - @PostMapping(value = "/del_film/{id}/{filmId}") - public String deleteFilm(@PathVariable(value = "id") Long id, - @PathVariable(value = "filmId") Long filmId) { - collectionService.deleteFilm(id, filmId); - return "redirect:/collection"; + @RequestParam("filmId") String filmId) { + Long filmIdAsLong = Long.parseLong(filmId); + collectionService.addFilm(id, filmIdAsLong); + return "redirect:../films/{id}"; } } diff --git a/src/main/java/ru/ulstu/is/lab1/DataBase/controller/GenreMvcController.java b/src/main/java/ru/ulstu/is/lab1/DataBase/controller/GenreMvcController.java index 288dbd0..b8fa169 100644 --- a/src/main/java/ru/ulstu/is/lab1/DataBase/controller/GenreMvcController.java +++ b/src/main/java/ru/ulstu/is/lab1/DataBase/controller/GenreMvcController.java @@ -62,7 +62,7 @@ public class GenreMvcController { return "redirect:/genre"; } @GetMapping("/report/{id}") - public String findWorkersOnWorkplace(@PathVariable(required = false) Long id, Model model){ + public String findFilmsOnGenre(@PathVariable(required = false) Long id, Model model){ model.addAttribute("cathegory", "Фильмы по жанру: " + genreService.findGenre(id).getName()); model.addAttribute("films", genreService.findFilmOnGenre(id).stream() .map(FilmDTO::new) diff --git a/src/main/java/ru/ulstu/is/lab1/DataBase/service/CollectionService.java b/src/main/java/ru/ulstu/is/lab1/DataBase/service/CollectionService.java index d22d4cd..f1336e4 100644 --- a/src/main/java/ru/ulstu/is/lab1/DataBase/service/CollectionService.java +++ b/src/main/java/ru/ulstu/is/lab1/DataBase/service/CollectionService.java @@ -97,4 +97,15 @@ public class CollectionService { collection.removeFilm(film); return collectionRepository.save(collection); } + + @Transactional + public List getFilmsFromCollection(Long collectionId){ + Optional collectionOptional = collectionRepository.findById(collectionId); + if (collectionOptional.isPresent()) { + Collection collection = collectionOptional.get(); + return collection.getFilms(); + } else { + throw new IllegalArgumentException("Collection not found with id: " + collectionId); + } + } } diff --git a/src/main/resources/templates/add-film.html b/src/main/resources/templates/add-film.html new file mode 100644 index 0000000..c2f0dd8 --- /dev/null +++ b/src/main/resources/templates/add-film.html @@ -0,0 +1,28 @@ + + + + + +
+
+
+
+

Выберите фильм:

+ +
+
+ + + Назад + +
+
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/collection.html b/src/main/resources/templates/collection.html index e0930d4..3c285a1 100644 --- a/src/main/resources/templates/collection.html +++ b/src/main/resources/templates/collection.html @@ -34,6 +34,12 @@ th:attr="onclick=|confirm('Удалить запись?') && document.getElementById('remove-${collection.id}').click()|"> Удалить + + Посмотреть фильмы + + Добавить фильмы