From 9fb6531f824e5f6452fbacf091fe59064d80ded1 Mon Sep 17 00:00:00 2001 From: "ityurner02@mail.ru" Date: Mon, 22 May 2023 17:29:07 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=A05=20=D0=BD=D0=B0=D1=87=D0=B0=D0=BB?= =?UTF-8?q?=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 7 ++ data.mv.db | Bin 77824 -> 69632 bytes .../controller/CollectionController.java | 3 +- .../controller/CollectionMvcController.java | 82 ++++++++++++++++++ .../DataBase/controller/FilmController.java | 3 +- .../controller/FilmMvcController.java | 79 +++++++++++++++++ .../DataBase/controller/GenreController.java | 3 +- .../controller/GenreMvcController.java | 62 +++++++++++++ .../ru/ulstu/is/lab1/WebConfiguration.java | 9 +- .../util/validation/ValidationException.java | 2 +- src/main/resources/templates/index.html | 10 +++ 11 files changed, 255 insertions(+), 5 deletions(-) create mode 100644 src/main/java/ru/ulstu/is/lab1/DataBase/controller/CollectionMvcController.java create mode 100644 src/main/java/ru/ulstu/is/lab1/DataBase/controller/FilmMvcController.java create mode 100644 src/main/java/ru/ulstu/is/lab1/DataBase/controller/GenreMvcController.java create mode 100644 src/main/resources/templates/index.html diff --git a/build.gradle b/build.gradle index b743061..fe4e924 100644 --- a/build.gradle +++ b/build.gradle @@ -14,6 +14,13 @@ repositories { dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' + implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' + implementation 'org.springframework.boot:spring-boot-devtools' + implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect' + + implementation 'org.webjars:bootstrap:5.1.3' + implementation 'org.webjars:jquery:3.6.0' + implementation 'org.webjars:font-awesome:6.1.0' implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'com.h2database:h2:2.1.210' diff --git a/data.mv.db b/data.mv.db index 195bd6ed7cf026c4d6e2b2edab7cb32e63c2206e..f8c9eb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R z2ZsV2{3e=4a*<%oF-?_8lWS5YO_9AX%j}WjMdD&N;(IzFVa{ETM{bZ1`6`|#3E6~4 z1K!($_Zsln9$w?Idl1jFgzUj_`1|5h_0q{n@zI~OC<4aUG|oviHhO?)`TravH{K^k z@&HyYrT~tE<}OUeVbK13l!*;KPk-bXIwcf@@*^0DSdf@EOiHHozZNB*`H)f4Gw+Gg zNuK7)A!ZxA$EsmhF&#tEth9deF&M|mBS;b}S3gmcB@dbenKXH5aYn`D;jm!tDX!^d zE(ybYm?#t}tf{v*V+qyt*Wzv>u7NkMeGi=LJL<1rKahjLKkTWWf9qndUi#M$g*>rJ zFA8vZRCSB}xmzMuK5UbItnHdgp{)8wP7rg9Ps^N7Zkf|gSqYexIncU)<&L!IV-QV? zz7(P#RNvTMSed%;_7m+Jaf@WzW&Q%k;0heLv$g-z>gN81{U@!uajeb>E;7bMF<}t) z{qxcT@W=nIPpoXm)UYi{ z4JSW1HT*0}4a-TT^o}?W6@RSsatI54%_OHfLId{Wn$!6rR7)BT^UMe6J5%Shg@>`l1o1fmG~gm4M--&voz2-+g6UhmgAd+qiFXV1yt-WDdI9t9k|4+u0V`R; zL@<;jf(NNpGX3j${aN9{ZBvO$08>K+VSpt79UiwUJ$lUddD0n#Bst~x;VL_LEpALc z0|n5gBK6YF!XPr@uzSULrgjg(Ga_ci^GsI_Oi6WPl9?wS72%<0mXw;W#Q)Wm$vg$2&zCdj)3H?ZTZ7-#XgekLU`2O2FD&C`zZM%$gT? zZPpwKj$ACS=eiei+`TZ-JDfGL?u9Hv@2UYfx33j`Wwb6a<2fqyZcik${|5dFZ7U6$L}R60`tzoFMZZeG=?mjy&Y5YM5^nV$iMH+ z0LaJ1nOWrFm=S({CgS1ZHGB genreIds){ + List genreIdsAsLong = genreIds.stream() + .map(Long::parseLong) + .collect(Collectors.toList()); + filmService.addGenres(id, genreIdsAsLong); + return "redirect:/film"; + } +} diff --git a/src/main/java/ru/ulstu/is/lab1/DataBase/controller/GenreController.java b/src/main/java/ru/ulstu/is/lab1/DataBase/controller/GenreController.java index d97f699..6523179 100644 --- a/src/main/java/ru/ulstu/is/lab1/DataBase/controller/GenreController.java +++ b/src/main/java/ru/ulstu/is/lab1/DataBase/controller/GenreController.java @@ -2,12 +2,13 @@ package ru.ulstu.is.lab1.DataBase.controller; import org.springframework.web.bind.annotation.*; import ru.ulstu.is.lab1.DataBase.service.GenreService; +import ru.ulstu.is.lab1.WebConfiguration; import javax.validation.Valid; import java.util.List; @RestController -@RequestMapping("/genre") +@RequestMapping(WebConfiguration.REST_API + "/genre") public class GenreController { private final GenreService genreService; 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 new file mode 100644 index 0000000..c147f6d --- /dev/null +++ b/src/main/java/ru/ulstu/is/lab1/DataBase/controller/GenreMvcController.java @@ -0,0 +1,62 @@ +package ru.ulstu.is.lab1.DataBase.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.*; +import ru.ulstu.is.lab1.DataBase.service.GenreService; + +import javax.validation.Valid; + +@Controller +@RequestMapping("/genre") +public class GenreMvcController { + private final GenreService genreService; + public GenreMvcController(GenreService genreService) { + this.genreService = genreService; + } + + @GetMapping + public String getGenres(Model model) { + model.addAttribute("genre", + genreService.findAllGenres().stream() + .map(GenreDTO::new) + .toList()); + return "genre"; + } + + @GetMapping(value = {"/edit", "/edit/{id}"}) + public String editGenre(@PathVariable(required = false) Long id, + Model model) { + if (id == null || id <= 0) { + model.addAttribute("genreDTO", new GenreDTO()); + } else { + model.addAttribute("genreId", id); + model.addAttribute("genreDTO", new GenreDTO(genreService.findGenre(id))); + } + return "genre-edit"; + } + + @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 "genre-edit"; + } + 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/ulstu/is/lab1/WebConfiguration.java b/src/main/java/ru/ulstu/is/lab1/WebConfiguration.java index f847c1d..4f079e4 100644 --- a/src/main/java/ru/ulstu/is/lab1/WebConfiguration.java +++ b/src/main/java/ru/ulstu/is/lab1/WebConfiguration.java @@ -2,10 +2,17 @@ package ru.ulstu.is.lab1; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.CorsRegistry; +import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @Configuration -class WebConfiguration implements WebMvcConfigurer { +public class WebConfiguration implements WebMvcConfigurer { + public static final String REST_API = "/api"; + @Override + public void addViewControllers(ViewControllerRegistry registry) { + WebMvcConfigurer.super.addViewControllers(registry); + registry.addViewController("rest-test"); + } @Override public void addCorsMappings(CorsRegistry registry){ registry.addMapping("/**").allowedMethods("*"); diff --git a/src/main/java/ru/ulstu/is/lab1/util/validation/ValidationException.java b/src/main/java/ru/ulstu/is/lab1/util/validation/ValidationException.java index 293032e..fe4527b 100644 --- a/src/main/java/ru/ulstu/is/lab1/util/validation/ValidationException.java +++ b/src/main/java/ru/ulstu/is/lab1/util/validation/ValidationException.java @@ -3,7 +3,7 @@ package ru.ulstu.is.lab1.util.validation; import java.util.Set; public class ValidationException extends RuntimeException{ - public ValidationException(Set errors) { + public ValidationException(Set errors) { super(String.join("\n", errors)); } } diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html new file mode 100644 index 0000000..0356770 --- /dev/null +++ b/src/main/resources/templates/index.html @@ -0,0 +1,10 @@ + + + + + VIDEOFILMS + + +

Hello!

+ + \ No newline at end of file