не работает обновление услуги и добавление компонента
This commit is contained in:
parent
c4810cda16
commit
82c35d6d5e
@ -77,11 +77,11 @@ export default {
|
||||
v-model:visible="this.modalShow"
|
||||
@done="saveItem">
|
||||
<div class="mb-3">
|
||||
<label for="name" class="form-label">Name</label>
|
||||
<label for="name" class="form-label">Название компонента</label>
|
||||
<input type="text" class="form-control" id="name" required v-model="data.componentName">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="amount" class="form-label">Amount</label>
|
||||
<label for="amount" class="form-label">Количество</label>
|
||||
<input type="number" class="form-control" id="amount" required v-model="data.amount">
|
||||
</div>
|
||||
</Modal>
|
||||
|
@ -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">
|
||||
<div class="mb-3">
|
||||
<label for="number" class="form-label">Номер кабинета</label>
|
||||
<input type="text" class="form-control" id="number" required v-model="data.number">
|
||||
<label for="name" class="form-label">Название услуги</label>
|
||||
<input type="text" class="form-control" id="name" required v-model="data.favorName">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="price" class="form-label">Цена</label>
|
||||
<input type="number" class="form-control" id="price" required v-model="data.price">
|
||||
</div>
|
||||
<DataTable
|
||||
:headers="this.headersComps"
|
||||
@ -149,9 +155,9 @@ export default {
|
||||
:selectedItems="this.selectedItemsComps">
|
||||
</DataTable>
|
||||
<div class="mb-3">
|
||||
<label for="computers" class="form-label">Добавить компьютер</label>
|
||||
<select class="form-select" id="computers" required>
|
||||
<option disabled value="">Выберите компьютер</option>
|
||||
<label for="components" class="form-label">Добавить компонент</label>
|
||||
<select class="form-select" id="components" required>
|
||||
<option disabled value="">Выберите компонент</option>
|
||||
<option v-for="component in this.components"
|
||||
:value="component.id">
|
||||
{{ component.componentName }}
|
||||
@ -160,21 +166,5 @@ export default {
|
||||
</div>
|
||||
<button class="btn btn-outline-secondary" type="button" id="addComputerButton"
|
||||
@click.prevent="addComponentToFavor(data.id)">Добавить</button>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- <div class="mb-3">
|
||||
<label for="order" class="form-label">Номер кабинета</label>
|
||||
<select class="form-select" id="order" v-model="data.orderId">
|
||||
<option disabled value="">Выберите номер кабинета</option>
|
||||
<option v-for="order in this.orders"
|
||||
:value="order.id"
|
||||
:selected="data.orderId && order.id === data.orderId">
|
||||
{{ order.number }}
|
||||
</option>
|
||||
</select>
|
||||
</div> -->
|
||||
</Modal>
|
||||
</template>
|
@ -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;
|
||||
|
@ -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")
|
||||
|
@ -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<ComponentDTO> componentsDTOList;
|
||||
private List<OrderDTO> ordersDTOList;
|
||||
|
||||
private List<Long> 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<Component> 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<OrderDTO> getOrdersDTOList() {
|
||||
return ordersDTOList;
|
||||
}
|
||||
|
||||
public List<Long> getcomponentIds() { return this.componentIds; }
|
||||
public void setcomponentIds(List<Long> componentIds) { this.componentIds = componentIds; }
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user