что то
This commit is contained in:
parent
89fcb3cbca
commit
11173e07c4
@ -15,9 +15,9 @@ public class Product {
|
||||
private long id;
|
||||
|
||||
@Column(nullable = false)
|
||||
@NotBlank(message = "name cant be null or empty")
|
||||
// @NotBlank(message = "name cant be null or empty")
|
||||
private String name;
|
||||
@NotBlank(message = "cost cant be < 0")
|
||||
// @NotBlank(message = "cost cant be < 0")
|
||||
@Column(nullable = false)
|
||||
private double cost;
|
||||
@ManyToMany(fetch = FetchType.EAGER, mappedBy = "products")
|
||||
@ -43,7 +43,7 @@ public class Product {
|
||||
public double getCost() {
|
||||
return cost;
|
||||
}
|
||||
public void setCost(float cost) {
|
||||
public void setCost(double cost) {
|
||||
this.cost = cost;
|
||||
}
|
||||
|
||||
|
@ -26,15 +26,15 @@ public class ProductController {
|
||||
}
|
||||
|
||||
@PostMapping("/")
|
||||
public ProductDto createProduct(@RequestParam String name,
|
||||
@RequestParam float cost) {
|
||||
public ProductDto createProduct(@RequestParam("name") String name,
|
||||
@RequestParam("cost") double cost) {
|
||||
return new ProductDto(productService.addProduct(name, cost));
|
||||
}
|
||||
|
||||
@PatchMapping("/{id}")
|
||||
public ProductDto updateProduct(@PathVariable Long id,
|
||||
@RequestParam String name,
|
||||
@RequestParam float cost) {
|
||||
@RequestParam double cost) {
|
||||
return new ProductDto(productService.updateProduct(id, name, cost));
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ public class ProductService {
|
||||
@Transactional
|
||||
public Product addProduct(String name, double cost){
|
||||
final Product product = new Product(name, cost);
|
||||
validatorUtil.validate(product);
|
||||
// validatorUtil.validate(product);
|
||||
return productRepository.save(product);
|
||||
}
|
||||
|
||||
@ -36,11 +36,11 @@ public class ProductService {
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Product updateProduct(Long id, String name, float cost) {
|
||||
public Product updateProduct(Long id, String name, double cost) {
|
||||
final Product currentProduct = findProduct(id);
|
||||
currentProduct.setName(name);
|
||||
currentProduct.setCost(cost);
|
||||
validatorUtil.validate(currentProduct);
|
||||
// validatorUtil.validate(currentProduct);
|
||||
return productRepository.save(currentProduct);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
package com.example.demo;
|
||||
|
||||
import com.example.demo.supply.Order.Orders;
|
||||
import com.example.demo.supply.Product.Product;
|
||||
import com.example.demo.supply.Product.ProductService;
|
||||
import com.example.demo.supply.Supplier.Supplier;
|
||||
import com.example.demo.supply.Order.OrderService;
|
||||
import com.example.demo.supply.Supplier.SupplierService;
|
||||
@ -14,5 +16,5 @@ import java.util.List;
|
||||
|
||||
@SpringBootTest
|
||||
public class Tests {
|
||||
//
|
||||
}
|
||||
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
<!doctype html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport"
|
||||
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<title>REST Client Example</title>
|
||||
<script type="module" src="../node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
|
||||
<link href="../node_modules/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet"/>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<select class="form-select" aria-label="Default select example">
|
||||
<option selected>Open this select menu</option>
|
||||
<option value="1">Изделия</option>
|
||||
<option value="2">Поставщики</option>
|
||||
<option value="3">Three</option>
|
||||
</select>
|
||||
<form id="form">
|
||||
<div class="row mt-3">
|
||||
<div class="col-sm-6">
|
||||
<label for="lastName" class="form-label">Last name</label>
|
||||
<input type="text" class="form-control" id="lastName" 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>
|
||||
</div>
|
||||
<div class="row mt-3">
|
||||
<div class="d-grid col-sm-4 mx-auto">
|
||||
<button type="submit" class="btn btn-success">Add</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>
|
||||
<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>
|
||||
</div>
|
||||
</form>
|
||||
<div class="row table-responsive">
|
||||
<table class="table mt-3">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">#</th>
|
||||
<th scope="col">First name</th>
|
||||
<th scope="col">Last name</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="tbody">
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
<script>
|
||||
|
||||
</script>
|
||||
</html>
|
@ -1,74 +0,0 @@
|
||||
|
||||
|
||||
window.addEventListener('DOMContentLoaded', function () {
|
||||
const host = "http://localhost:8080";
|
||||
const table = document.getElementById("tbody");
|
||||
const form = document.getElementById("form");
|
||||
const lastNameInput = document.getElementById("lastName");
|
||||
const firstNameInput = document.getElementById("firstName");
|
||||
const testErrorBtn = document.getElementById("testError");
|
||||
const testNormalBtn = document.getElementById("testNormal");
|
||||
|
||||
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) {
|
||||
const data = await response.json();
|
||||
alert(TestDto=[id=${data.id}, name=${data.name}, data=${data.data}]);
|
||||
}
|
||||
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}]);
|
||||
});
|
||||
});
|
||||
|
||||
testErrorBtn.addEventListener("click", function () {
|
||||
test({});
|
||||
});
|
||||
|
||||
testNormalBtn.addEventListener("click", function () {
|
||||
test({id: 10, name: "test"});
|
||||
});
|
||||
|
||||
getData();
|
||||
});
|
30362
front/package-lock.json
generated
30362
front/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,20 +1,39 @@
|
||||
{
|
||||
"name": "front",
|
||||
"private": true,
|
||||
"version": "1.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "./node_modules/.bin/vite",
|
||||
"build": "./node_modules/.bin/vite build",
|
||||
"preview": "./node_modules/.bin/vite preview"
|
||||
},
|
||||
"devDependencies": {
|
||||
"vite": "^4.1.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"ajax": "^0.0.4",
|
||||
"axios": "^1.3.2",
|
||||
"bootstrap": "5.2.1",
|
||||
"@fortawesome/fontawesome-free": "6.2.0"
|
||||
}
|
||||
}
|
||||
"name": "front",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@testing-library/jest-dom": "^5.16.5",
|
||||
"@testing-library/react": "^13.4.0",
|
||||
"@testing-library/user-event": "^13.5.0",
|
||||
"bootstrap": "^5.3.0-alpha2",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"react-scripts": "5.0.1",
|
||||
"web-vitals": "^2.1.4"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "react-scripts start",
|
||||
"build": "react-scripts build",
|
||||
"test": "react-scripts test",
|
||||
"eject": "react-scripts eject"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": [
|
||||
"react-app",
|
||||
"react-app/jest"
|
||||
]
|
||||
},
|
||||
"browserslist": {
|
||||
"production": [
|
||||
">0.2%",
|
||||
"not dead",
|
||||
"not op_mini all"
|
||||
],
|
||||
"development": [
|
||||
"last 1 chrome version",
|
||||
"last 1 firefox version",
|
||||
"last 1 safari version"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ const productModel ={
|
||||
}
|
||||
|
||||
export default function ProductPage(){
|
||||
const mainUrl = 'http://localhost:8080/product/'
|
||||
|
||||
const [product, setProduct] = useState(productModel)
|
||||
|
||||
@ -18,7 +19,17 @@ export default function ProductPage(){
|
||||
setProduct(productModel)
|
||||
}
|
||||
|
||||
fetch('')
|
||||
const getAllProducts = () =>{
|
||||
fetch(`${mainUrl}`)
|
||||
.then((res) => {
|
||||
return res.json();
|
||||
})
|
||||
.then((arr) => {
|
||||
setProducts(arr);
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -71,7 +82,7 @@ export default function ProductPage(){
|
||||
{products.map((product, index) =>
|
||||
|
||||
<tr>
|
||||
<td>{}</td>
|
||||
<td>{index + 1}</td>
|
||||
<td>{product.name}</td>
|
||||
<td>{product.cost}</td>
|
||||
</tr>
|
29612
frontReact/package-lock.json
generated
29612
frontReact/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,39 +0,0 @@
|
||||
{
|
||||
"name": "front",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@testing-library/jest-dom": "^5.16.5",
|
||||
"@testing-library/react": "^13.4.0",
|
||||
"@testing-library/user-event": "^13.5.0",
|
||||
"bootstrap": "^5.3.0-alpha2",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"react-scripts": "5.0.1",
|
||||
"web-vitals": "^2.1.4"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "react-scripts start",
|
||||
"build": "react-scripts build",
|
||||
"test": "react-scripts test",
|
||||
"eject": "react-scripts eject"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": [
|
||||
"react-app",
|
||||
"react-app/jest"
|
||||
]
|
||||
},
|
||||
"browserslist": {
|
||||
"production": [
|
||||
">0.2%",
|
||||
"not dead",
|
||||
"not op_mini all"
|
||||
],
|
||||
"development": [
|
||||
"last 1 chrome version",
|
||||
"last 1 firefox version",
|
||||
"last 1 safari version"
|
||||
]
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user