From 1d1b1404b0bc1d35bc87cbc63055c7b73604d2c6 Mon Sep 17 00:00:00 2001 From: "ityurner02@mail.ru" Date: Mon, 1 May 2023 17:36:10 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=A04=20=D0=B6=D0=B0=D0=BD=D1=80=D1=8B?= =?UTF-8?q?=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D1=8E=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../vue-project/src/mixins/CatalogMixins.js | 2 +- data.mv.db | Bin 40960 -> 53248 bytes .../DataBase/controller/GenreController.java | 28 +++++++----------- .../is/lab1/DataBase/controller/GenreDTO.java | 5 ++-- .../ulstu/is/lab1/DataBase/model/Genre.java | 9 +++--- .../lab1/DataBase/service/GenreService.java | 7 +++++ .../ru/ulstu/is/lab1/WebConfiguration.java | 2 +- 7 files changed, 27 insertions(+), 26 deletions(-) diff --git a/Frontend/vue-project/src/mixins/CatalogMixins.js b/Frontend/vue-project/src/mixins/CatalogMixins.js index 4b493d2..3c700ba 100644 --- a/Frontend/vue-project/src/mixins/CatalogMixins.js +++ b/Frontend/vue-project/src/mixins/CatalogMixins.js @@ -82,7 +82,7 @@ const CatalogMixin = { const promises = []; const self = this; this.selectedItems.forEach(item => { - promises.push(DataService.delete(this.dataUrl + item)); + promises.push(DataService.delete(this.dataUrl + "/" + item)); }); Promise.all(promises).then((results) => { results.forEach(function (id) { diff --git a/data.mv.db b/data.mv.db index 39ecef297863bc91c813c2a06954aaeb84d72935..8c0e32d4c5f56ed55f96b372f5925842eb87b38c 100644 GIT binary patch literal 53248 zcmeHQ&2JpZb?+Hc(wMYX{?Kj$BY=BnwJRx^ope=yPi$w0L#6b5}4$ z3KXSCxg>|c=O8eQAV5C;fW)Ug895{e1GW#w2sUg3h7tIbTysdS$?K}F?&_ZIVe?~m zsa4Hkx_hR(>h-UxtLwe@d#~0yxaIEdd*5N((Stt^I!IBJmiN(>$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main/java/ru/ulstu/is/lab1/DataBase/controller/GenreController.java b/src/main/java/ru/ulstu/is/lab1/DataBase/controller/GenreController.java index d0db0aa..51c88f4 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 @@ -1,16 +1,9 @@ package ru.ulstu.is.lab1.DataBase.controller; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PatchMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import ru.ulstu.is.lab1.DataBase.service.GenreService; +import javax.validation.Valid; import java.util.List; @RestController @@ -18,7 +11,6 @@ import java.util.List; public class GenreController { private final GenreService genreService; - @Autowired public GenreController(GenreService genreService) { this.genreService = genreService; } @@ -28,19 +20,19 @@ public class GenreController { return new GenreDTO(genreService.findGenre(id)); } - @GetMapping + @GetMapping("/") public List getGenre() { return genreService.findAllGenres().stream().map(GenreDTO::new).toList(); } - @PostMapping - public GenreDTO createGenre(@RequestParam("name") String name) { - return new GenreDTO(genreService.addGenre(name)); + @PostMapping("/") + public GenreDTO createGenre(@RequestBody @Valid GenreDTO genreDTO) { + return new GenreDTO(genreService.addGenre(genreDTO.getName())); } - @PatchMapping("/{id}") - public GenreDTO updateGenre(@PathVariable Long id, @RequestParam("name") String name) { - return new GenreDTO(genreService.updateGenre(id, name)); + @PutMapping("/{id}") + public GenreDTO updateGenre(@PathVariable Long id, @RequestBody @Valid GenreDTO genreDTO) { + return new GenreDTO(genreService.updateGenre(id, genreDTO.getName())); } @DeleteMapping("/{id}") @@ -48,7 +40,7 @@ public class GenreController { return new GenreDTO(genreService.deleteGenre(id)); } - @DeleteMapping + @DeleteMapping("/") public void deleteAllGenres(){ genreService.deleteAllGenres(); } diff --git a/src/main/java/ru/ulstu/is/lab1/DataBase/controller/GenreDTO.java b/src/main/java/ru/ulstu/is/lab1/DataBase/controller/GenreDTO.java index fa616f0..b49a765 100644 --- a/src/main/java/ru/ulstu/is/lab1/DataBase/controller/GenreDTO.java +++ b/src/main/java/ru/ulstu/is/lab1/DataBase/controller/GenreDTO.java @@ -5,16 +5,17 @@ import ru.ulstu.is.lab1.DataBase.model.Genre; public class GenreDTO { private Long id; private String name; + public GenreDTO() { + } public GenreDTO(Genre genre){ this.id = genre.getId(); this.name = genre.getName(); } - public GenreDTO() { - } public Long getId(){ return id; } public String getName(){ return name; } + public void setName(String name) { this.name = name; } } diff --git a/src/main/java/ru/ulstu/is/lab1/DataBase/model/Genre.java b/src/main/java/ru/ulstu/is/lab1/DataBase/model/Genre.java index cfb0d7a..cd9319b 100644 --- a/src/main/java/ru/ulstu/is/lab1/DataBase/model/Genre.java +++ b/src/main/java/ru/ulstu/is/lab1/DataBase/model/Genre.java @@ -3,7 +3,6 @@ package ru.ulstu.is.lab1.DataBase.model; import javax.persistence.*; import javax.validation.constraints.NotBlank; -import java.util.List; import java.util.Objects; @Entity @@ -35,10 +34,12 @@ public class Genre { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) + return true; + if (!(o instanceof Genre)) + return false; Genre genre = (Genre) o; - return Objects.equals(id, genre.id); + return Objects.equals(id, genre.id) && Objects.equals(this.name, genre.name); } @Override public int hashCode() { diff --git a/src/main/java/ru/ulstu/is/lab1/DataBase/service/GenreService.java b/src/main/java/ru/ulstu/is/lab1/DataBase/service/GenreService.java index ab78ab7..dbfb3cf 100644 --- a/src/main/java/ru/ulstu/is/lab1/DataBase/service/GenreService.java +++ b/src/main/java/ru/ulstu/is/lab1/DataBase/service/GenreService.java @@ -6,6 +6,7 @@ import ru.ulstu.is.lab1.DataBase.Repository.IGenreRepository; import ru.ulstu.is.lab1.util.validation.ValidatorUtil; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.StringUtils; import java.util.List; import java.util.Optional; @@ -21,6 +22,9 @@ public class GenreService { @Transactional public Genre addGenre(String name) { + if (!StringUtils.hasText(name)) { + throw new IllegalArgumentException("Genre name is null or empty"); + } final Genre genre = new Genre(name); validatorUtil.validate(genre); return genreRepository.save(genre); @@ -39,6 +43,9 @@ public class GenreService { @Transactional public Genre updateGenre(Long id, String name) { + if (!StringUtils.hasText(name)) { + throw new IllegalArgumentException("Genre name is null or empty"); + } final Genre currentGenre = findGenre(id); currentGenre.setName(name); validatorUtil.validate(currentGenre); diff --git a/src/main/java/ru/ulstu/is/lab1/WebConfiguration.java b/src/main/java/ru/ulstu/is/lab1/WebConfiguration.java index 59abff5..f847c1d 100644 --- a/src/main/java/ru/ulstu/is/lab1/WebConfiguration.java +++ b/src/main/java/ru/ulstu/is/lab1/WebConfiguration.java @@ -5,7 +5,7 @@ import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @Configuration -class webConfiguration implements WebMvcConfigurer { +class WebConfiguration implements WebMvcConfigurer { @Override public void addCorsMappings(CorsRegistry registry){ registry.addMapping("/**").allowedMethods("*");