diff --git a/front/src/index.html b/front/src/index.html index 447171f..59944c7 100644 --- a/front/src/index.html +++ b/front/src/index.html @@ -27,26 +27,38 @@ -
+
-
- - +
+ +
-
- - +
+ + +
+
+ + +
+
+ + +
+
+ +
- +
-
- +
+
-
- +
+
@@ -54,9 +66,10 @@ - - - + + + + diff --git a/front/src/scriptComponent.js b/front/src/scriptComponent.js index 4a784dc..e0e883f 100644 --- a/front/src/scriptComponent.js +++ b/front/src/scriptComponent.js @@ -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(); } diff --git a/front/src/scriptOrder.js b/front/src/scriptOrder.js index 0d8d677..1078ead 100644 --- a/front/src/scriptOrder.js +++ b/front/src/scriptOrder.js @@ -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 += - ` - - - - `; - }) - } - 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 = "" + table.innerHTML += + ` + + + + + `; + }) } - 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(); }); \ No newline at end of file diff --git a/src/main/java/ip/labwork/shop/model/Order.java b/src/main/java/ip/labwork/shop/model/Order.java index 9163f52..9feed15 100644 --- a/src/main/java/ip/labwork/shop/model/Order.java +++ b/src/main/java/ip/labwork/shop/model/Order.java @@ -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") diff --git a/src/main/java/ip/labwork/shop/model/OrderProducts.java b/src/main/java/ip/labwork/shop/model/OrderProducts.java index 9696cb3..9ec4ec5 100644 --- a/src/main/java/ip/labwork/shop/model/OrderProducts.java +++ b/src/main/java/ip/labwork/shop/model/OrderProducts.java @@ -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;
#First nameLast nameИДДата оформленияЦенаПродукты
${student.id}${student.firstName}${student.lastName}
${Order.id}${Order.date}${Order.price}${temp}