From 29605e7fbee50c54dc6a3ef082e730eb525a6ca4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=BE=D0=BB=D0=B0=D0=B9?= Date: Thu, 11 May 2023 17:18:01 +0400 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20=D0=BA?= =?UTF-8?q?=D1=80=D0=B0=D1=81=D0=B8=D0=B2=D0=BE,=20=D0=BD=D0=B5=20=D1=82?= =?UTF-8?q?=D0=B5=D1=81=D1=82=D0=B8=D0=BB,=20=D1=81=D0=BA=D0=BE=D1=80?= =?UTF-8?q?=D0=B5=D0=B5=20=D0=B2=D1=81=D0=B5=D0=B3=D0=BE=20=D1=81=D0=BB?= =?UTF-8?q?=D0=BE=D0=BC=D0=B0=D0=B5=D1=82=D1=81=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Creator/CreatorActionMvcController.java | 98 ++++++++----------- .../Reader/ReaderActionMvcController.java | 53 ++++------ .../templates/creatorAction-edit.html | 4 +- .../resources/templates/creatorAction.html | 16 +-- .../resources/templates/readerAction.html | 14 +-- 5 files changed, 68 insertions(+), 117 deletions(-) diff --git a/src/main/java/com/LabWork/app/MangaStore/controller/Creator/CreatorActionMvcController.java b/src/main/java/com/LabWork/app/MangaStore/controller/Creator/CreatorActionMvcController.java index e1a1687..e0fa8fa 100644 --- a/src/main/java/com/LabWork/app/MangaStore/controller/Creator/CreatorActionMvcController.java +++ b/src/main/java/com/LabWork/app/MangaStore/controller/Creator/CreatorActionMvcController.java @@ -34,23 +34,19 @@ public class CreatorActionMvcController { } @GetMapping() - public String getCreator(@RequestParam("login") String login, Model model, Principal principal) { - if (login.equals(principal.getName())) { - model.addAttribute("creators", - creatorService.findAllCreators().stream() - .map(CreatorMangaDto::new) - .toList()); - CreatorMangaDto currentCreator = new CreatorMangaDto(creatorService.findByLogin(login)); - model.addAttribute("currentCreator", currentCreator); - model.addAttribute("login", login); - return "creatorAction"; - } + public String getCreator(Model model, Principal principal) { + model.addAttribute("creators", + creatorService.findAllCreators().stream() + .map(CreatorMangaDto::new) + .toList()); + CreatorMangaDto currentCreator = new CreatorMangaDto(creatorService.findByLogin(principal.getName())); + model.addAttribute("currentCreator", currentCreator); return "creatorAction"; } - @GetMapping("/edit/{id}/{login}") - public String editManga(@PathVariable Long id, @PathVariable String login, Model model, Principal principal) { - if (login.equals(principal.getName())) { + @GetMapping("/edit/{id}") + public String editManga(@PathVariable Long id, Model model, Principal principal) { + if (principal.getName().equals(principal.getName())) { model.addAttribute("Id", id); model.addAttribute("mangaDto", new MangaDto(mangaService.findManga(id))); model.addAttribute("controller", "manga/"); @@ -59,66 +55,52 @@ public class CreatorActionMvcController { return "creatorAction"; } - @GetMapping("/create/{login}") - public String createManga(@PathVariable String login, Model model, Principal principal) { - if (login.equals(principal.getName())) { - model.addAttribute("login", login); - model.addAttribute("mangaDto", new MangaDto()); - model.addAttribute("controller", "creator/"); - return "creatorAction-edit"; - } - return "creatorAction"; + @GetMapping("/create") + public String createManga(Model model, Principal principal) { + model.addAttribute("mangaDto", new MangaDto()); + model.addAttribute("controller", "creator/"); + return "creatorAction-edit"; } - @PostMapping( "/creator/{login}") - public String saveManga(@PathVariable(value = "login", required = false) String login, - @RequestParam("multipartFile") MultipartFile multipartFile, + @PostMapping( "/creator") + public String saveManga(@RequestParam("multipartFile") MultipartFile multipartFile, @ModelAttribute @Valid MangaDto mangaDto, BindingResult bindingResult, Model model, Principal principal) throws IOException { - if (login.equals(principal.getName())) { - if (bindingResult.hasErrors()) { - model.addAttribute("errors", bindingResult.getAllErrors()); - return "creatorAction-edit"; - } - mangaDto.setImage("data:" + multipartFile.getContentType() + ";base64," + Base64.getEncoder().encodeToString(multipartFile.getBytes())); - mangaDto.setLogin(login); - mangaService.addManga(mangaDto); - return "redirect:/creatorAction?login=" + login; + if (bindingResult.hasErrors()) { + model.addAttribute("errors", bindingResult.getAllErrors()); + return "creatorAction-edit"; } - return "creatorAction"; + mangaDto.setImage("data:" + multipartFile.getContentType() + ";base64," + Base64.getEncoder().encodeToString(multipartFile.getBytes())); + mangaDto.setLogin(principal.getName()); + mangaService.addManga(mangaDto); + return "redirect:/creatorAction"; } - @PostMapping( "/manga/{mangaId}/{login}") - public String updateManga(@PathVariable(value = "mangaId", required = false) Long mangaId, @PathVariable(value = "login", required = false) String login, @RequestParam("multipartFile") MultipartFile multipartFile, + @PostMapping( "/manga/{mangaId}") + public String updateManga(@PathVariable(value = "mangaId", required = false) Long mangaId, @RequestParam("multipartFile") MultipartFile multipartFile, @ModelAttribute @Valid MangaDto mangaDto, BindingResult bindingResult, Model model, Principal principal) throws IOException { - if (login.equals(principal.getName())) { - if (bindingResult.hasErrors()) { - model.addAttribute("errors", bindingResult.getAllErrors()); - return "creatorAction-edit"; - } - mangaDto.setImage("data:" + multipartFile.getContentType() + ";base64," + Base64.getEncoder().encodeToString(multipartFile.getBytes())); - mangaService.updateManga(mangaId, mangaDto.getChapterCount(), mangaDto.getImage()); - return "redirect:/creatorAction?login=" + login; + if (bindingResult.hasErrors()) { + model.addAttribute("errors", bindingResult.getAllErrors()); + return "creatorAction-edit"; } - return "creatorAction"; + mangaDto.setImage("data:" + multipartFile.getContentType() + ";base64," + Base64.getEncoder().encodeToString(multipartFile.getBytes())); + mangaService.updateManga(mangaId, mangaDto.getChapterCount(), mangaDto.getImage()); + return "redirect:/creatorAction"; } - @PostMapping("/delete/{mangaId}/{login}") - public String deleteCreator(@PathVariable Long mangaId, @PathVariable String login,Principal principal) { - if (login.equals(principal.getName())) { - Long creatorId = mangaService.findManga(mangaId).getCreatorId(); - mangaService.deleteManga(mangaId); - if (creatorId != null){ - return "redirect:/creatorAction?login=" + login; - } else { - return "redirect:/creatorAction"; - } + @PostMapping("/delete/{mangaId}") + public String deleteCreator(@PathVariable Long mangaId, Principal principal) { + Long creatorId = mangaService.findManga(mangaId).getCreatorId(); + mangaService.deleteManga(mangaId); + if (creatorId != null){ + return "redirect:/creatorAction"; + } else { + return "redirect:/creatorAction"; } - return "creatorAction"; } } diff --git a/src/main/java/com/LabWork/app/MangaStore/controller/Reader/ReaderActionMvcController.java b/src/main/java/com/LabWork/app/MangaStore/controller/Reader/ReaderActionMvcController.java index 04336fb..d147637 100644 --- a/src/main/java/com/LabWork/app/MangaStore/controller/Reader/ReaderActionMvcController.java +++ b/src/main/java/com/LabWork/app/MangaStore/controller/Reader/ReaderActionMvcController.java @@ -32,20 +32,16 @@ public class ReaderActionMvcController { } @GetMapping() - public String getReader(@RequestParam("readerLogin") String readerLogin, Model model, Principal principal) { - if (readerLogin.equals(principal.getName())) { - model.addAttribute("readers", - readerService.findAllReaders().stream() - .map(ReaderMangaDto::new) - .toList()); - ReaderMangaDto currentReader = new ReaderMangaDto(readerService.findByLogin(readerLogin)); - model.addAttribute("readerLogin", readerLogin); - model.addAttribute("readerId", currentReader.getId()); - model.addAttribute("reader", new ReaderMangaDto(readerService.findReader(currentReader.getId()))); - model.addAttribute("MangaDto", new MangaDto()); - model.addAttribute("mangaList", mangaService.findAllMangas()); - return "readerAction"; - } + public String getReader(Model model, Principal principal) { + model.addAttribute("readers", + readerService.findAllReaders().stream() + .map(ReaderMangaDto::new) + .toList()); + ReaderMangaDto currentReader = new ReaderMangaDto(readerService.findByLogin(principal.getName())); + model.addAttribute("readerId", currentReader.getId()); + model.addAttribute("reader", new ReaderMangaDto(readerService.findReader(currentReader.getId()))); + model.addAttribute("MangaDto", new MangaDto()); + model.addAttribute("mangaList", mangaService.findAllMangas()); return "readerAction"; } @@ -67,30 +63,23 @@ public class ReaderActionMvcController { return "readerAction"; }*/ - @PostMapping("/manga/{readerLogin}") - public String saveManga(@PathVariable String readerLogin, - @RequestParam("mangaId") Long mangaId, + @PostMapping("/manga") + public String saveManga(@RequestParam("mangaId") Long mangaId, @ModelAttribute @Valid MangaDto MangaDto, BindingResult bindingResult, Model model, Principal principal){ - if (readerLogin.equals(principal.getName())) { - if (bindingResult.hasErrors()) { - model.addAttribute("errors", bindingResult.getAllErrors()); - return "readerAction"; - } - readerService.addManga(mangaId, readerLogin); - return "redirect:/readerAction/?readerLogin=" + readerLogin; + if (bindingResult.hasErrors()) { + model.addAttribute("errors", bindingResult.getAllErrors()); + return "readerAction"; } - return "readerAction"; + readerService.addManga(mangaId, principal.getName()); + return "redirect:/readerAction"; } - @PostMapping("/{readerLogin}/removeManga/{mangaId}") - public String removeManga(@PathVariable String readerLogin, @PathVariable Long mangaId, Principal principal) { - if (readerLogin.equals(principal.getName())) { - readerService.removeManga(mangaId, readerLogin); - return "redirect:/readerAction/?readerLogin=" + readerLogin; - } - return "readerAction"; + @PostMapping("/removeManga/{mangaId}") + public String removeManga(@PathVariable Long mangaId, Principal principal) { + readerService.removeManga(mangaId, principal.getName()); + return "redirect:/readerAction/?readerLogin=" + principal.getName(); } } diff --git a/src/main/resources/templates/creatorAction-edit.html b/src/main/resources/templates/creatorAction-edit.html index b7e664d..a4e2c13 100644 --- a/src/main/resources/templates/creatorAction-edit.html +++ b/src/main/resources/templates/creatorAction-edit.html @@ -7,7 +7,7 @@
-
+
@@ -30,7 +30,7 @@
-
+
diff --git a/src/main/resources/templates/creatorAction.html b/src/main/resources/templates/creatorAction.html index 422caad..b98cedc 100644 --- a/src/main/resources/templates/creatorAction.html +++ b/src/main/resources/templates/creatorAction.html @@ -14,23 +14,13 @@
-
-
- - -
-
@@ -45,7 +35,7 @@
- + @@ -53,7 +43,7 @@ th:attr="onclick=|confirm('Удалить запись?') && document.getElementById('remove-${manga.id}').click()|"> Удалить -
+ diff --git a/src/main/resources/templates/readerAction.html b/src/main/resources/templates/readerAction.html index 81845bf..2aa1ea9 100644 --- a/src/main/resources/templates/readerAction.html +++ b/src/main/resources/templates/readerAction.html @@ -13,7 +13,7 @@
- +
- - - -
-
@@ -58,7 +48,7 @@ th:attr="onclick=|confirm('Удалить запись?') && document.getElementById('remove-${manga.id}').click()|"> Удалить -
+