Merge remote-tracking branch 'origin/LabWork04' into LabWork04
# Conflicts: # src/main/java/ip/labwork/shop/controller/OrderController.java # src/main/java/ip/labwork/shop/controller/OrderDTO.java # src/main/java/ip/labwork/shop/controller/ProductController.java # src/main/java/ip/labwork/shop/controller/ProductDTO.java # src/main/java/ip/labwork/shop/service/OrderService.java # src/main/java/ip/labwork/shop/service/ProductService.java
This commit is contained in:
commit
5d790b350c
@ -27,26 +27,38 @@
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
<form id="form">
|
||||
<form id="form" novalidate>
|
||||
<div class="row mt-3">
|
||||
<div class="col-sm-6">
|
||||
<label for="componentName" class="form-label">Название компонента</label>
|
||||
<input type="text" class="form-control" id="componentName" required>
|
||||
<div class="col-sm-4">
|
||||
<label for="orderId" class="form-label">ИД Заказа</label>
|
||||
<input type="text" class="form-control" id="orderId" required>
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<label for="firstName" class="form-label">First name</label>
|
||||
<input type="text" class="form-control" id="firstName" required>
|
||||
<div class="col-sm-4">
|
||||
<label for="orderDate" class="form-label">Время оформления</label>
|
||||
<input type="text" class="form-control" id="orderDate" required>
|
||||
</div>
|
||||
<div class="col-sm-4">
|
||||
<label for="orderPrice" class="form-label">Цена</label>
|
||||
<input type="text" class="form-control" id="orderPrice" required>
|
||||
</div>
|
||||
<div class="col-sm-4">
|
||||
<label for="productId" class="form-label">ИД продукта</label>
|
||||
<input type="text" class="form-control" id="productId" required>
|
||||
</div>
|
||||
<div class="col-sm-4">
|
||||
<label for="productCount" class="form-label">Количество продукта</label>
|
||||
<input type="text" class="form-control" id="productCount" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mt-3">
|
||||
<div class="d-grid col-sm-4 mx-auto">
|
||||
<button type="submit" class="btn btn-success">Add</button>
|
||||
<button type="submit" class="btn btn-success">Добавить</button>
|
||||
</div>
|
||||
<div class="d-grid col-sm-4 mx-auto mt-3 mt-sm-0">
|
||||
<button id="testError" type="button" class="btn btn-danger">Test</button>
|
||||
<div class="d-grid col-sm-4 mx-auto">
|
||||
<button type="submit" class="btn btn-success" id="btnUpdate" >Обновить</button>
|
||||
</div>
|
||||
<div class="d-grid col-sm-4 mx-auto mt-3 mt-sm-0">
|
||||
<button id="testNormal" type="button" class="btn btn-secondary">Test</button>
|
||||
<div class="d-grid col-sm-4 mx-auto">
|
||||
<button id="btnRemove" class="btn btn-success">Удалить</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
@ -54,9 +66,10 @@
|
||||
<table class="table mt-3">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">#</th>
|
||||
<th scope="col">First name</th>
|
||||
<th scope="col">Last name</th>
|
||||
<th scope="col">ИД</th>
|
||||
<th scope="col">Дата оформления</th>
|
||||
<th scope="col">Цена</th>
|
||||
<th scope="col">Продукты</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="tbody">
|
||||
|
@ -36,7 +36,7 @@ window.addEventListener('DOMContentLoaded', function () {
|
||||
|
||||
const remove = async function (){
|
||||
console.info('Try to remove item');
|
||||
if (itemId.value !== 0) {
|
||||
if (componentIdInput.value !== 0) {
|
||||
if (!confirm('Do you really want to remove this item?')) {
|
||||
console.info('Canceled');
|
||||
return;
|
||||
@ -48,7 +48,7 @@ window.addEventListener('DOMContentLoaded', function () {
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
};
|
||||
const response = await fetch(host + `/component/` + itemId.value, requestParams);
|
||||
const response = await fetch(host + `/component/` + componentIdInput.value, requestParams);
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
|
@ -4,72 +4,110 @@ window.addEventListener('DOMContentLoaded', function () {
|
||||
const host = "http://localhost:8080";
|
||||
const table = document.getElementById("tbody");
|
||||
const form = document.getElementById("form");
|
||||
const lastNameInput = document.getElementById("componentName");
|
||||
const firstNameInput = document.getElementById("firstName");
|
||||
const testErrorBtn = document.getElementById("testError");
|
||||
const testNormalBtn = document.getElementById("testNormal");
|
||||
const orderIdInput = document.getElementById("orderId");
|
||||
const orderDate = document.getElementById("orderDate");
|
||||
const priceInput = document.getElementById("orderPrice");
|
||||
const productIdInput = document.getElementById("productId");
|
||||
const productCountInput = document.getElementById("productCount");
|
||||
const buttonRemove = document.getElementById("btnRemove");
|
||||
const buttonUpdate = document.getElementById("btnUpdate");
|
||||
|
||||
const getData = async function () {
|
||||
table.innerHTML = "";
|
||||
const response = await fetch(host + "/student");
|
||||
const data = await response.json();
|
||||
data.forEach(student => {
|
||||
table.innerHTML +=
|
||||
`<tr>
|
||||
<th scope="row">${student.id}</th>
|
||||
<td>${student.firstName}</td>
|
||||
<td>${student.lastName}</td>
|
||||
</tr>`;
|
||||
})
|
||||
}
|
||||
|
||||
const create = async function (firstName, lastName) {
|
||||
const requestParams = {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
};
|
||||
const response = await fetch(host + `/student?firstName=${firstName}&lastName=${lastName}`, requestParams);
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
const test = async function (testObject) {
|
||||
const requestParams = {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(testObject),
|
||||
};
|
||||
const response = await fetch(host + "/test", requestParams);
|
||||
if (response.status === 200) {
|
||||
table.innerHTML = "";
|
||||
const response = await fetch(host + "/order");
|
||||
const data = await response.json();
|
||||
alert(`TestDto=[id=${data.id}, name=${data.name}, data=${data.data}]`);
|
||||
data.forEach(Order => {
|
||||
let temp = "<select>";
|
||||
Order.productDTOList.forEach(Product => {
|
||||
temp += `<option>${Product.productName + " " + Product.count}</option>>`
|
||||
})
|
||||
temp += "</select>"
|
||||
table.innerHTML +=
|
||||
`<tr>
|
||||
<th scope="row">${Order.id}</th>
|
||||
<td>${Order.date}</td>
|
||||
<td>${Order.price}</td>
|
||||
<td>${temp}</td>
|
||||
</tr>`;
|
||||
})
|
||||
}
|
||||
if (response.status === 400) {
|
||||
const data = await response.text();
|
||||
alert(data);
|
||||
}
|
||||
}
|
||||
|
||||
form.addEventListener("submit", function (event) {
|
||||
event.preventDefault();
|
||||
create(firstNameInput.value, lastNameInput.value).then((result) => {
|
||||
getData();
|
||||
firstNameInput.value = "";
|
||||
lastNameInput.value = "";
|
||||
alert(`Student[id=${result.id}, firstName=${result.firstName}, lastName=${result.lastName}]`);
|
||||
const create = async function () {
|
||||
const requestParams = {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
};
|
||||
let temp = Date.now();
|
||||
let time = new Date(temp);
|
||||
let tru = time.toString();
|
||||
const response = await fetch(host + `/order?price=${priceInput.value}&date=${tru}&count=${productCountInput.value}&prod=${productIdInput.value}`, requestParams);
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
const remove = async function (){
|
||||
console.info('Try to remove item');
|
||||
if (orderIdInput.value !== 0) {
|
||||
if (!confirm('Do you really want to remove this item?')) {
|
||||
console.info('Canceled');
|
||||
return;
|
||||
}
|
||||
}
|
||||
const requestParams = {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
};
|
||||
const response = await fetch(host + `/order/` + orderIdInput.value, requestParams);
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
const update = async function (){
|
||||
console.info('Try to update item');
|
||||
if (orderIdInput.value === 0 || orderDate.value == null || orderPrice.value === 0 || productIdInput.value === 0 || productCountInput.value === 0) {
|
||||
return;
|
||||
}
|
||||
const requestParams = {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
};
|
||||
let temp = Date.now();
|
||||
let time = new Date(temp);
|
||||
let tru = time.toString();
|
||||
const response = await fetch(host + `/order/${orderIdInput.value}?price=${priceInput.value}&date=${tru}&count=${productCountInput.value}&prod=${productIdInput.value}`, requestParams);
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
buttonRemove.addEventListener('click', function (event){
|
||||
event.preventDefault();
|
||||
remove().then((result) => {
|
||||
getData()
|
||||
orderIdInput.value = "";
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
testErrorBtn.addEventListener("click", function () {
|
||||
test({});
|
||||
});
|
||||
buttonUpdate.addEventListener('click', function (event){
|
||||
event.preventDefault();
|
||||
update().then((result) => {
|
||||
getData()
|
||||
orderIdInput.value = "";
|
||||
priceInput.value = "";
|
||||
});
|
||||
});
|
||||
|
||||
testNormalBtn.addEventListener("click", function () {
|
||||
test({id: 10, name: "test"});
|
||||
});
|
||||
|
||||
getData();
|
||||
form.addEventListener("submit", function (event) {
|
||||
event.preventDefault();
|
||||
create().then((result) => {
|
||||
getData();
|
||||
priceInput.value = "";
|
||||
orderIdInput.value = "";
|
||||
alert(`Component[id=${result.id}, price=${result.price}, componentName=${result.date}]`);
|
||||
});
|
||||
});
|
||||
getData();
|
||||
});
|
@ -14,7 +14,7 @@ public class Order {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private Long id;
|
||||
@NotNull(message = "Date can't be null or empty")
|
||||
//@NotNull(message = "Date can't be null or empty")
|
||||
@Column(name = "date")
|
||||
private Date date;
|
||||
@NotNull(message = "Price can't be null or empty")
|
||||
|
@ -27,7 +27,6 @@ public class OrderProducts {
|
||||
|
||||
public OrderProducts(Order order, Product product, Integer count) {
|
||||
this.order = order;
|
||||
this.id = new OrderProductsKey(product.getId(), order.getId());
|
||||
this.id.setOrderId(order.getId());
|
||||
this.id.setProductId(product.getId());
|
||||
this.product = product;
|
||||
|
Loading…
Reference in New Issue
Block a user