diff --git a/data.mv.db b/data.mv.db index e070829..c3014e0 100644 Binary files a/data.mv.db and b/data.mv.db differ diff --git a/src/main/java/ru/ip/labs/labs/films/controller/ActorMvcController.java b/src/main/java/ru/ip/labs/labs/films/controller/ActorMvcController.java new file mode 100644 index 0000000..571918d --- /dev/null +++ b/src/main/java/ru/ip/labs/labs/films/controller/ActorMvcController.java @@ -0,0 +1,52 @@ +package ru.ip.labs.labs.films.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.*; +import ru.ip.labs.labs.films.dto.ActorDTO; +import ru.ip.labs.labs.films.service.ActorService; + +import javax.validation.Valid; + +@Controller +@RequestMapping("/actor") +public class ActorMvcController { + private ActorService actorService; + public ActorMvcController(ActorService actorService) { + this.actorService = actorService; + } + @GetMapping + public String getActors(Model model) { + model.addAttribute("actors", + actorService.findAllActors().stream() + .map(ActorDTO::new).toList()); + + model.addAttribute("actorDTO", new ActorDTO()); + + return "actors-catalog"; + } + + @PostMapping(value = {"", "/{id}"}) + public String saveActor(@PathVariable(required = false) Long id, + @ModelAttribute @Valid ActorDTO actorDTO, + BindingResult bindingResult, + Model model) { + if (bindingResult.hasErrors()) { + model.addAttribute("errors", bindingResult.getAllErrors()); + return "actors-catalog"; + } + if (id == null || id <= 0) { + actorService.addActor(actorDTO.getName(), actorDTO.getSurname()); + } else { + actorService.updateActor(id, actorDTO.getName(), actorDTO.getSurname()); + } + return "redirect:/actor"; + } + + @PostMapping("/delete/{id}") + public String deleteGenre(@PathVariable Long id) { + actorService.deleteActor(id); + return "redirect:/actor"; + } +} diff --git a/src/main/java/ru/ip/labs/labs/films/controller/FilmMvcController.java b/src/main/java/ru/ip/labs/labs/films/controller/FilmMvcController.java new file mode 100644 index 0000000..399ac93 --- /dev/null +++ b/src/main/java/ru/ip/labs/labs/films/controller/FilmMvcController.java @@ -0,0 +1,70 @@ +package ru.ip.labs.labs.films.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.*; +import ru.ip.labs.labs.films.dto.FilmDTO; +import ru.ip.labs.labs.films.models.Film; +import ru.ip.labs.labs.films.service.ActorService; +import ru.ip.labs.labs.films.service.FilmsService; +import ru.ip.labs.labs.films.service.GenreService; + +import javax.validation.Valid; + +@Controller +@RequestMapping("/film") +public class FilmMvcController { + private FilmsService filmService; + private GenreService genreService; + private ActorService actorService; + public FilmMvcController(FilmsService filmService, GenreService genreService, ActorService actorService) { + this.filmService = filmService; + this.genreService = genreService; + this.actorService = actorService; + } + @GetMapping + public String getFilms(Model model) { + model.addAttribute("films", + filmService.findAllFilms().stream() + .map(FilmDTO::new).toList()); + + model.addAttribute("filmDTO", new FilmDTO()); + model.addAttribute("allGenres", + genreService.findAllGenres().stream() + .map(g -> g.getName()).toList()); + model.addAttribute("allActors", + actorService.findAllActors().stream() + .map(a -> a.getName() + " " + a.getSurname()).toList()); + + return "films-catalog"; + } + + @PostMapping(value = {"", "/{id}"}) + public String saveFilm(@PathVariable(required = false) Long id, + @ModelAttribute @Valid FilmDTO filmDTO, + BindingResult bindingResult, + Model model) { + if (bindingResult.hasErrors()) { + model.addAttribute("errors", bindingResult.getAllErrors()); + return "films-catalog"; + } + Long filmId = filmDTO.getId(); + + if (id == null || id <= 0) { + Film result = filmService.addFilm(filmDTO.getName()); + filmId = result.getId(); + } else { + filmService.updateFilm(id, filmDTO.getName()); + } + filmService.updateGenres(filmId, filmDTO.getGenre()); + filmService.updateActors(filmId, filmDTO.getFullNames()); + return "redirect:/film"; + } + + @PostMapping("/delete/{id}") + public String deleteGenre(@PathVariable Long id) { + filmService.deleteFilm(id); + return "redirect:/film"; + } +} diff --git a/src/main/java/ru/ip/labs/labs/films/controller/GenreMvcController.java b/src/main/java/ru/ip/labs/labs/films/controller/GenreMvcController.java new file mode 100644 index 0000000..68ec859 --- /dev/null +++ b/src/main/java/ru/ip/labs/labs/films/controller/GenreMvcController.java @@ -0,0 +1,52 @@ +package ru.ip.labs.labs.films.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.*; +import ru.ip.labs.labs.films.dto.GenreDTO; +import ru.ip.labs.labs.films.service.GenreService; + +import javax.validation.Valid; + +@Controller +@RequestMapping("/genre") +public class GenreMvcController { + private GenreService genreService; + public GenreMvcController(GenreService genreService) { + this.genreService = genreService; + } + @GetMapping + public String getGenres(Model model) { + model.addAttribute("genres", + genreService.findAllGenres().stream() + .map(GenreDTO::new).toList()); + + model.addAttribute("genreDTO", new GenreDTO()); + + return "genres-catalog"; + } + + @PostMapping(value = {"", "/{id}"}) + public String saveGenre(@PathVariable(required = false) Long id, + @ModelAttribute @Valid GenreDTO genreDTO, + BindingResult bindingResult, + Model model) { + if (bindingResult.hasErrors()) { + model.addAttribute("errors", bindingResult.getAllErrors()); + return "genres-catalog"; + } + if (id == null || id <= 0) { + genreService.addGenre(genreDTO.getName()); + } else { + genreService.updateGenre(id, genreDTO.getName()); + } + return "redirect:/genre"; + } + + @PostMapping("/delete/{id}") + public String deleteGenre(@PathVariable Long id) { + genreService.deleteGenre(id); + return "redirect:/genre"; + } +} diff --git a/src/main/java/ru/ip/labs/labs/films/dto/FilmDTO.java b/src/main/java/ru/ip/labs/labs/films/dto/FilmDTO.java index 3cdd2cd..b2ca5ad 100644 --- a/src/main/java/ru/ip/labs/labs/films/dto/FilmDTO.java +++ b/src/main/java/ru/ip/labs/labs/films/dto/FilmDTO.java @@ -52,10 +52,18 @@ public class FilmDTO { return fullNames; } + public void setFullNames(List fullNames) { + this.fullNames = fullNames; + } + public List getGenre() { return genre; } + public void setGenre(List genre) { + this.genre = genre; + } + @Override public String toString() { String res = "\nFilm{" + diff --git a/src/main/resources/static/css/Table.css b/src/main/resources/static/css/Table.css new file mode 100644 index 0000000..ab885e0 --- /dev/null +++ b/src/main/resources/static/css/Table.css @@ -0,0 +1,3 @@ +.selected { + background: #2150de; +} \ No newline at end of file diff --git a/src/main/resources/templates/actors-catalog.html b/src/main/resources/templates/actors-catalog.html new file mode 100644 index 0000000..fa306dd --- /dev/null +++ b/src/main/resources/templates/actors-catalog.html @@ -0,0 +1,110 @@ + + + + + + +
+
+
+ + + +
+ + + + + + + + + + + + + + + + +
#ИмяФамилия
+ +
+ +
+ + + + + + diff --git a/src/main/resources/templates/catalogs.html b/src/main/resources/templates/catalogs.html index 118fb42..6704252 100644 --- a/src/main/resources/templates/catalogs.html +++ b/src/main/resources/templates/catalogs.html @@ -6,9 +6,9 @@
- фильмы - жанры - актеры + фильмы + жанры + актеры
\ No newline at end of file diff --git a/src/main/resources/templates/films-catalog.html b/src/main/resources/templates/films-catalog.html new file mode 100644 index 0000000..480e06a --- /dev/null +++ b/src/main/resources/templates/films-catalog.html @@ -0,0 +1,120 @@ + + + + + + +
+
+
+ + + +
+ + + + + + + + + + + + + + + + + + +
#НазваниеЖанрыАктеры
+ +
+ +
+ + + + + + diff --git a/src/main/resources/templates/genres-catalog.html b/src/main/resources/templates/genres-catalog.html new file mode 100644 index 0000000..f5a694a --- /dev/null +++ b/src/main/resources/templates/genres-catalog.html @@ -0,0 +1,101 @@ + + + + + + +
+
+
+ + + +
+ + + + + + + + + + + + + + +
#Жанр
+ +
+ +
+ + + + + +