From 3d47fb12efe806eb9385c074d87656e2dc3223f6 Mon Sep 17 00:00:00 2001 From: "ityurner02@mail.ru" Date: Thu, 4 May 2023 21:57:42 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=A04=20=D0=B2=D1=81=D0=B5=20=D1=80?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/CatalogCollections.vue | 106 ++++++++++++++++++ .../vue-project/src/components/Catalogs.vue | 4 +- Frontend/vue-project/src/main.js | 5 +- Frontend/vue-project/src/models/Collection.js | 2 +- data.mv.db | Bin 45056 -> 61440 bytes .../controller/CollectionController.java | 63 +++-------- .../DataBase/controller/CollectionDTO.java | 18 +-- .../DataBase/service/CollectionService.java | 62 ++++++---- .../is/lab1/DataBase/service/FilmService.java | 1 - 9 files changed, 179 insertions(+), 82 deletions(-) create mode 100644 Frontend/vue-project/src/components/CatalogCollections.vue diff --git a/Frontend/vue-project/src/components/CatalogCollections.vue b/Frontend/vue-project/src/components/CatalogCollections.vue new file mode 100644 index 0000000..8957f25 --- /dev/null +++ b/Frontend/vue-project/src/components/CatalogCollections.vue @@ -0,0 +1,106 @@ + + + \ No newline at end of file diff --git a/Frontend/vue-project/src/components/Catalogs.vue b/Frontend/vue-project/src/components/Catalogs.vue index b95dcad..427bb95 100644 --- a/Frontend/vue-project/src/components/Catalogs.vue +++ b/Frontend/vue-project/src/components/Catalogs.vue @@ -3,9 +3,9 @@ data() { return { catalogs: [ - { name: 'collections', label: 'Сборники' }, + { name: 'genres', label: 'Жанры' }, { name: 'films', label: 'Фильмы' }, - { name: 'genres', label: 'Жанры' } + { name: 'collections', label: 'Коллекции' } ] } } diff --git a/Frontend/vue-project/src/main.js b/Frontend/vue-project/src/main.js index ccfdb17..f01baa4 100644 --- a/Frontend/vue-project/src/main.js +++ b/Frontend/vue-project/src/main.js @@ -10,7 +10,7 @@ import Table from './components/Table.vue' import Catalogs from './components/Catalogs.vue' import CatalogGenres from './components/CatalogGenres.vue' import CatalogFilms from './components/CatalogFilms.vue' - +import CatalogCollections from './components/CatalogCollections.vue' const routes = [ { path: '/', redirect: '/index' }, @@ -22,7 +22,8 @@ const routes = [ { path: '/table', component: Table}, { path: '/catalogs', component: Catalogs}, { path: '/catalogs/genres', component: CatalogGenres}, - { path: '/catalogs/films', component: CatalogFilms} + { path: '/catalogs/films', component: CatalogFilms}, + { path: '/catalogs/collections', component: CatalogCollections} ] const router = createRouter({ diff --git a/Frontend/vue-project/src/models/Collection.js b/Frontend/vue-project/src/models/Collection.js index dbef5df..69163d5 100644 --- a/Frontend/vue-project/src/models/Collection.js +++ b/Frontend/vue-project/src/models/Collection.js @@ -21,6 +21,6 @@ export default class Collection { } get filmIds() { - return this.filmIds; + return this._filmIds; } } \ No newline at end of file diff --git a/data.mv.db b/data.mv.db index f1103738aa75c653cd62280a0290be66ee464736..4bd2a56cb01d582dcf7c1efaa2968346bf27b4ef 100644 GIT binary patch literal 61440 zcmeHQNo*Y1d9G@9Q*CNrMv9XdZndP*DB&=*FFiB1xHLr$7jZ~xLjn-B&L|_10!1lO zPRe*PiQxnZkckgIB(@PCfRW`AUlWZFL6C#df}OzdCC)WBBLQNcod2!0Q%$lpkuwB+Wy?>wSXrunEjo^K@Ub*?ZQAbr2Wi)v2-un9;%Nz|hBX27TJE~(_QLJi) zt&PSTo436!xaoehdH3eVI=U{t6>SCYMVlQh@^sA!jS)%w1Ofs9fq+0jARrJB2nYlO z0s;YnfIvVXAP{&C5SU?nKU)j_|2b$CL4rU)ARrJB2nYlO0s;YnfIvVXAP^7;2m}U; z09W!eBY<1cdPg0-?cM2^CafNGEK3<(j~;AwtkFB(yV2c_F}k_2vDHys1FQrTMUP!; zbnE8rsAD^^p;&I1wh7qU2s&11wFdS>HU(dl{zW=4B-MuYNsUkBhKCm4k{jPcOE`T} z`nG%oPB*+EIIxc#luk*1UOS48ej*RS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vV(XR&k#uCbp>-=OZzl@>01aSs?EnA( diff --git a/src/main/java/ru/ulstu/is/lab1/DataBase/controller/CollectionController.java b/src/main/java/ru/ulstu/is/lab1/DataBase/controller/CollectionController.java index 8c49f10..1841c54 100644 --- a/src/main/java/ru/ulstu/is/lab1/DataBase/controller/CollectionController.java +++ b/src/main/java/ru/ulstu/is/lab1/DataBase/controller/CollectionController.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.Collection; +import org.springframework.web.bind.annotation.*; import ru.ulstu.is.lab1.DataBase.service.CollectionService; -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 CollectionController { private final CollectionService collectionService; - @Autowired public CollectionController(CollectionService collectionService) { this.collectionService = collectionService; } @@ -37,41 +26,13 @@ public class CollectionController { } @PostMapping - public CollectionDTO createCollection(@RequestParam("name") String name, @RequestParam("FilmsId") String FilmsId) throws IOException { - List ids = new ArrayList<>(); - String num = ""; - if(FilmsId.length() == 0) - FilmsId = ""; - for (Character sm: - FilmsId.toCharArray()) { - if(sm.equals('-')) - { - ids.add(Long.parseLong(num)); - num=""; - } - else - num+=sm; - } - return new CollectionDTO(collectionService.addCollection(name, ids)); + public CollectionDTO createCollection(@RequestBody @Valid CollectionDTO collectionDTO) { + return new CollectionDTO(collectionService.addCollection(collectionDTO.getName())); } - @PatchMapping("/{id}") - public CollectionDTO updateCollection(@PathVariable Long id, @RequestParam("name") String name, @RequestParam("FilmsId") String FilmsId) { - List ids = new ArrayList<>(); - String num = ""; - if(FilmsId.length() == 0) - FilmsId = ""; - for (Character sm: - FilmsId.toCharArray()) { - if(sm.equals('-')) - { - ids.add(Long.parseLong(num)); - num=""; - } - else - num+=sm; - } - return new CollectionDTO(collectionService.updateCollection(id, name, ids)); + @PutMapping("/{id}") + public CollectionDTO updateCollection(@PathVariable Long id, @RequestBody @Valid CollectionDTO collectionDTO) { + return new CollectionDTO(collectionService.updateCollection(id, collectionDTO.getName())); } @DeleteMapping("/{id}") @@ -82,4 +43,14 @@ public class CollectionController { public void deleteAllCollections(){ collectionService.deleteAllCollections(); } + + @PostMapping("/add_film/{id}") + public CollectionDTO addFilm(@PathVariable Long id, @RequestParam Long film_id) { + return new CollectionDTO(collectionService.addFilm(id, film_id)); + } + + @DeleteMapping("/del_film/{id}") + public CollectionDTO delFilm(@PathVariable Long id, @RequestParam Long film_id) { + return new CollectionDTO(collectionService.deleteFilm(id, film_id)); + } } diff --git a/src/main/java/ru/ulstu/is/lab1/DataBase/controller/CollectionDTO.java b/src/main/java/ru/ulstu/is/lab1/DataBase/controller/CollectionDTO.java index 3688251..61a25cf 100644 --- a/src/main/java/ru/ulstu/is/lab1/DataBase/controller/CollectionDTO.java +++ b/src/main/java/ru/ulstu/is/lab1/DataBase/controller/CollectionDTO.java @@ -1,22 +1,22 @@ package ru.ulstu.is.lab1.DataBase.controller; import ru.ulstu.is.lab1.DataBase.model.Collection; +import ru.ulstu.is.lab1.DataBase.model.Film; import java.util.List; public class CollectionDTO { private Long id; private String name; - private List filmDTOList; + private List filmIds; + public CollectionDTO() { + } public CollectionDTO(Collection collection){ this.id = collection.getId(); this.name = collection.getName(); - this.filmDTOList = collection.getFilms() == null ? null : collection.getFilms() - .stream() - .map(FilmDTO::new) - .toList(); - } - public CollectionDTO() { + if(collection.getFilms() != null) { + this.filmIds = collection.getFilms().stream().map(Film::getId).toList(); + } } public Long getId(){ return id; @@ -24,7 +24,7 @@ public class CollectionDTO { public String getName(){ return name; } - public List getFilmDTOList(){ - return filmDTOList; + public List getFilmIds(){ + return filmIds; } } diff --git a/src/main/java/ru/ulstu/is/lab1/DataBase/service/CollectionService.java b/src/main/java/ru/ulstu/is/lab1/DataBase/service/CollectionService.java index 14bac03..d22d4cd 100644 --- a/src/main/java/ru/ulstu/is/lab1/DataBase/service/CollectionService.java +++ b/src/main/java/ru/ulstu/is/lab1/DataBase/service/CollectionService.java @@ -1,13 +1,15 @@ package ru.ulstu.is.lab1.DataBase.service; +import org.springframework.util.StringUtils; import ru.ulstu.is.lab1.DataBase.model.Film; import ru.ulstu.is.lab1.DataBase.model.Collection; import ru.ulstu.is.lab1.DataBase.Repository.ICollectionRepository; +import ru.ulstu.is.lab1.DataBase.model.Genre; import ru.ulstu.is.lab1.util.validation.ValidatorUtil; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.io.IOException; +import javax.persistence.EntityNotFoundException; import java.util.List; import java.util.Optional; @@ -23,17 +25,12 @@ public class CollectionService { this.filmService = filmService; } @Transactional - public Collection addCollection(String name, List filmsId) throws IOException { - final Collection collection = new Collection(name); - if(filmsId.size() > 0 ) - { - for (Long id: filmsId) { - Film film = filmService.findFilm(id); - collection.addFilm(film); - } + public Collection addCollection(String name) { + if (!StringUtils.hasText(name)) { + throw new IllegalArgumentException("Collection name is null or empty"); } + final Collection collection = new Collection(name); validatorUtil.validate(collection); - return collectionRepository.save(collection); } @@ -49,19 +46,12 @@ public class CollectionService { } @Transactional - public Collection updateCollection(Long id, String name, List filmsId) { + public Collection updateCollection(Long id, String name) { + if (!StringUtils.hasText(name)) { + throw new IllegalArgumentException("Collection name is null or empty"); + } final Collection currentCollection = findCollection(id); currentCollection.setName(name); - if(filmsId.size()>0) - { - currentCollection.getFilms().clear(); - for (Long filmId: filmsId) { - Film film = filmService.findFilm(filmId); - currentCollection.addFilm(film); - } - } - else - currentCollection.getFilms().clear(); validatorUtil.validate(currentCollection); return collectionRepository.save(currentCollection); } @@ -77,4 +67,34 @@ public class CollectionService { public void deleteAllCollections() { collectionRepository.deleteAll(); } + + @Transactional + public Collection addFilm(Long collectionId, Long filmId) { + Collection collection = findCollection(collectionId); + if (collection == null) { + throw new EntityNotFoundException(String.format("Collection with id [%s] is not found", collectionId)); + } + final Film film = filmService.findFilm(filmId); + if (film == null) { + throw new EntityNotFoundException(String.format("Film with id [%s] is not found", filmId)); + } + + collection.addFilm(film); + return collectionRepository.save(collection); + } + + @Transactional + public Collection deleteFilm(Long collectionId, Long filmId) { + Collection collection = findCollection(collectionId); + if (collection == null) { + throw new EntityNotFoundException(String.format("Collection with id [%s] is not found", collectionId)); + } + final Film film = filmService.findFilm(filmId); + if (film == null) { + throw new EntityNotFoundException(String.format("Film with id [%s] is not found", filmId)); + } + + collection.removeFilm(film); + return collectionRepository.save(collection); + } } 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 b912be8..e19280b 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 @@ -9,7 +9,6 @@ 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;