From b07faa67c58d2070583b88ff405ed6e9a469b081 Mon Sep 17 00:00:00 2001 From: "ityurner02@mail.ru" Date: Wed, 3 May 2023 22:18:30 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=A04=20=D1=81=D1=87=D0=B8=D1=82=D1=8B?= =?UTF-8?q?=D0=B2=D0=B0=D1=8E=D1=82=D1=81=D1=8F=20=D0=B6=D0=B0=D0=BD=D1=80?= =?UTF-8?q?=D1=8B=20=D0=B4=D0=BB=D1=8F=20=D0=BA=D0=B0=D0=B6=D0=B4=D0=BE?= =?UTF-8?q?=D0=B3=D0=BE=20=D1=84=D0=B8=D0=BB=D1=8C=D0=BC=D0=B0,=20=D0=BD?= =?UTF-8?q?=D0=BE=20=D0=BD=D0=B5=20=D1=80=D0=B5=D0=B4=D0=B0=D0=BA=D1=82?= =?UTF-8?q?=D0=B8=D1=80=D1=83=D1=8E=D1=82=D1=81=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/CatalogFilms.vue | 102 ++++++++++++++++++ .../vue-project/src/components/DataTable.vue | 2 +- Frontend/vue-project/src/components/Modal.vue | 9 +- Frontend/vue-project/src/main.js | 4 +- data.mv.db | Bin 53248 -> 32768 bytes .../DataBase/controller/FilmController.java | 63 +++-------- .../is/lab1/DataBase/controller/FilmDTO.java | 19 ++-- .../is/lab1/DataBase/controller/GenreDTO.java | 1 - .../ulstu/is/lab1/DataBase/model/Genre.java | 8 +- .../is/lab1/DataBase/service/FilmService.java | 66 ++++++++---- 10 files changed, 187 insertions(+), 87 deletions(-) create mode 100644 Frontend/vue-project/src/components/CatalogFilms.vue diff --git a/Frontend/vue-project/src/components/CatalogFilms.vue b/Frontend/vue-project/src/components/CatalogFilms.vue new file mode 100644 index 0000000..6dae233 --- /dev/null +++ b/Frontend/vue-project/src/components/CatalogFilms.vue @@ -0,0 +1,102 @@ + + + \ No newline at end of file diff --git a/Frontend/vue-project/src/components/DataTable.vue b/Frontend/vue-project/src/components/DataTable.vue index 036f145..5d6b33c 100644 --- a/Frontend/vue-project/src/components/DataTable.vue +++ b/Frontend/vue-project/src/components/DataTable.vue @@ -65,6 +65,6 @@ user-select: none; } *{ - color: white; + color: red; } \ No newline at end of file diff --git a/Frontend/vue-project/src/components/Modal.vue b/Frontend/vue-project/src/components/Modal.vue index f12c004..4dd2b91 100644 --- a/Frontend/vue-project/src/components/Modal.vue +++ b/Frontend/vue-project/src/components/Modal.vue @@ -57,7 +57,10 @@ \ No newline at end of file diff --git a/Frontend/vue-project/src/main.js b/Frontend/vue-project/src/main.js index 75e6397..ccfdb17 100644 --- a/Frontend/vue-project/src/main.js +++ b/Frontend/vue-project/src/main.js @@ -9,6 +9,7 @@ import Form from './components/Form.vue' import Table from './components/Table.vue' import Catalogs from './components/Catalogs.vue' import CatalogGenres from './components/CatalogGenres.vue' +import CatalogFilms from './components/CatalogFilms.vue' const routes = [ @@ -20,7 +21,8 @@ const routes = [ { path: '/form', component: Form}, { path: '/table', component: Table}, { path: '/catalogs', component: Catalogs}, - { path: '/catalogs/genres', component: CatalogGenres} + { path: '/catalogs/genres', component: CatalogGenres}, + { path: '/catalogs/films', component: CatalogFilms} ] const router = createRouter({ diff --git a/data.mv.db b/data.mv.db index 8c0e32d4c5f56ed55f96b372f5925842eb87b38c..a977f73d80b74bbab7b4f5400ede9d0d82b38451 100644 GIT binary patch literal 32768 zcmeHQ%X1q^8K04zMA++OH_3*orGSZ&Y+}%g>7KV(sK~Y)Yi%ozBDD}~vE|sQ$}X)cYkD;O_~zF= zJ>U2JzHTqoan;-0@jv9p?!)hsI#N}&>OXk0{b5}*tNt!=`y{9%+cHUrux{aMxU;+E z_My;Ivitbq&UTb9+$4Sf0okqVy5V8hCsUI62m}NI0s(=5KtLcM5D*9m1Ox&C0fB%( zKp^lMAh5*kets18|7*}ILIi<;KtLcM5D*9m1Ox&C0fB%(Kp-Fx5C|ME0z;CY2LWu7 z?K-M%xsU3)1BYjI7eWEH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>n4Ac??ck$gk8v*yp!+FW zkS2VU7N~{RRC0m)0*$r1~F7mk=^k2b-U_Jb=E2eb?0N&sjpiGtbvnjV=EQ zh7nXjx*B*Q)Ifw9+;Mi#L8!s`PYwAp21Cq$JooKmXCc%Sl7&!17hsyu7Fh^I7Q!>i zLTDY4h0qdN2w&wagql*<5acFnUio2t=Azv!k_%f^*bF~lYdEtQ2_sg5X7B?}oEn{` z#{-XhtSaTx<>8d%&t*^NUBo7f>6jvIGkFU`jbe$9Pv)MIFb$eW`Q5yL2BU{y7SoYW z=vTmCINg%i)$lA_B3oqVwRX|RalJRBnAv|jX*#kAP^7; z2m}NI0s(=5KtLcM5D*9m1Ox&{A`tukQ~!J7|F={BzXOZN+nVp4)Ms9P-NOF^6yB8g diff --git a/src/main/java/ru/ulstu/is/lab1/DataBase/controller/FilmController.java b/src/main/java/ru/ulstu/is/lab1/DataBase/controller/FilmController.java index f4c84d8..d1937b3 100644 --- a/src/main/java/ru/ulstu/is/lab1/DataBase/controller/FilmController.java +++ b/src/main/java/ru/ulstu/is/lab1/DataBase/controller/FilmController.java @@ -1,19 +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 ru.ulstu.is.lab1.DataBase.model.Film; +import org.springframework.web.bind.annotation.*; import ru.ulstu.is.lab1.DataBase.service.FilmService; -import java.io.IOException; -import java.util.ArrayList; +import javax.validation.Valid; import java.util.List; @RestController @@ -21,7 +11,6 @@ import java.util.List; public class FilmController { private final FilmService filmService; - @Autowired public FilmController(FilmService filmService) { this.filmService = filmService; } @@ -37,41 +26,13 @@ public class FilmController { } @PostMapping - public FilmDTO createFilm(@RequestParam("name") String name, @RequestParam("GenresId") String GenresId) throws IOException { - List ids = new ArrayList<>(); - String num = ""; - if(GenresId.length() == 0) - GenresId = ""; - for (Character sm: - GenresId.toCharArray()) { - if(sm.equals('-')) - { - ids.add(Long.parseLong(num)); - num=""; - } - else - num+=sm; - } - return new FilmDTO(filmService.addFilm(name, ids)); + public FilmDTO createFilm(@RequestBody @Valid FilmDTO filmDTO) { + return new FilmDTO(filmService.addFilm(filmDTO.getName())); } - @PatchMapping("/{id}") - public FilmDTO updateFilm(@PathVariable Long id, @RequestParam("name") String name, @RequestParam("GenresId") String GenresId) { - List ids = new ArrayList<>(); - String num = ""; - if(GenresId.length() == 0) - GenresId = ""; - for (Character sm: - GenresId.toCharArray()) { - if(sm.equals('-')) - { - ids.add(Long.parseLong(num)); - num=""; - } - else - num+=sm; - } - return new FilmDTO(filmService.updateFilm(id, name, ids)); + @PutMapping("/{id}") + public FilmDTO updateFilm(@PathVariable Long id, @RequestBody @Valid FilmDTO filmDTO) { + return new FilmDTO(filmService.updateFilm(id, filmDTO.getName())); } @DeleteMapping("/{id}") @@ -83,4 +44,14 @@ public class FilmController { public void deleteAllFilms(){ filmService.deleteAllFilms(); } + + @PostMapping("/add_genre/{id}") + public FilmDTO addGenre(@PathVariable Long id, @RequestParam Long genre_id) { + return new FilmDTO(filmService.addGenre(id, genre_id)); + } + + @DeleteMapping("/del_genre/{id}") + public FilmDTO delGenre(@PathVariable Long id, @RequestParam Long genre_id) { + return new FilmDTO(filmService.deleteGenre(id, genre_id)); + } } diff --git a/src/main/java/ru/ulstu/is/lab1/DataBase/controller/FilmDTO.java b/src/main/java/ru/ulstu/is/lab1/DataBase/controller/FilmDTO.java index 95ec3c4..2b18abd 100644 --- a/src/main/java/ru/ulstu/is/lab1/DataBase/controller/FilmDTO.java +++ b/src/main/java/ru/ulstu/is/lab1/DataBase/controller/FilmDTO.java @@ -1,23 +1,22 @@ package ru.ulstu.is.lab1.DataBase.controller; import ru.ulstu.is.lab1.DataBase.model.Film; +import ru.ulstu.is.lab1.DataBase.model.Genre; import java.util.List; public class FilmDTO { private Long id; private String name; - private List genreDTOList; - private List collectionDTOList; + private List genreIds; + public FilmDTO() { + } public FilmDTO(Film film){ this.id = film.getId(); this.name = film.getName(); - this.genreDTOList = film.getGenres() == null ? null : film.getGenres() - .stream() - .map(GenreDTO::new) - .toList(); - } - public FilmDTO() { + if(film.getGenres() != null) { + this.genreIds = film.getGenres().stream().map(Genre::getId).toList(); + } } public Long getId(){ return id; @@ -25,7 +24,7 @@ public class FilmDTO { public String getName(){ return name; } - public List getGenreDTOList(){ - return genreDTOList; + public List getGenreIds(){ + return genreIds; } } 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 b49a765..ff9302b 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 @@ -17,5 +17,4 @@ public class GenreDTO { 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 cd9319b..9680cde 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 @@ -34,12 +34,10 @@ public class Genre { @Override public boolean equals(Object o) { - if (this == o) - return true; - if (!(o instanceof Genre)) - return false; + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; Genre genre = (Genre) o; - return Objects.equals(id, genre.id) && Objects.equals(this.name, genre.name); + return Objects.equals(id, genre.id); } @Override public int hashCode() { 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 fd063d4..f4f9866 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 @@ -6,7 +6,9 @@ import ru.ulstu.is.lab1.DataBase.Repository.IFilmRepository; 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 javax.persistence.EntityNotFoundException; import java.io.IOException; import java.util.List; import java.util.Optional; @@ -24,17 +26,12 @@ public class FilmService { } @Transactional - public Film addFilm(String name, List genresId) throws IOException { - final Film film = new Film(name); - if(genresId.size() > 0 ) - { - for (Long id: genresId) { - Genre genre = genreService.findGenre(id); - film.addGenre(genre); - } + public Film addFilm(String name) { + if (!StringUtils.hasText(name)) { + throw new IllegalArgumentException("Film name is null or empty"); } + final Film film = new Film(name); validatorUtil.validate(film); - return filmRepository.save(film); } @@ -50,19 +47,12 @@ public class FilmService { } @Transactional - public Film updateFilm(Long id, String name, List genresId) { + public Film updateFilm(Long id, String name) { + if (!StringUtils.hasText(name)) { + throw new IllegalArgumentException("Film name is null or empty"); + } final Film currentFilm = findFilm(id); currentFilm.setName(name); - if(genresId.size()>0) - { - currentFilm.getGenres().clear(); - for (Long genreId: genresId) { - Genre genre = genreService.findGenre(genreId); - currentFilm.addGenre(genre); - } - } - else - currentFilm.getGenres().clear(); validatorUtil.validate(currentFilm); return filmRepository.save(currentFilm); } @@ -78,4 +68,40 @@ public class FilmService { public void deleteAllFilms() { filmRepository.deleteAll(); } + + @Transactional + public Film addGenre(Long filmId, Long genreId) { + final Optional filmOpt = filmRepository.findById(filmId); + + if (filmOpt.isEmpty()) { + throw new EntityNotFoundException(String.format("Film with id [%s] is not found", filmId)); + } + Film film = filmOpt.get(); + + final Genre genre = genreService.findGenre(genreId); + if (genre == null) { + throw new EntityNotFoundException(String.format("Genre with id [%s] is not found", genreId)); + } + + film.addGenre(genre); + return filmRepository.save(film); + } + + @Transactional + public Film deleteGenre(Long filmId, Long genreId) { + final Optional filmOpt = filmRepository.findById(filmId); + + if (filmOpt.isEmpty()) { + throw new EntityNotFoundException(String.format("Film with id [%s] is not found", filmId)); + } + Film film = filmOpt.get(); + + 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); + } }