diff --git a/backend/ipLab/build.gradle b/backend/ipLab/build.gradle index dec8f5c..292d83d 100644 --- a/backend/ipLab/build.gradle +++ b/backend/ipLab/build.gradle @@ -23,6 +23,13 @@ dependencies { testImplementation 'org.springframework.boot:spring-boot-starter-test' implementation 'org.hibernate.validator:hibernate-validator' + + implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' + implementation 'org.springframework.boot:spring-boot-devtools' + implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect' + implementation 'org.webjars:bootstrap:5.1.3' + implementation 'org.webjars:jquery:3.6.0' + implementation 'org.webjars:font-awesome:6.1.0' } tasks.named('test') { diff --git a/backend/ipLab/data.mv.db b/backend/ipLab/data.mv.db index af21ef0..49988c5 100644 Binary files a/backend/ipLab/data.mv.db and b/backend/ipLab/data.mv.db differ diff --git a/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/Controllers/CustomerController.java b/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/Controllers/CustomerController.java index 1da68d3..a1c9c23 100644 --- a/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/Controllers/CustomerController.java +++ b/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/Controllers/CustomerController.java @@ -3,12 +3,14 @@ package com.example.ipLab.StoreDataBase.Controllers; import com.example.ipLab.StoreDataBase.DTO.CustomerDTO; import com.example.ipLab.StoreDataBase.Model.Customer; import com.example.ipLab.StoreDataBase.Service.CustomerService; +import com.example.ipLab.WebConfiguration; +import jakarta.validation.Valid; import org.springframework.web.bind.annotation.*; import java.util.List; @RestController -@RequestMapping("/customer") +@RequestMapping(WebConfiguration.REST_API + "/customer") public class CustomerController { private final CustomerService customerService; @@ -29,19 +31,15 @@ public class CustomerController { } @PostMapping - public CustomerDTO createCustomer(@RequestParam("customerLastName") String customerLastName, - @RequestParam("customerFirstName") String customerFirstName, - @RequestParam("customerMiddleName") String customerMiddleName){ - final Customer customer = customerService.addCustomer(customerLastName, customerFirstName, customerMiddleName); + public CustomerDTO createCustomer(@RequestBody @Valid CustomerDTO customerDTO){ + final Customer customer = customerService.addCustomer(customerDTO.getlastName(), customerDTO.getfirstName(), customerDTO.getmiddleName()); return new CustomerDTO(customer); } @PutMapping("/{id}") - public CustomerDTO updateCustomer(@RequestParam("customerLastName") String customerLastName, - @RequestParam("customerFirstName") String customerFirstName, - @RequestParam("customerMiddleName") String customerMiddleName, + public CustomerDTO updateCustomer(@RequestBody @Valid CustomerDTO customerDTO, @PathVariable Long id){ - return new CustomerDTO(customerService.updateCustomer(id, customerLastName, customerFirstName, customerMiddleName)); + return new CustomerDTO(customerService.updateCustomer(id, customerDTO.getlastName(), customerDTO.getfirstName(), customerDTO.getmiddleName())); } @DeleteMapping("/{id}") diff --git a/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/Controllers/OrderedController.java b/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/Controllers/OrderedController.java index 498ffd1..c1bf254 100644 --- a/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/Controllers/OrderedController.java +++ b/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/Controllers/OrderedController.java @@ -5,12 +5,14 @@ import com.example.ipLab.StoreDataBase.Model.Ordered; import com.example.ipLab.StoreDataBase.Service.CustomerService; import com.example.ipLab.StoreDataBase.Service.OrderService; import com.example.ipLab.StoreDataBase.Service.ProductService; +import com.example.ipLab.WebConfiguration; +import jakarta.validation.Valid; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; import java.util.List; @RestController -@RequestMapping("/order") +@RequestMapping(WebConfiguration.REST_API + "/order") public class OrderedController { private final OrderService orderedService; private final ProductService productService; @@ -35,17 +37,15 @@ public class OrderedController { } @PostMapping - public OrderedDTO createOrdered(@RequestParam("productId") Long productId, - @RequestParam("customerId") Long customerId, - @RequestParam("quantity") Integer quantity){ - final Ordered ordered = orderedService.addOrder(productService.getProduct(productId), customerService.getCustomer(customerId), quantity); + public OrderedDTO createOrdered(@RequestBody @Valid OrderedDTO orderedDTO){ + final Ordered ordered = orderedService.addOrder(productService.getProduct(orderedDTO.getProductId()), customerService.getCustomer(orderedDTO.getCustomerId()), orderedDTO.quantity); return new OrderedDTO(ordered); } @PutMapping("/{id}") - public OrderedDTO updateOrdered(@RequestParam("quantity") Integer quantity, + public OrderedDTO updateOrdered(@RequestBody @Valid OrderedDTO orderedDTO, @PathVariable Long id){ - return new OrderedDTO(orderedService.updateOrder(id, quantity)); + return new OrderedDTO(orderedService.updateOrder(id, orderedDTO.quantity)); } @DeleteMapping("/{id}") diff --git a/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/Controllers/ProductController.java b/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/Controllers/ProductController.java index db8db1c..aa6cdd3 100644 --- a/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/Controllers/ProductController.java +++ b/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/Controllers/ProductController.java @@ -3,12 +3,14 @@ package com.example.ipLab.StoreDataBase.Controllers; import com.example.ipLab.StoreDataBase.DTO.ProductDTO; import com.example.ipLab.StoreDataBase.Model.Product; import com.example.ipLab.StoreDataBase.Service.ProductService; +import com.example.ipLab.WebConfiguration; +import jakarta.validation.Valid; import org.springframework.web.bind.annotation.*; import java.util.List; @RestController -@RequestMapping("/product") +@RequestMapping(WebConfiguration.REST_API + "/product") public class ProductController { private final ProductService productService; @@ -43,15 +45,15 @@ public class ProductController { } @PostMapping - public ProductDTO createProduct(@RequestParam("productName") String productName){ - final Product product = productService.addProduct(productName); + public ProductDTO createProduct(@RequestBody @Valid ProductDTO productDTO){ + final Product product = productService.addProduct(productDTO.getName()); return new ProductDTO(product); } @PutMapping("/{id}") - public ProductDTO updateProduct(@RequestParam("productName") String productName, + public ProductDTO updateProduct(@RequestBody @Valid ProductDTO productDTO, @PathVariable Long id){ - return new ProductDTO(productService.updateProduct(id, productName)); + return new ProductDTO(productService.updateProduct(id, productDTO.getName())); } @DeleteMapping("/{id}") diff --git a/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/Controllers/StoreController.java b/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/Controllers/StoreController.java index f918377..69cb869 100644 --- a/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/Controllers/StoreController.java +++ b/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/Controllers/StoreController.java @@ -7,12 +7,14 @@ import com.example.ipLab.StoreDataBase.Model.Customer; import com.example.ipLab.StoreDataBase.Model.Store; import com.example.ipLab.StoreDataBase.Service.CustomerService; import com.example.ipLab.StoreDataBase.Service.StoreService; +import com.example.ipLab.WebConfiguration; +import jakarta.validation.Valid; import org.springframework.web.bind.annotation.*; import java.util.List; @RestController -@RequestMapping("/store") +@RequestMapping(WebConfiguration.REST_API + "/store") public class StoreController { private final StoreService storeService; @@ -33,21 +35,21 @@ public class StoreController { } @PostMapping - public StoreDTO createStore(@RequestParam("storeName") String storeName){ - final Store store = storeService.addStore(storeName); + public StoreDTO createStore(@RequestBody @Valid StoreDTO storeDTO){ + final Store store = storeService.addStore(storeDTO.getStoreName()); return new StoreDTO(store); } @PutMapping("/{id}") - public StoreDTO updateStore(@RequestParam("storeName") String storeName, + public StoreDTO updateStore(@RequestBody @Valid StoreDTO storeDTO, @PathVariable Long id){ - return new StoreDTO(storeService.updateStore(id, storeName)); + return new StoreDTO(storeService.updateStore(id, storeDTO.getStoreName())); } - @PutMapping("/add") - public ProductDTO addProduct(@RequestParam("storeId") Long storeId, - @RequestParam("productId") Long productId){ - return new ProductDTO(storeService.addProduct(storeId, productId)); + @PutMapping("{id}/add") + public ProductDTO addProduct(@PathVariable Long id, + @RequestBody @Valid CustomerDTO customerDTO){ + return new ProductDTO(storeService.addProduct(id, customerDTO.getId())); } @DeleteMapping("/{id}") diff --git a/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/DTO/CustomerDTO.java b/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/DTO/CustomerDTO.java index 25ba14b..d2d41d4 100644 --- a/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/DTO/CustomerDTO.java +++ b/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/DTO/CustomerDTO.java @@ -1,14 +1,20 @@ package com.example.ipLab.StoreDataBase.DTO; import com.example.ipLab.StoreDataBase.Model.Customer; - -import java.util.List; +import jakarta.validation.constraints.NotBlank; public class CustomerDTO { - public final Long id; - public final String lastName; - public final String firstName; - public final String middleName; + public Long id; + @NotBlank(message = "lastName can't be null or empty") + public String lastName; + @NotBlank(message = "firstName can't be null or empty") + public String firstName; + @NotBlank(message = "middleName can't be null or empty") + public String middleName; + + public CustomerDTO(){ + + } public CustomerDTO(Customer customer){ this.id = customer.getId(); @@ -20,16 +26,25 @@ public class CustomerDTO { public Long getId() { return id; } - - public String getLastname() { + public void setId(Long id) { + this.id = id; + } + public String getlastName() { return lastName; } - - public String getFirstname() { + public void setlastName(String lastName) { + this.lastName = lastName; + } + public String getfirstName() { return firstName; } - - public String getMiddleName() { + public void setfirstName(String firstName) { + this.firstName = firstName; + } + public String getmiddleName() { return middleName; } + public void setmiddleName(String middleName) { + this.middleName = middleName; + } } diff --git a/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/DTO/OrderedDTO.java b/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/DTO/OrderedDTO.java index 2eabeec..24e4fd0 100644 --- a/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/DTO/OrderedDTO.java +++ b/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/DTO/OrderedDTO.java @@ -3,11 +3,17 @@ package com.example.ipLab.StoreDataBase.DTO; import com.example.ipLab.StoreDataBase.Model.Ordered; public class OrderedDTO { - public final Long id; - public final int quantity; - public final String productName; - public final String customerFIO; - public final String storeName; + public Long id; + public int quantity; + public String productName; + public String customerFIO; + public String storeName; + public Long customerId; + public Long productId; + + public OrderedDTO(){ + + } public OrderedDTO(Ordered ordered){ this.id = ordered.getId(); @@ -15,6 +21,8 @@ public class OrderedDTO { this.productName = ordered.getProduct().getName(); this.storeName = ordered.getProduct().getStore().getStoreName(); this.customerFIO = ordered.getCustomer().getLastName() + " " + ordered.getCustomer().getFirstName() + " " + ordered.getCustomer().getMiddleName(); + this.customerId = ordered.getProduct().getId(); + this.productId = ordered.getProduct().getId(); } public Long getId() { @@ -36,4 +44,12 @@ public class OrderedDTO { public String getStoreName() { return storeName; } + + public Long getCustomerId() { + return customerId; + } + + public Long getProductId() { + return productId; + } } diff --git a/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/DTO/ProductDTO.java b/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/DTO/ProductDTO.java index 826b2b8..ad38611 100644 --- a/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/DTO/ProductDTO.java +++ b/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/DTO/ProductDTO.java @@ -5,9 +5,12 @@ import com.example.ipLab.StoreDataBase.Model.Product; import java.util.List; public class ProductDTO { - public final Long id; - public final String productName; - public final String storeName; + public Long id; + public String productName; + public String storeName; + public ProductDTO(){ + + } public ProductDTO(Product product){ this.id = product.getId(); diff --git a/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/DTO/StoreDTO.java b/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/DTO/StoreDTO.java index a03e101..8157137 100644 --- a/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/DTO/StoreDTO.java +++ b/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/DTO/StoreDTO.java @@ -5,9 +5,13 @@ import com.example.ipLab.StoreDataBase.Model.Store; import java.util.List; public class StoreDTO { - public final Long id; - public final String storeName; - public final List products; + public Long id; + public String storeName; + public List products; + + public StoreDTO(){ + + } public StoreDTO(Store store){ this.id = store.getId(); diff --git a/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/MVC/CustomerMVCController.java b/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/MVC/CustomerMVCController.java new file mode 100644 index 0000000..fa6546b --- /dev/null +++ b/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/MVC/CustomerMVCController.java @@ -0,0 +1,63 @@ +package com.example.ipLab.StoreDataBase.MVC; + +import com.example.ipLab.StoreDataBase.DTO.CustomerDTO; +import com.example.ipLab.StoreDataBase.Service.CustomerService; +import jakarta.validation.Valid; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.*; + +@Controller +@RequestMapping("/customer") +public class CustomerMVCController { + private final CustomerService customerService; + + public CustomerMVCController(CustomerService customerService) { + this.customerService = customerService; + } + + @GetMapping + public String getCustomers(Model model) { + model.addAttribute("customers", + customerService.getAllCustomers().stream() + .map(CustomerDTO::new) + .toList()); + return "customer"; + } + + @GetMapping(value = {"/edit/", "/edit/{id}"}) + public String editCustomer(@PathVariable(required = false) Long id, + Model model) { + if (id == null || id <= 0) { + model.addAttribute("customerDTO", new CustomerDTO()); + } else { + model.addAttribute("customerId", id); + model.addAttribute("customerDTO", new CustomerDTO(customerService.getCustomer(id))); + } + return "customer-edit"; + } + + @PostMapping(value = {"/", "/{id}"}) + public String saveCustomer(@PathVariable(required = false) Long id, + @ModelAttribute @Valid CustomerDTO customerDto, + BindingResult bindingResult, + Model model) { + if (bindingResult.hasErrors()) { + model.addAttribute("errors", bindingResult.getAllErrors()); + return "customer-edit"; + } + if (id == null || id <= 0) { + customerService.addCustomer(customerDto.getlastName(), customerDto.getfirstName(), customerDto.getmiddleName()); + } else { + customerService.updateCustomer(id, customerDto.getlastName(), customerDto.getfirstName(), customerDto.getmiddleName()); + } + return "redirect:/customer"; + } + + @PostMapping("/delete/{id}") + public String deleteCustomer(@PathVariable Long id) { + customerService.deleteCustomer(id); + return "redirect:/customer"; + } +} diff --git a/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/util/error/AdviceController.java b/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/util/error/AdviceController.java index d9a5aa5..2a261cf 100644 --- a/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/util/error/AdviceController.java +++ b/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/util/error/AdviceController.java @@ -11,10 +11,11 @@ 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 org.springframework.web.bind.annotation.RestController; import java.util.stream.Collectors; -@ControllerAdvice +@ControllerAdvice(annotations = RestController.class) public class AdviceController { @ExceptionHandler({ CustomerNotFoundException.class, diff --git a/backend/ipLab/src/main/java/com/example/ipLab/WebConfiguration.java b/backend/ipLab/src/main/java/com/example/ipLab/WebConfiguration.java index 7e79574..8db3443 100644 --- a/backend/ipLab/src/main/java/com/example/ipLab/WebConfiguration.java +++ b/backend/ipLab/src/main/java/com/example/ipLab/WebConfiguration.java @@ -6,6 +6,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @Configuration public class WebConfiguration implements WebMvcConfigurer { + public static final String REST_API = "/api"; @Override public void addCorsMappings(CorsRegistry registry){ registry.addMapping("/**").allowedMethods("*"); diff --git a/backend/ipLab/src/main/resources/public/css/styleSite.css b/backend/ipLab/src/main/resources/public/css/styleSite.css new file mode 100644 index 0000000..53cdb75 --- /dev/null +++ b/backend/ipLab/src/main/resources/public/css/styleSite.css @@ -0,0 +1,284 @@ +header{ + background-color: #9094c1; + flex-direction: row; +} +header nav{ + font-family: Segoe UI; + font-weight: bold; + font-size: 42px; +} +header nav a{ + color: inherit; +} +header nav a:hover{ + text-decoration: underline; +} +.navigationCaption{ + font-family: Segoe UI; + font-weight: bold; + font-size: 42px; +} +.headNav{ + color: inherit; +} +a{ + color: inherit; + text-decoration: none; +} +td, th{ + border: 1px solid black; + font-family: Segoe UI; + text-align: center; + font-size: 28px; +} +table tbody td a:hover{ + text-decoration: underline; + color: inherit; +} + +footer{ + background-color: #707be5; + max-height: 110px; +} + +.mainPage a:hover{ + text-decoration: underline; + color: inherit; +} + +.popularCaption{ + font-family: Segoe UI; + font-size: 24px; +} + +.discountsCaption{ + font-family: Segoe UI; + font-size: 24px; +} + +.item{ + font-family: Segoe UI; + font-size: 18px; +} + +.item img{ + width: 200px; + height: 200px; +} + +.tableMy table caption{ + font-family: Segoe UI; + font-weight: bold; + font-size: 45px; +} +.tableMy table tbody td a:hover{ + text-decoration: underline; + color: inherit !important; +} + +.tableCart table caption{ + font-family: Segoe UI; + font-weight: bold; + font-size: 32px; +} + +.cartInfo{ + margin-top: 320px; + margin-right: 400px; + font-family: Segoe UI; + font-size: 45px; +} + +.buttonOrder{ + background-color: #4d89d9; +} + +.itemCaption{ + font-family: Segoe UI; + font-size: 32px; +} + +#itemPhoto{ + margin-left: 50px; +} + +.itemInfo{ + font-family: Segoe UI; + font-size: 45px; + margin-left: 85px; +} + +.itemInfo li{ + list-style-type: none; +} + +.buttonAdd{ + font-family: Segoe UI; + font-size: 45px; + background-color: #4d89d9; + margin-left: 35px; +} +.companyName{ + font-family: Segoe UI; + font-size: 45px; +} +.longText{ + font-family: Segoe UI; + font-size: 25px; +} +#logoName{ + font-family: Rockwell Condensed; + font-size: 64px; + font-weight: bold; + font-stretch: condensed; + text-decoration: none; +} + +#logoName a:hover{ + text-decoration: none; + color: inherit; +} + +.footerLeft{ + margin-bottom: 10px; + font-family: Segoe UI; + font-size: 16px; +} +.footerBottom{ + font-family: Segoe UI; + font-size: 28px; +} + +.hide{ + display: none; +} + +.active{ + display: block; +} + +.active img{ + width: 200px; + height: 100px; +} + +@media (max-width: 1080px){ + header{ + flex-direction: column; + } + + header nav{ + text-align: center; + } + + .headerContainer{ + flex-direction: column !important; + } + + .itemContent{ + flex-direction: column !important; + justify-content: center !important; + } + + #itemPhoto{ + margin-left: auto !important; + margin-right: auto ; + } + + .itemInfo{ + margin-bottom: 10px !important; + margin-left: 10px!important; + } + + #cartContainer{ + flex-direction: column !important; + } + + .cartInfo{ + margin-top: 0px !important; + margin-left: 5px; + margin-right: auto; + margin-bottom: 10px; + } + + #tableCart{ + width: auto; + } + + .mainPage{ + flex-direction: column !important; + justify-content: center; + } + + .tablePopular{ + margin-left: auto !important; + margin-right: auto !important; + } + + .tableDiscounts{ + margin-top: 30px; + margin-left: auto !important; + margin-right: auto !important; + } +} + +@media (max-width: 767px){ + .tableMy table thead th{ + font-size: 12px !important; + } + + .tableMy table tr td{ + font-size: 12px !important; + } + + .tableCart table thead th{ + font-size: 18px !important; + } + + .tableCart table tr td{ + font-size: 18px !important; + } + + .cartInfo{ + font-size: 18px !important; + } + + .itemInfo{ + font-size: 18px !important; + } + + .buttonAdd{ + font-size: 18px !important + } + + .footerLeft{ + font-size: 12px !important; + } + + .footerBottom{ + font-size: 16px !important; + } + + .footerRight img{ + width: 55px; + height: 27px; + } + + .mainPage img{ + width: 100px !important; + height: 100px !important; + } + + .popularCaption{ + font-size: 18px !important; + } + + .discountsCaption{ + font-size: 18px !important; + } + + #itemIcon{ + width: 250px !important; + height: 250px !important; + } +} \ No newline at end of file diff --git a/backend/ipLab/src/main/resources/public/favicon.ico b/backend/ipLab/src/main/resources/public/favicon.ico new file mode 100644 index 0000000..0bd84aa Binary files /dev/null and b/backend/ipLab/src/main/resources/public/favicon.ico differ diff --git a/backend/ipLab/src/main/resources/templates/customer-edit.html b/backend/ipLab/src/main/resources/templates/customer-edit.html new file mode 100644 index 0000000..ca60b54 --- /dev/null +++ b/backend/ipLab/src/main/resources/templates/customer-edit.html @@ -0,0 +1,35 @@ + + + + + +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + + Назад + +
+
+
+ + \ No newline at end of file diff --git a/backend/ipLab/src/main/resources/templates/customer.html b/backend/ipLab/src/main/resources/templates/customer.html new file mode 100644 index 0000000..16afff1 --- /dev/null +++ b/backend/ipLab/src/main/resources/templates/customer.html @@ -0,0 +1,55 @@ + + + + + +
+
+ + Добавить + +
+
+ + + + + + + + + + + + + + + +
#ФамилияИмяОтчество
+ + + + +
+ + Изменить + + +
+
+ +
+
+
+
+ + \ No newline at end of file diff --git a/backend/ipLab/src/main/resources/templates/default.html b/backend/ipLab/src/main/resources/templates/default.html new file mode 100644 index 0000000..f9b6cb9 --- /dev/null +++ b/backend/ipLab/src/main/resources/templates/default.html @@ -0,0 +1,47 @@ + + + + + IP Example + + + + + + + + +
+
+ +
+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/backend/ipLab/src/main/resources/templates/error.html b/backend/ipLab/src/main/resources/templates/error.html new file mode 100644 index 0000000..78fb62d --- /dev/null +++ b/backend/ipLab/src/main/resources/templates/error.html @@ -0,0 +1,13 @@ + + + + + +
+
+ На главную +
+ + \ No newline at end of file diff --git a/backend/ipLab/src/main/resources/templates/index.html b/backend/ipLab/src/main/resources/templates/index.html new file mode 100644 index 0000000..0749f2c --- /dev/null +++ b/backend/ipLab/src/main/resources/templates/index.html @@ -0,0 +1,13 @@ + + + + + +
+
It's works!
+ ERROR +
+ + \ No newline at end of file diff --git a/frontend/src/components/common/customerTable.jsx b/frontend/src/components/common/customerTable.jsx index 61d4574..4e3a84e 100644 --- a/frontend/src/components/common/customerTable.jsx +++ b/frontend/src/components/common/customerTable.jsx @@ -23,14 +23,15 @@ export default function CustomerTable(props){ } function saveItem() { + let customer = { + lastName: props.data.lastName, + firstName: props.data.firstName, + middleName: props.data.middleName + } if (!isEdit) { - DataService.create(props.url, "?customerLastName=" + props.data.lastName - + "&customerFirstName=" + props.data.firstName - + "&customerMiddleName=" + props.data.middleName).then(() => loadItems()); + DataService.create(props.url, customer).then(() => loadItems()); } else { - DataService.update(props.getUrl + props.data.id, "?customerLastName=" + props.data.lastName - + "&customerFirstName=" + props.data.firstName - + "&customerMiddleName=" + props.data.middleName).then(() => loadItems()); + DataService.update(props.getUrl + props.data.id, customer).then(() => loadItems()); } } diff --git a/frontend/src/components/common/orderTable.jsx b/frontend/src/components/common/orderTable.jsx index 330325e..047ed19 100644 --- a/frontend/src/components/common/orderTable.jsx +++ b/frontend/src/components/common/orderTable.jsx @@ -28,10 +28,15 @@ export default function CustomerTable(props){ } function saveItem() { + let ordered = { + productId: props.data.productId, + customerId: props.data.customerId, + quantity: props.data.quantity + } if (!isEdit) { - DataService.create(props.url, "?productId=" + props.data.productId + "&customerId=" + props.data.customerId + "&quantity=" + props.data.quantity).then(() => loadItems()); + DataService.create(props.url, ordered).then(() => loadItems()); } else { - DataService.update(props.getUrl + props.data.id, "?productId=" + props.data.productId + "&customerId=" + props.data.customerId + "&quantity=" + props.data.quantity).then(() => loadItems()); + DataService.update(props.getUrl + props.data.id, ordered).then(() => loadItems()); } } diff --git a/frontend/src/components/common/productTable.jsx b/frontend/src/components/common/productTable.jsx index 6a8b67b..49e17a3 100644 --- a/frontend/src/components/common/productTable.jsx +++ b/frontend/src/components/common/productTable.jsx @@ -23,10 +23,13 @@ export default function CustomerTable(props){ } function saveItem() { + let product = { + productName: props.data.productName + } if (!isEdit) { - DataService.create(props.url, "?productName=" + props.data.productName).then(() => loadItems()); + DataService.create(props.url, product).then(() => loadItems()); } else { - DataService.update(props.getUrl + props.data.id, "?productName=" + props.data.productName).then(() => loadItems()); + DataService.update(props.getUrl + props.data.id, product).then(() => loadItems()); } } diff --git a/frontend/src/components/common/storeTable.jsx b/frontend/src/components/common/storeTable.jsx index 51a0e21..b1b3bda 100644 --- a/frontend/src/components/common/storeTable.jsx +++ b/frontend/src/components/common/storeTable.jsx @@ -23,10 +23,13 @@ export default function CustomerTable(props){ } function saveItem() { + let store = { + storeName: props.data.storeName + } if (!isEdit) { - DataService.create(props.url, "?storeName=" + props.data.storeName).then(() => loadItems()); + DataService.create(props.url, store).then(() => loadItems()); } else { - DataService.update(props.getUrl + props.data.id, "?storeName=" + props.data.storeName).then(() => loadItems()); + DataService.update(props.getUrl + props.data.id, store).then(() => loadItems()); } } diff --git a/frontend/src/components/pages/addToStorePage.jsx b/frontend/src/components/pages/addToStorePage.jsx index 2c232f7..c725c89 100644 --- a/frontend/src/components/pages/addToStorePage.jsx +++ b/frontend/src/components/pages/addToStorePage.jsx @@ -6,7 +6,7 @@ import { useState, useEffect} from "react"; export default function AddToStorePage(){ const getStoreUrl = 'store'; const getProductUrl = 'product/getWithoutStores' - const url = 'store/add' + const url = 'store/' const [storeOptions, setStoreOptions] = useState([]) const [productOptions, setProductOptions] = useState([]) const transformerProduct = (data) => new Product(data); @@ -44,8 +44,10 @@ export default function AddToStorePage(){ function add(){ var storeId = document.getElementById("storeId").value; var productId = document.getElementById("productId").value; - - DataService.update(url, "?storeId=" + storeId + "&productId=" + productId); + let product = { + id: productId + } + DataService.update(url + storeId + "/add", product); window.location.replace("/product"); } diff --git a/frontend/src/services/DataService.js b/frontend/src/services/DataService.js index a703069..7ed9068 100644 --- a/frontend/src/services/DataService.js +++ b/frontend/src/services/DataService.js @@ -13,7 +13,7 @@ function toJSON(data) { } export default class DataService { - static dataUrlPrefix = 'http://localhost:8080/'; + static dataUrlPrefix = 'http://localhost:8080/api/'; static async readAll(url, transformer) { const response = await axios.get(this.dataUrlPrefix + url); @@ -26,13 +26,12 @@ export default class DataService { } static async create(url, data) { - console.log("Test create " + this.dataUrlPrefix + url + data); - const response = await axios.post(this.dataUrlPrefix + url + data); + const response = await axios.post(this.dataUrlPrefix + url, data); return true; } static async update(url, data) { - const response = await axios.put(this.dataUrlPrefix + url + data); + const response = await axios.put(this.dataUrlPrefix + url, data); return true; }