устала -_-

This commit is contained in:
Inohara 2023-05-02 14:47:10 +04:00
parent 44d9f2b935
commit cf46765fb9
28 changed files with 416 additions and 188 deletions

View File

@ -1,7 +1,7 @@
plugins { plugins {
id 'java' id 'java'
id 'org.springframework.boot' version '3.0.2' id 'org.springframework.boot' version '2.6.3'
id 'io.spring.dependency-management' version '1.1.0' id 'io.spring.dependency-management' version '1.0.11.RELEASE'
} }
group = 'com.example' group = 'com.example'
@ -17,7 +17,6 @@ jar{
} }
dependencies { dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-devtools' implementation 'org.springframework.boot:spring-boot-devtools'
@ -29,7 +28,9 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'com.h2database:h2:2.1.210' implementation 'com.h2database:h2:2.1.210'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.hibernate.validator:hibernate-validator'
implementation 'org.springdoc:springdoc-openapi-ui:1.6.5' implementation 'org.springdoc:springdoc-openapi-ui:1.6.5'
testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework.boot:spring-boot-starter-test'

View File

@ -8,16 +8,16 @@ import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration @Configuration
@EnableWebMvc public class WebConfiguration implements WebMvcConfigurer {
public class WebConfiguration {
@Bean @Override
public WebMvcConfigurer corsConfigurer() { public void addViewControllers(ViewControllerRegistry registry) {
return new WebMvcConfigurer() { WebMvcConfigurer.super.addViewControllers(registry);
@Override registry.addViewController("rest-test");
public void addCorsMappings(CorsRegistry registry) { }
registry.addMapping("/**")
.allowedMethods("HEAD", "GET", "PUT", "POST", "DELETE", "PATCH", "OPTIONS"); @Override
} public void addCorsMappings(CorsRegistry registry) {
}; registry.addMapping("/**").allowedMethods("*");
} }
} }

View File

@ -3,16 +3,22 @@ package com.example.demo.supply.Order;
import com.example.demo.supply.Product.Product; import com.example.demo.supply.Product.Product;
import com.example.demo.supply.Supplier.Supplier; import com.example.demo.supply.Supplier.Supplier;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.util.Objects;
import javax.persistence.*;
import java.util.Date; import java.util.Date;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects;
@Entity @Entity
public class _Order { @Table(name = "tab_order")
public class Order {
@Id @Id
@GeneratedValue(strategy = GenerationType.AUTO) @GeneratedValue(strategy = GenerationType.AUTO)
private Long id; private Long id;
@ -36,12 +42,12 @@ public class _Order {
public Long getId(){ public Long getId(){
return id; return id;
} }
public _Order(Date dateOfOrder) { public Order(Date dateOfOrder) {
this.dateOfOrder = dateOfOrder; this.dateOfOrder = dateOfOrder;
products = new ArrayList<>(); products = new ArrayList<>();
} }
public _Order() { public Order() {
} }
public Date getDateOfOrder() { public Date getDateOfOrder() {
@ -81,7 +87,7 @@ public class _Order {
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false; if (o == null || getClass() != o.getClass()) return false;
_Order order = (_Order) o; Order order = (Order) o;
if(!Objects.equals(id, order.id)) return false; if(!Objects.equals(id, order.id)) return false;
if(!Objects.equals(dateOfOrder.toString(), order.dateOfOrder.toString())) return false; if(!Objects.equals(dateOfOrder.toString(), order.dateOfOrder.toString())) return false;

View File

@ -11,7 +11,7 @@ import java.util.List;
@RestController @RestController
@CrossOrigin @CrossOrigin
@RequestMapping("/order") @RequestMapping("/api/order")
public class OrderController { public class OrderController {
private OrderService orderService; private OrderService orderService;
@ -34,15 +34,10 @@ public class OrderController {
return orderService.findAllOrderProducts(id).stream().map(ProductDto::new).toList(); return orderService.findAllOrderProducts(id).stream().map(ProductDto::new).toList();
} }
// @PostMapping("/someSuppliers/") @GetMapping("/someSuppliers/{id}")
// public List<SupplierDto> getSomeSuppliers(@RequestBody() List<Product> products) { public List<SupplierDto> getSomeSuppliers(@PathVariable Long id) {
// return orderService.suppliers(products).stream().map(SupplierDto::new).toList(); return orderService.suppliers(id).stream().map(SupplierDto::new).toList();
// } }
// @PostMapping("/someSuppliers/")
// public List<ProductDto> getSomeSuppliers(@RequestBody() List<ProductDto> products) {
// return products;
// }
@PostMapping("/") @PostMapping("/")
public Long createOrder(@RequestParam() Long supplierId) { public Long createOrder(@RequestParam() Long supplierId) {

View File

@ -14,7 +14,9 @@ public class OrderDto {
private Supplier supplier; private Supplier supplier;
private List<Product> products; private List<Product> products;
public OrderDto(_Order order){ public OrderDto(){
}
public OrderDto(Order order){
this.id = order.getId(); this.id = order.getId();
this.dateOfOrder = order.getDateOfOrder(); this.dateOfOrder = order.getDateOfOrder();
this.supplier = order.getSupplier(); this.supplier = order.getSupplier();
@ -36,4 +38,15 @@ public class OrderDto {
public List<Product> getProducts() { public List<Product> getProducts() {
return products; return products;
} }
public void setDateOfOrder(Date dateOfOrder) {
this.dateOfOrder = dateOfOrder;
}
public void setSupplier(Supplier supplier) {
this.supplier = supplier;
}
public void setProducts(List<Product> products) {
this.products = products;
}
} }

View File

@ -0,0 +1,72 @@
package com.example.demo.supply.Order;
import com.example.demo.supply.Product.ProductDto;
import com.example.demo.supply.Product.ProductService;
import com.example.demo.supply.Supplier.SupplierDto;
import com.example.demo.supply.Supplier.SupplierService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;
@Controller
@RequestMapping("/order")
public class OrderMvcController {
private OrderService orderService;
private ProductService productService;
private SupplierService supplierService;
public OrderMvcController(OrderService orderService,
ProductService productService,
SupplierService supplierService){
this.orderService = orderService;
this.productService = productService;
this.supplierService = supplierService;
}
@GetMapping
public String getOrders(Model model) {
model.addAttribute("orders",
orderService.findAllOrders().stream()
.map(OrderDto::new)
.toList());
// model.addAttribute("products",
// pro.findAllOrders().stream()
// .map(OrderDto::new)
// .toList());
return "order";
}
@GetMapping("/{id}")
public String getOrder(@PathVariable Long id,
Model model) {
model.addAttribute("orderId", id);
model.addAttribute("orderDto", new OrderDto(orderService.findOrder(id)));
return "product-edit";
}
@PostMapping("/")
public String createOrder(@ModelAttribute @Valid OrderDto orderDto,
BindingResult bindingResult,
Model model) {
if (bindingResult.hasErrors()) {
model.addAttribute("errors", bindingResult.getAllErrors());
return "order-add";
}
List<SupplierDto> suppliers =supplierService.findAllSuppliers().stream()
.map(SupplierDto::new).toList();
orderService.addOrder(orderDto.getSupplier().getId());
return "redirect:/order";
}
//
// @PostMapping("/delete/{id}")
// public String deleteProduct(@PathVariable Long id) {
// orderService.deleteProduct(id);
// return "redirect:/product";
// }
}

View File

@ -7,8 +7,7 @@ import org.springframework.data.jpa.repository.Query;
import java.util.List; import java.util.List;
public interface OrderRepository extends JpaRepository<_Order, Long> { public interface OrderRepository extends JpaRepository<Order, Long> {
@Query("SELECT distinct o.supplier FROM _Order o join Product p where p in (?1)") @Query("SELECT distinct o.supplier FROM Order o join Product p where p = ?1")
List<Supplier> getSomeSuppliers(List<Product> products); List<Supplier> getSomeSuppliers(Product product);
} }

View File

@ -28,58 +28,52 @@ public class OrderService {
} }
@Transactional @Transactional
public _Order addOrder(Long supplierId){ public Order addOrder(Long supplierId){
final _Order order = new _Order(new Date()); final Order order = new Order(new Date());
order.setSupplier(supplierService.findSupplier(supplierId)); order.setSupplier(supplierService.findSupplier(supplierId));
return orderRepository.save(order); return orderRepository.save(order);
} }
//поставщики, у которых есть заказ на конкретный товар или несколько товаров
// @Transactional
// public List<Supplier> suppliers(List<Product> products){
// return em.createQuery("SELECT distinct o.supplier FROM Orders o join Product p where p in (:products) ", Supplier.class)
// .setParameter("products", products).getResultList();
// }
@Transactional @Transactional
public List<Supplier> suppliers(List<Product> products){ public List<Supplier> suppliers(Long productId){
return orderRepository.getSomeSuppliers(products); final Product product = productService.findProduct(productId);
return orderRepository.getSomeSuppliers(product);
} }
@Transactional @Transactional
public _Order addProduct(Long id, Long productId) { public Order addProduct(Long id, Long productId) {
final _Order currentOrder = findOrder(id); final Order currentOrder = findOrder(id);
currentOrder.addProduct(productService.findProduct(productId)); currentOrder.addProduct(productService.findProduct(productId));
return orderRepository.save(currentOrder); return orderRepository.save(currentOrder);
} }
@Transactional @Transactional
public _Order removeProduct(Long id, Long productId) { public Order removeProduct(Long id, Long productId) {
final _Order currentOrder = findOrder(id); final Order currentOrder = findOrder(id);
currentOrder.addProduct(productService.findProduct(productId)); currentOrder.addProduct(productService.findProduct(productId));
return orderRepository.save(currentOrder); return orderRepository.save(currentOrder);
} }
@Transactional(readOnly = true) @Transactional(readOnly = true)
public _Order findOrder(Long id) { public Order findOrder(Long id) {
final Optional<_Order> order = orderRepository.findById(id); final Optional<Order> order = orderRepository.findById(id);
return order.orElseThrow(() -> new OrderNotFoundException(id)); return order.orElseThrow(() -> new OrderNotFoundException(id));
} }
@Transactional(readOnly = true) @Transactional(readOnly = true)
public List<_Order> findAllOrders() { public List<Order> findAllOrders() {
return orderRepository.findAll(); return orderRepository.findAll();
} }
@Transactional(readOnly = true) @Transactional(readOnly = true)
public List<Product> findAllOrderProducts(Long orderId) { public List<Product> findAllOrderProducts(Long orderId) {
final Optional<_Order> order = orderRepository.findById(orderId); final Optional<Order> order = orderRepository.findById(orderId);
return order.orElseThrow(() -> new OrderNotFoundException(orderId)).getProducts(); return order.orElseThrow(() -> new OrderNotFoundException(orderId)).getProducts();
} }
@Transactional @Transactional
public _Order deleteOrder(Long id) { public Order deleteOrder(Long id) {
final _Order currentOrder = findOrder(id); final Order currentOrder = findOrder(id);
orderRepository.delete(currentOrder); orderRepository.delete(currentOrder);
return currentOrder; return currentOrder;
} }

View File

@ -1,12 +1,13 @@
package com.example.demo.supply.Product; package com.example.demo.supply.Product;
import com.example.demo.supply.Order._Order; import com.example.demo.supply.Order.Order;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import javax.persistence.*;
import java.util.Objects;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects;
@Entity @Entity
public class Product { public class Product {
@ -22,7 +23,7 @@ public class Product {
private double cost; private double cost;
@JsonIgnore @JsonIgnore
@ManyToMany(fetch = FetchType.EAGER, mappedBy = "products") @ManyToMany(fetch = FetchType.EAGER, mappedBy = "products")
private List<_Order> orders; private List<Order> orders;
public Product(){} public Product(){}
@ -48,11 +49,11 @@ public class Product {
this.cost = cost; this.cost = cost;
} }
public List<_Order> getOrders() { public List<Order> getOrders() {
return orders; return orders;
} }
public void setOrders(List<_Order> orders) { public void setOrders(List<Order> orders) {
this.orders = orders; this.orders = orders;
} }

View File

@ -1,6 +1,6 @@
package com.example.demo.supply.Product; package com.example.demo.supply.Product;
import com.example.demo.supply.Order._Order; import com.example.demo.supply.Order.Order;
import java.util.List; import java.util.List;
@ -8,7 +8,7 @@ public class ProductDto {
private long id; private long id;
private String name; private String name;
private double cost; private double cost;
private List<_Order> orders; private List<Order> orders;
public ProductDto() {} public ProductDto() {}
@ -28,7 +28,19 @@ public class ProductDto {
public double getCost() { public double getCost() {
return cost; return cost;
} }
public List<_Order> getOrders() { public List<Order> getOrders() {
return orders; return orders;
} }
public void setName(String name) {
this.name = name;
}
public void setCost(double cost) {
this.cost = cost;
}
public void setOrders(List<Order> orders) {
this.orders = orders;
}
} }

View File

@ -1,11 +1,12 @@
package com.example.demo.supply.Product; package com.example.demo.supply.Product;
import jakarta.validation.Valid;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.validation.BindingResult; import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
@Controller @Controller
@RequestMapping("/product") @RequestMapping("/product")
public class ProductMvcController { public class ProductMvcController {
@ -16,7 +17,9 @@ public class ProductMvcController {
@GetMapping @GetMapping
public String getProducts(Model model) { public String getProducts(Model model) {
model.addAttribute("products", model.addAttribute("products",
productService.findAllProducts().stream().map(ProductDto::new).toList()); productService.findAllProducts().stream()
.map(ProductDto::new)
.toList());
return "product"; return "product";
} }

View File

@ -1,6 +1,5 @@
package com.example.demo.supply.Product; package com.example.demo.supply.Product;
import com.example.demo.util.ValidatorUtil;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;

View File

@ -1,13 +1,13 @@
package com.example.demo.supply.Supplier; package com.example.demo.supply.Supplier;
import com.example.demo.supply.Order._Order; import com.example.demo.supply.Order.Order;
import com.example.demo.supply.Product.Product;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import javax.persistence.*;
import java.util.Objects;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects;
@Entity @Entity
public class Supplier { public class Supplier {
@ -22,7 +22,7 @@ public class Supplier {
@JsonIgnore @JsonIgnore
@OneToMany(fetch = FetchType.EAGER, mappedBy = "supplier", cascade = CascadeType.REMOVE) @OneToMany(fetch = FetchType.EAGER, mappedBy = "supplier", cascade = CascadeType.REMOVE)
private List<_Order> orders; private List<Order> orders;
public Supplier(){} public Supplier(){}
@ -49,11 +49,11 @@ public class Supplier {
this.license = license; this.license = license;
} }
public List<_Order> getOrders() { public List<Order> getOrders() {
return orders; return orders;
} }
public void setOrders(List<_Order> orders) { public void setOrders(List<Order> orders) {
this.orders = orders; this.orders = orders;
} }

View File

@ -1,6 +1,6 @@
package com.example.demo.supply.Supplier; package com.example.demo.supply.Supplier;
import com.example.demo.supply.Order._Order; import com.example.demo.supply.Order.Order;
import java.util.List; import java.util.List;
@ -8,7 +8,7 @@ public class SupplierDto {
private Long id; private Long id;
private String name; private String name;
private int license; private int license;
private List<_Order> orders; private List<Order> orders;
public SupplierDto(){ public SupplierDto(){
} }
@ -27,7 +27,19 @@ public class SupplierDto {
public int getLicense() { public int getLicense() {
return license; return license;
} }
public List<_Order> getOrders() { public List<Order> getOrders() {
return orders; return orders;
} }
public void setName(String name) {
this.name = name;
}
public void setLicense(int license) {
this.license = license;
}
public void setOrders(List<Order> orders) {
this.orders = orders;
}
} }

View File

@ -1,11 +1,12 @@
package com.example.demo.supply.Supplier; package com.example.demo.supply.Supplier;
import jakarta.validation.Valid;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.validation.BindingResult; import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
@Controller @Controller
@RequestMapping("/supplier") @RequestMapping("/supplier")
public class SupplierMvcController { public class SupplierMvcController {
@ -13,15 +14,17 @@ public class SupplierMvcController {
public SupplierMvcController(SupplierService supplierService){ this.supplierService = supplierService;} public SupplierMvcController(SupplierService supplierService){ this.supplierService = supplierService;}
@GetMapping("/") @GetMapping
public String getProducts(Model model) { public String getSuppliers(Model model) {
model.addAttribute("suppliers", model.addAttribute("suppliers",
supplierService.findAllSuppliers().stream().map(SupplierDto::new).toList()); supplierService.findAllSuppliers().stream()
.map(SupplierDto::new)
.toList());
return "supplier"; return "supplier";
} }
@GetMapping(value = {"/edit", "/edit/{id}"}) @GetMapping(value = {"/edit", "/edit/{id}"})
public String editProduct(@PathVariable(required = false) Long id, public String editSuppliers(@PathVariable(required = false) Long id,
Model model) { Model model) {
if (id == null || id <= 0) { if (id == null || id <= 0) {
model.addAttribute("supplierDto", new SupplierDto()); model.addAttribute("supplierDto", new SupplierDto());
@ -33,7 +36,7 @@ public class SupplierMvcController {
} }
@PostMapping(value = {"", "/{id}"}) @PostMapping(value = {"", "/{id}"})
public String saveProduct(@PathVariable(required = false) Long id, public String saveSuppliers(@PathVariable(required = false) Long id,
@ModelAttribute @Valid SupplierDto supplierDto, @ModelAttribute @Valid SupplierDto supplierDto,
BindingResult bindingResult, BindingResult bindingResult,
Model model) { Model model) {
@ -42,7 +45,7 @@ public class SupplierMvcController {
return "supplier-edit"; return "supplier-edit";
} }
if (id == null || id <= 0) { if (id == null || id <= 0) {
supplierService.addSupplier(supplierDto.getName() , supplierDto.getLicense()); supplierService.addSupplier(supplierDto.getName(), supplierDto.getLicense());
} else { } else {
supplierService.updateSupplier(id, supplierDto.getName(), supplierDto.getLicense()); supplierService.updateSupplier(id, supplierDto.getName(), supplierDto.getLicense());
} }
@ -50,7 +53,7 @@ public class SupplierMvcController {
} }
@PostMapping("/delete/{id}") @PostMapping("/delete/{id}")
public String deleteProduct(@PathVariable Long id) { public String deleteSuppliers(@PathVariable Long id) {
supplierService.deleteSupplier(id); supplierService.deleteSupplier(id);
return "redirect:/supplier"; return "redirect:/supplier";
} }

View File

@ -1,37 +0,0 @@
package com.example.demo.util;
import com.example.demo.supply.Product.ProductNotFoundException;
import org.springframework.context.support.DefaultMessageSourceResolvable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import java.util.stream.Collectors;
@ControllerAdvice
public class AdviceController {
@ExceptionHandler({
ProductNotFoundException.class,
ValidationException.class
})
public ResponseEntity<Object> handleException(Throwable e) {
return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST);
}
@ExceptionHandler(MethodArgumentNotValidException.class)
public ResponseEntity<Object> handleBindException(MethodArgumentNotValidException e) {
final ValidationException validationException = new ValidationException(
e.getBindingResult().getAllErrors().stream()
.map(DefaultMessageSourceResolvable::getDefaultMessage)
.collect(Collectors.toSet()));
return handleException(validationException);
}
@ExceptionHandler(Exception.class)
public ResponseEntity<Object> handleUnknownException(Throwable e) {
e.printStackTrace();
return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}

View File

@ -1,9 +0,0 @@
package com.example.demo.util;
import java.util.Set;
public class ValidationException extends RuntimeException {
public ValidationException(Set<String> errors) {
super(String.join("\n", errors));
}
}

View File

@ -1,29 +0,0 @@
package com.example.demo.util;
import jakarta.validation.ConstraintViolation;
import jakarta.validation.Validation;
import jakarta.validation.Validator;
import jakarta.validation.ValidatorFactory;
import org.springframework.stereotype.Component;
import java.util.Set;
import java.util.stream.Collectors;
@Component
public class ValidatorUtil {
private final Validator validator;
public ValidatorUtil() {
try (ValidatorFactory factory = Validation.buildDefaultValidatorFactory()) {
this.validator = factory.getValidator();
}
}
public <T> void validate(T object) {
final Set<ConstraintViolation<T>> errors = validator.validate(object);
if (!errors.isEmpty()) {
throw new ValidationException(errors.stream()
.map(ConstraintViolation::getMessage)
.collect(Collectors.toSet()));
}
}
}

View File

@ -1,5 +1,5 @@
spring.main.banner-mode=off spring.main.banner-mode=off
server.port=8081 server.port=8080
spring.datasource.url=jdbc:h2:file:./data spring.datasource.url=jdbc:h2:file:./data
spring.datasource.driverClassName=org.h2.Driver spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa spring.datasource.username=sa

View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
</body>
</html>

View File

@ -6,18 +6,16 @@
<meta charset="UTF-8"/> <meta charset="UTF-8"/>
<title>Поставки</title> <title>Поставки</title>
<meta name="viewport" content="width=device-width, initial-scale=1"/> <meta name="viewport" content="width=device-width, initial-scale=1"/>
<!-- <link rel="icon" href="/">--> <link rel="icon" href="/favicon.svg">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous"> <script type="text/javascript" src="/webjars/bootstrap/5.1.3/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-gtEjrD/SeCtmISkJkNUaaKMoLD0//ElJ19smozuHV6z3Iehds+3Ulb9Bn9Plx0x4" crossorigin="anonymous"></script> <link rel="stylesheet" href="/webjars/bootstrap/5.1.3/css/bootstrap.min.css"/>
<script type="text/javascript" src="./webjars/bootstrap"></script> <link rel="stylesheet" href="/webjars/font-awesome/6.1.0/css/all.min.css"/>
<link rel="stylesheet" href="./webjars/bootstrap"/> <link rel="stylesheet" href="/css/style.css"/>
<link rel="stylesheet" href="./webjars/font-awesome"/>
<link rel="stylesheet" href="../public/favicon.svg"/>
</head> </head>
<body> <body>
<nav class="navbar navbar-expand-lg navbar-light bg-light"> <nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid"> <div class="container-fluid">
<a class="navbar-brand"> <a class="navbar-brand" href="/">
<i class="fa-solid fa-font-awesome"></i> <i class="fa-solid fa-font-awesome"></i>
Поставки Поставки
</a> </a>
@ -28,10 +26,14 @@
</button> </button>
<div class="collapse navbar-collapse" id="navbarNav"> <div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav" th:with="activeLink=${#request.requestURI}"> <ul class="navbar-nav" th:with="activeLink=${#request.requestURI}">
<a class="nav-link" href="/"
th:classappend="${#strings.equals(activeLink, '/')} ? 'active' : ''">Главная</a>
<a class="nav-link" href="/product" <a class="nav-link" href="/product"
th:classappend="${#strings.equals(activeLink, '/product')} ? 'active' : ''">Продукт</a> th:classappend="${#strings.equals(activeLink, '/product')} ? 'active' : ''">Продукты</a>
<a class="nav-link" href="/supplier" <a class="nav-link" href="/supplier"
th:classappend="${#strings.equals(activeLink, '/supplier')} ? 'active' : ''">Поставщик</a> th:classappend="${#strings.equals(activeLink, '/supplier')} ? 'active' : ''">Поставщики</a>
<a class="nav-link" href="/order"
th:classappend="${#strings.equals(activeLink, '/order')} ? 'active' : ''">Заказы</a>
<a class="nav-link" href="/swagger-ui/index.html" target="_blank">Документация REST API</a> <a class="nav-link" href="/swagger-ui/index.html" target="_blank">Документация REST API</a>
<a class="nav-link" href="/h2-console/" target="_blank">Консоль H2</a> <a class="nav-link" href="/h2-console/" target="_blank">Консоль H2</a>
</ul> </ul>

View File

@ -1,13 +1,12 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en" <html lang="en"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{main}"> layout:decorate="~{default}">
<head> <head>
</head> </head>
<body> <body>
<div layout:fragment="content"> <div layout:fragment="content">
<div>It's works!</div> <div>It's works!</div>
<a href="123">ERROR</a>
</div> </div>
</body> </body>
</html> </html>

View File

@ -0,0 +1,135 @@
<!DOCTYPE html>
<html lang="en"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{default}">
<head>
</head>
<body>
<div layout:fragment="content" class="mw-100">
<form action="#" th:action="@{/car/{id}(id=${id})}" method="post" class="mb-3">
<div class="d-flex justify-content-center">
<div style="margin-left: 2vw;">
<button type="submit" class="btn btn-outline-dark text-center button-fixed">
<span>Создать</span>
</button>
</div>
<div style="margin-left: 2vw;">
<a class="btn btn-outline-dark text-center button-fixed" th:href="@{/order}">
Отмена
</a>
</div>
</div>
</form>
<div class="d-flex container-fluid ">
<div style="width: 45vw; margin-right: 2vw" class="container-fluid">
<form action="#" th:action="@{/car/{id}(id=${id})}" method="post" >
<input name="wpName" type="hidden" th:value="${name}" />
<input name="PW" type="hidden" th:value="W" />
<div class="mb-3">
<label for="idW" class="form-label">Покупатель</label>
<select class="form-select" id = "idW" th:name="idPW">
<option th:each="value: ${buyers}"
th:value="${value.id}"
th:text="${value.buyerFirstName} + ' ' + ${value.buyerSecondName}">
</option>
</select>
</div>
<div class="mb-3">
<button type="submit" class="btn btn-outline-dark text-center button-fixed">
<span>Добавить продукт</span>
</button>
</div>
</form>
<table class="table" >
<thead>
<tr>
<th scope="col">id</th>
<th scope="col">Название</th>
<th scope="col">Цена</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
<tr th:each="product, iterator: ${carBuyers}">
<td th:text="${iterator.index} + 1"></td>
<td th:text="${product.name}"></td>
<td th:text="${product.cost}"></td>
<td>
<div>
<a type="button" class="btn btn-outline-dark text-center button-fixed"
th:attr="onclick=|confirm('Удалить запись?') && document.getElementById('remove-${product.id}').click()|">
<i class="fa fa-trash"></i>
</a>
</div>
<form th:action="@{'/car/' + ${id} + '?PW=W&wpName='+ ${name} +'&idPW=' + ${product.id} + '&delete=true'}" method="post">
<button th:id="'remove-' + ${product.id}" type="submit" style="display: none">
Удалить
</button>
</form>
</td>
</tr>
</tbody>
</table>
</div>
<div style="width: 45vw; margin-left: 2vw" class="container-fluid">
<form action="#" th:action="@{/car/{id}(id=${id})}" method="post" class="mb-3">
<input name="wpName" type="hidden" th:value="${name}" />
<input type="hidden" th:value="P" name="PW"/>
<div class="mb-3">
<label for="idP" class="form-label">Магазин</label>
<select class="form-select" id = "idP" th:name="idPW">
<option th:each="store, iterator: ${stores}"
th:value="${store.id}"
th:text="${store.storeName}">
</option>
</select>
</div>
<div class="mb-3">
<button type="submit" class="btn btn-outline-dark text-center button-fixed">
<span>Добавить</span>
</button>
</div>
</form>
<table class="table" id="tbl-items">
<thead>
<tr>
<th scope="col">id</th>
<th scope="col">Название</th>
<th scope="col">Цена</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
<tr th:each="carStore, iterator: ${carStores}">
<td th:text="${iterator.index} + 1"></td>
<td th:text="${carStore.storeName}"></td>
<td>
<div>
<a type="button" class="btn btn-outline-dark text-center button-fixed"
th:attr="onclick=|confirm('Удалить запись?') && document.getElementById('remove-${carStore.id}').click()|">
<i class="fa fa-trash"></i>
</a>
</div>
<form th:action="@{'/car/' + ${id} + '?PW=P&wpName='+ ${name} + '&idPW=' + ${carStore.id} + '&delete=true'}" method="post">
<button class = "btn btn-outline-dark text-center button-fixed" th:id="'remove-' + ${carStore.id}" type="submit" style="display: none">
Удалить
</button>
</form>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</body>
</html>

View File

@ -0,0 +1,49 @@
<!DOCTYPE html>
<html lang="en"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{default}">
<head>
</head>
<body>
<div layout:fragment="content">
<div>
<a class="btn btn-success button-fixed"
th:href="@{/order/}">
<i class="fa-solid fa-plus"></i> Создать заказ
</a>
</div>
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">ID</th>
<th scope="col">Дата создания</th>
<th scope="col">Поставщик</th>
<th scope="col">Продукты</th>
</tr>
</thead>
<tbody>
<tr th:each="product, iterator: ${orders}">
<th scope="row" th:text="${iterator.index} + 1"/>
<td th:text="${order.id}"/>
<td th:text="${order.dateOfOrder}" />
<td th:text="${order.supplier}" />
<td>
<li th:each="product : ${order.products}" th:text="${product.name}"></li>
<!-- <select class="form-select" size="3" aria-label="size 3 select example">-->
<!-- <option selected>Open this select menu</option>-->
<!-- <option value="1">One</option>-->
<!-- <option value="2">Two</option>-->
<!-- <option value="3">Three</option>-->
<!-- </select>-->
</td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>

View File

@ -1,12 +1,11 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en" <html lang="en"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{main}"> layout:decorate="~{default}">
<head> <head>
</head> </head>
<body> <body>
<div layout:fragment="content"> <div layout:fragment="content">
<!-- <div th:text="${errors}" class="margin-bottom alert-danger"></div>-->
<form action="#" th:action="@{/product/{id}(id=${id})}" th:object="${productDto}" method="post"> <form action="#" th:action="@{/product/{id}(id=${id})}" th:object="${productDto}" method="post">
<div class="mb-3"> <div class="mb-3">
<label for="name" class="form-label">Название</label> <label for="name" class="form-label">Название</label>

View File

@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en" <html lang="en"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{main}"> layout:decorate="~{default}">
<head> <head>
</head> </head>
<body> <body>
@ -28,7 +28,7 @@
<th scope="row" th:text="${iterator.index} + 1"/> <th scope="row" th:text="${iterator.index} + 1"/>
<td th:text="${product.id}"/> <td th:text="${product.id}"/>
<td th:text="${product.name}" /> <td th:text="${product.name}" />
<td th:text="${product.cost}"/> <td th:text="${product.cost}" />
<td style="width: 10%"> <td style="width: 10%">
<div class="btn-group" role="group" aria-label="Basic example"> <div class="btn-group" role="group" aria-label="Basic example">
<a class="btn btn-warning button-fixed button-sm" <a class="btn btn-warning button-fixed button-sm"

View File

@ -1,27 +1,26 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en" <html lang="en"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{main}"> layout:decorate="~{default}">
<head> <head>
</head> </head>
<body> <body>
<div layout:fragment="content"> <div layout:fragment="content">
<!-- <div th:text="${errors}" class="margin-bottom alert-danger"></div>--> <form action="#" th:action="@{/supplier/{id}(id=${id})}" th:object="${supplierDto}" method="post">
<form action="#" th:action="@{/product/{id}(id=${id})}" th:object="${productDto}" method="post">
<div class="mb-3"> <div class="mb-3">
<label for="name" class="form-label">Название</label> <label for="name" class="form-label">Название</label>
<input type="text" class="form-control" id="name" th:field="${productDto.name}" required="true"> <input type="text" class="form-control" id="name" th:field="${supplierDto.name}" required="true">
</div> </div>
<div class="mb-3"> <div class="mb-3">
<label for="cost" class="form-label">Лицензия</label> <label for="license" class="form-label">Лицензия</label>
<input type="text" class="form-control" id="cost" th:field="${productDto.cost}" required="true"> <input type="text" class="form-control" id="license" th:field="${supplierDto.license}" required="true">
</div> </div>
<div class="mb-3"> <div class="mb-3">
<button type="submit" class="btn btn-primary button-fixed"> <button type="submit" class="btn btn-primary button-fixed">
<span th:if="${id == null}">Добавить</span> <span th:if="${id == null}">Добавить</span>
<span th:if="${id != null}">Обновить</span> <span th:if="${id != null}">Обновить</span>
</button> </button>
<a class="btn btn-secondary button-fixed" th:href="@{/product}"> <a class="btn btn-secondary button-fixed" th:href="@{/supplier}">
Назад Назад
</a> </a>
</div> </div>

View File

@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en" <html lang="en"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{main}"> layout:decorate="~{default}">
<head> <head>
</head> </head>
<body> <body>
@ -27,7 +27,7 @@
<tr th:each="supplier, iterator: ${suppliers}"> <tr th:each="supplier, iterator: ${suppliers}">
<th scope="row" th:text="${iterator.index} + 1"/> <th scope="row" th:text="${iterator.index} + 1"/>
<td th:text="${supplier.id}"/> <td th:text="${supplier.id}"/>
<td th:text="${supplier.name}" style="width: 60%"/> <td th:text="${supplier.name}"/>
<td th:text="${supplier.license}"/> <td th:text="${supplier.license}"/>
<td style="width: 10%"> <td style="width: 10%">
<div class="btn-group" role="group" aria-label="Basic example"> <div class="btn-group" role="group" aria-label="Basic example">