diff --git a/data.mv.db b/data.mv.db index 047e6f6..945a1d3 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 54505fa..453b9f8 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 @@ -36,6 +36,7 @@ public class CollectionMvcController { public String getFilmsFromCollection(@PathVariable Long id, Model model) { List films = collectionService.getFilmsFromCollection(id); model.addAttribute("films", films); + model.addAttribute("collectionId", id); return "view-films"; } @@ -91,4 +92,11 @@ public class CollectionMvcController { collectionService.addFilm(id, filmIdAsLong); return "redirect:../films/{id}"; } + + @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/films/{id}"; + } } diff --git a/src/main/java/ru/ulstu/is/lab1/DataBase/controller/FilmMvcController.java b/src/main/java/ru/ulstu/is/lab1/DataBase/controller/FilmMvcController.java index e01fb04..29d97c2 100644 --- a/src/main/java/ru/ulstu/is/lab1/DataBase/controller/FilmMvcController.java +++ b/src/main/java/ru/ulstu/is/lab1/DataBase/controller/FilmMvcController.java @@ -37,6 +37,7 @@ public class FilmMvcController { public String getGenresFromFilm(@PathVariable Long id, Model model) { List genres = filmService.getGenresFromFilm(id); model.addAttribute("genres", genres); + model.addAttribute("filmId", id); return "view-genres"; } @@ -94,4 +95,11 @@ public class FilmMvcController { filmService.addGenres(id, genreIdsAsLong); return "redirect:../genres/{id}"; } + + @PostMapping(value = "/del_genre/{id}/{genreId}") + public String deleteFilm(@PathVariable(value = "id") Long id, + @PathVariable(value = "genreId") Long genreId) { + filmService.deleteGenre(id, genreId); + return "redirect:/film/genres/{id}"; + } } diff --git a/src/main/java/ru/ulstu/is/lab1/DataBase/service/FilmService.java b/src/main/java/ru/ulstu/is/lab1/DataBase/service/FilmService.java index 2bfd868..a4d92d5 100644 --- a/src/main/java/ru/ulstu/is/lab1/DataBase/service/FilmService.java +++ b/src/main/java/ru/ulstu/is/lab1/DataBase/service/FilmService.java @@ -82,6 +82,21 @@ public class FilmService { return filmRepository.save(film); } + @Transactional + public Film deleteGenre(Long filmId, Long genreId) { + Film film = findFilm(filmId); + if (film == null) { + throw new EntityNotFoundException(String.format("Film with id [%s] is not found", filmId)); + } + final Genre genre = genreService.findGenre(genreId); + if (genre == null) { + throw new EntityNotFoundException(String.format("Genre with id [%s] is not found", genreId)); + } + + film.removeGenre(genre); + return filmRepository.save(film); + } + @Transactional public List getGenresFromFilm(Long filmId){ Optional filmOptional = filmRepository.findById(filmId); diff --git a/src/main/resources/templates/view-films.html b/src/main/resources/templates/view-films.html index a04e1ab..367bf39 100644 --- a/src/main/resources/templates/view-films.html +++ b/src/main/resources/templates/view-films.html @@ -11,11 +11,17 @@ Название + + +
+ +
+ diff --git a/src/main/resources/templates/view-genres.html b/src/main/resources/templates/view-genres.html index a161db9..35febbf 100644 --- a/src/main/resources/templates/view-genres.html +++ b/src/main/resources/templates/view-genres.html @@ -11,11 +11,17 @@ Название + + +
+ +
+