From 82c35d6d5e66f3149d9859374f2e0bd5d33bcb94 Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Thu, 11 May 2023 00:24:23 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BD=D0=B5=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=D0=B5=D1=82=20=D0=BE=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=83=D1=81=D0=BB=D1=83=D0=B3=D0=B8=20?= =?UTF-8?q?=D0=B8=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BA=D0=BE=D0=BC=D0=BF=D0=BE=D0=BD=D0=B5=D0=BD=D1=82?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../vue-project/src/components/Components.vue | 4 +- front/vue-project/src/components/Favors.vue | 38 +++++++------------ front/vue-project/src/models/Favor.js | 2 +- .../repair/controller/FavorController.java | 4 +- .../ulstu/is/sbapp/repair/dtos/FavorDTO.java | 17 +++++++++ 5 files changed, 36 insertions(+), 29 deletions(-) diff --git a/front/vue-project/src/components/Components.vue b/front/vue-project/src/components/Components.vue index ba6ff26..6d92889 100644 --- a/front/vue-project/src/components/Components.vue +++ b/front/vue-project/src/components/Components.vue @@ -77,11 +77,11 @@ export default { v-model:visible="this.modalShow" @done="saveItem">
- +
- +
diff --git a/front/vue-project/src/components/Favors.vue b/front/vue-project/src/components/Favors.vue index 36cea16..9a997e6 100644 --- a/front/vue-project/src/components/Favors.vue +++ b/front/vue-project/src/components/Favors.vue @@ -16,8 +16,8 @@ export default { dataUrl: 'favor', transformer: (data) => new Favor(data), headers: [ - { name: 'favorName', label: 'name' }, - { name: 'price', label: 'price' }, + { name: 'favorName', label: 'Название услуги' }, + { name: 'price', label: 'Цена' }, ], headersComps: [ { name: 'componentName', label: 'Компонент' } @@ -82,7 +82,8 @@ export default { }, addComponentToFavor(favorId) { let componentId = document.getElementById('components').value; - let response = axios.post(`http://localhost:8080/api/favor/${favorId}/component?compId=${componentId}`); + let response = axios.post(`http://localhost:8080/favor/${favorId}/component?compId=${componentId}`); + console.log(response); }, itemsComps(componentIds) { let result = []; @@ -92,6 +93,7 @@ export default { this.components.forEach(component => { for (let i = 0; i < componentIds.length; i++) { if (component.id === componentIds[i]) { + result.push(component); } } @@ -140,8 +142,12 @@ export default { v-model:visible="this.modalShow" @done="saveItem">
- - + + +
+
+ +
- - +
- - - - - - \ No newline at end of file diff --git a/front/vue-project/src/models/Favor.js b/front/vue-project/src/models/Favor.js index 0ea8167..7c3e323 100644 --- a/front/vue-project/src/models/Favor.js +++ b/front/vue-project/src/models/Favor.js @@ -28,7 +28,7 @@ export default class Favor { } set price(value) { - if (typeof value !== 'string' || value === null || value.length == 0) { + if (typeof value !== 'number' || value === null || value.length == 0) { throw 'New price value ' + value + ' is not a string or empty'; } this._price = value; diff --git a/src/main/java/ru/ulstu/is/sbapp/repair/controller/FavorController.java b/src/main/java/ru/ulstu/is/sbapp/repair/controller/FavorController.java index e50a9db..9f1b6e4 100644 --- a/src/main/java/ru/ulstu/is/sbapp/repair/controller/FavorController.java +++ b/src/main/java/ru/ulstu/is/sbapp/repair/controller/FavorController.java @@ -22,8 +22,8 @@ public class FavorController { } @PutMapping("/{id}") - public FavorDTO updateFavor(@PathVariable Long id,@RequestParam("name") String name, @RequestParam("price") Integer price) { - return new FavorDTO(favorService.updateFavor(id,name, price)); + public FavorDTO updateFavor(@PathVariable Long id,@RequestBody @Valid FavorDTO favorDTO) { + return new FavorDTO(favorService.updateFavor(id,favorDTO.getFavorName(), favorDTO.getPrice())); } @PutMapping("/{id}/component") diff --git a/src/main/java/ru/ulstu/is/sbapp/repair/dtos/FavorDTO.java b/src/main/java/ru/ulstu/is/sbapp/repair/dtos/FavorDTO.java index 81a2351..1052a13 100644 --- a/src/main/java/ru/ulstu/is/sbapp/repair/dtos/FavorDTO.java +++ b/src/main/java/ru/ulstu/is/sbapp/repair/dtos/FavorDTO.java @@ -1,7 +1,9 @@ package ru.ulstu.is.sbapp.repair.dtos; +import ru.ulstu.is.sbapp.repair.model.Component; import ru.ulstu.is.sbapp.repair.model.Favor; +import java.util.ArrayList; import java.util.List; public class FavorDTO { @@ -11,10 +13,22 @@ public class FavorDTO { private List componentsDTOList; private List ordersDTOList; + private List componentIds; + public FavorDTO(Favor favor){ this.id =favor.getId(); this.favorName = favor.getFavorName(); this.price = favor.getPrice(); + if (favor.getComponents() == null){ + this. componentIds = new ArrayList<>(); + } + else { + this.componentIds = new ArrayList<>(); + List components = favor.getComponents(); + for (Component component : components) { + componentIds.add(component.getId()); + } + } this.componentsDTOList = favor.getComponents() == null ? null: favor.getComponents() .stream() .filter(x -> x.getFavors().contains(favor.getId())) @@ -45,4 +59,7 @@ public class FavorDTO { public List getOrdersDTOList() { return ordersDTOList; } + + public List getcomponentIds() { return this.componentIds; } + public void setcomponentIds(List componentIds) { this.componentIds = componentIds; } }