diff --git a/backend/ipLab/build.gradle b/backend/ipLab/build.gradle index 292d83d..8e65326 100644 --- a/backend/ipLab/build.gradle +++ b/backend/ipLab/build.gradle @@ -1,6 +1,6 @@ plugins { id 'java' - id 'org.springframework.boot' version '3.0.2' + id 'org.springframework.boot' version '3.0.1' id 'io.spring.dependency-management' version '1.1.0' } diff --git a/backend/ipLab/data.mv.db b/backend/ipLab/data.mv.db index dc92361..fcff4ed 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/ProductController.java b/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/Controllers/ProductController.java index aa6cdd3..ba86444 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 @@ -46,14 +46,14 @@ public class ProductController { @PostMapping public ProductDTO createProduct(@RequestBody @Valid ProductDTO productDTO){ - final Product product = productService.addProduct(productDTO.getName()); + final Product product = productService.addProduct(productDTO.getproductName()); return new ProductDTO(product); } @PutMapping("/{id}") public ProductDTO updateProduct(@RequestBody @Valid ProductDTO productDTO, @PathVariable Long id){ - return new ProductDTO(productService.updateProduct(id, productDTO.getName())); + return new ProductDTO(productService.updateProduct(id, productDTO.getproductName())); } @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 69cb869..d2ceb16 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 @@ -3,9 +3,7 @@ package com.example.ipLab.StoreDataBase.Controllers; import com.example.ipLab.StoreDataBase.DTO.CustomerDTO; import com.example.ipLab.StoreDataBase.DTO.ProductDTO; import com.example.ipLab.StoreDataBase.DTO.StoreDTO; -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; @@ -36,14 +34,14 @@ public class StoreController { @PostMapping public StoreDTO createStore(@RequestBody @Valid StoreDTO storeDTO){ - final Store store = storeService.addStore(storeDTO.getStoreName()); + final Store store = storeService.addStore(storeDTO.getstoreName()); return new StoreDTO(store); } @PutMapping("/{id}") public StoreDTO updateStore(@RequestBody @Valid StoreDTO storeDTO, @PathVariable Long id){ - return new StoreDTO(storeService.updateStore(id, storeDTO.getStoreName())); + return new StoreDTO(storeService.updateStore(id, storeDTO.getstoreName())); } @PutMapping("{id}/add") 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 d2d41d4..8d49373 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 @@ -11,6 +11,7 @@ public class CustomerDTO { public String firstName; @NotBlank(message = "middleName can't be null or empty") public String middleName; + public String customerFIO; public CustomerDTO(){ @@ -21,6 +22,7 @@ public class CustomerDTO { this.lastName = customer.getLastName(); this.firstName = customer.getFirstName(); this.middleName = customer.getMiddleName(); + this.customerFIO = lastName + " " + firstName + " " + middleName; } public Long getId() { @@ -47,4 +49,12 @@ public class CustomerDTO { public void setmiddleName(String middleName) { this.middleName = middleName; } + + public String getcustomerFIO() { + return customerFIO; + } + + public void setcustomerFIO(String customerFIO) { + this.customerFIO = customerFIO; + } } 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 24e4fd0..04090e1 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 @@ -1,6 +1,8 @@ package com.example.ipLab.StoreDataBase.DTO; +import com.example.ipLab.StoreDataBase.Model.Customer; import com.example.ipLab.StoreDataBase.Model.Ordered; +import com.example.ipLab.StoreDataBase.Model.Product; public class OrderedDTO { public Long id; @@ -33,18 +35,30 @@ public class OrderedDTO { return quantity; } - public String getProductName() { + public String getproductName() { return productName; } - public String getCustomerFIO() { + public void setproductName(String productName) { + this.productName = productName; + } + + public String getcustomerFIO() { return customerFIO; } - public String getStoreName() { + public void setcustomerFIO(String customerFIO) { + this.customerFIO = customerFIO; + } + + public String getstoreName() { return storeName; } + public void setstoreName(String storeName) { + this.storeName = storeName; + } + public Long getCustomerId() { return customerId; } 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 ad38611..06620d6 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 @@ -2,8 +2,6 @@ package com.example.ipLab.StoreDataBase.DTO; import com.example.ipLab.StoreDataBase.Model.Product; -import java.util.List; - public class ProductDTO { public Long id; public String productName; @@ -22,10 +20,14 @@ public class ProductDTO { return id; } - public String getName() { + public String getproductName() { return productName; } + public void setproductName(String productName) { + this.productName = productName; + } + public String getStoreName() { return storeName; } 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 8157137..5cf8566 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 @@ -23,10 +23,14 @@ public class StoreDTO { return id; } - public String getStoreName() { + public String getstoreName() { return storeName; } + public void setstoreName(String storeName) { + this.storeName = storeName; + } + public List getProducts() { return products; } diff --git a/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/MVC/OrderedMVCController.java b/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/MVC/OrderedMVCController.java new file mode 100644 index 0000000..10018f9 --- /dev/null +++ b/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/MVC/OrderedMVCController.java @@ -0,0 +1,65 @@ +package com.example.ipLab.StoreDataBase.MVC; + +import com.example.ipLab.StoreDataBase.DTO.CustomerDTO; +import com.example.ipLab.StoreDataBase.DTO.OrderedDTO; +import com.example.ipLab.StoreDataBase.DTO.ProductDTO; +import com.example.ipLab.StoreDataBase.Service.CustomerService; +import com.example.ipLab.StoreDataBase.Service.OrderService; +import com.example.ipLab.StoreDataBase.Service.ProductService; +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("/order") +public class OrderedMVCController { + private final OrderService orderedService; + private final ProductService productService; + private final CustomerService customerService; + + public OrderedMVCController(OrderService orderedService, ProductService productService, CustomerService customerService){ + this.productService = productService; + this.customerService = customerService; + this.orderedService = orderedService; + } + + @GetMapping + public String getOrdereds(Model model) { + model.addAttribute("orders", + orderedService.getAllOrders().stream() + .map(OrderedDTO::new) + .toList()); + return "order"; + } + + @GetMapping(value = {"/edit/", "/edit/{id}"}) + public String editOrdered(@PathVariable(required = false) Long id, + Model model) { + model.addAttribute("orderDTO", new OrderedDTO()); + model.addAttribute("customers", customerService.getAllCustomers().stream().map(CustomerDTO::new).toList()); + model.addAttribute("products", productService.getAllProductsWithStores().stream().map(ProductDTO::new).toList()); + return "order-edit"; + } + + @PostMapping(value = {"/", "/{id}"}) + public String saveOrdered(@RequestParam(value = "productId") Long productId, + @RequestParam(value = "customerId") Long customerId, + @ModelAttribute @Valid OrderedDTO orderedDto, + BindingResult bindingResult, + Model model) { + if (bindingResult.hasErrors()) { + model.addAttribute("errors", bindingResult.getAllErrors()); + return "ordered-edit"; + } + orderedService.addOrder(productService.getProduct(productId), customerService.getCustomer(customerId), orderedDto.getQuantity()); + return "redirect:/order"; + } + + @PostMapping("/delete/{id}") + public String deleteOrdered(@PathVariable Long id) { + orderedService.deleteOrder(id); + return "redirect:/order"; + } +} diff --git a/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/MVC/ProductMVCController.java b/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/MVC/ProductMVCController.java new file mode 100644 index 0000000..305ff2f --- /dev/null +++ b/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/MVC/ProductMVCController.java @@ -0,0 +1,63 @@ +package com.example.ipLab.StoreDataBase.MVC; + +import com.example.ipLab.StoreDataBase.DTO.ProductDTO; +import com.example.ipLab.StoreDataBase.Service.ProductService; +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("/product") +public class ProductMVCController { + private final ProductService productService; + + public ProductMVCController(ProductService productService) { + this.productService = productService; + } + + @GetMapping + public String getProducts(Model model) { + model.addAttribute("products", + productService.getAllProducts().stream() + .map(ProductDTO::new) + .toList()); + return "product"; + } + + @GetMapping(value = {"/edit/", "/edit/{id}"}) + public String editProduct(@PathVariable(required = false) Long id, + Model model) { + if (id == null || id <= 0) { + model.addAttribute("productDTO", new ProductDTO()); + } else { + model.addAttribute("productId", id); + model.addAttribute("productDTO", new ProductDTO(productService.getProduct(id))); + } + return "product-edit"; + } + + @PostMapping(value = {"/", "/{id}"}) + public String saveProduct(@PathVariable(required = false) Long id, + @ModelAttribute @Valid ProductDTO productDto, + BindingResult bindingResult, + Model model) { + if (bindingResult.hasErrors()) { + model.addAttribute("errors", bindingResult.getAllErrors()); + return "product-edit"; + } + if (id == null || id <= 0) { + productService.addProduct(productDto.getproductName()); + } else { + productService.updateProduct(id, productDto.getproductName()); + } + return "redirect:/product"; + } + + @PostMapping("/delete/{id}") + public String deleteProduct(@PathVariable Long id) { + productService.deleteProduct(id); + return "redirect:/product"; + } +} diff --git a/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/MVC/StoreMVCController.java b/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/MVC/StoreMVCController.java new file mode 100644 index 0000000..73554ad --- /dev/null +++ b/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/MVC/StoreMVCController.java @@ -0,0 +1,84 @@ +package com.example.ipLab.StoreDataBase.MVC; + +import com.example.ipLab.StoreDataBase.DTO.CustomerDTO; +import com.example.ipLab.StoreDataBase.DTO.ProductDTO; +import com.example.ipLab.StoreDataBase.DTO.StoreDTO; +import com.example.ipLab.StoreDataBase.Service.ProductService; +import com.example.ipLab.StoreDataBase.Service.StoreService; +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("/store") +public class StoreMVCController { + private final StoreService storeService; + private final ProductService productService; + + public StoreMVCController(StoreService storeService, ProductService productService) { + this.storeService = storeService; + this.productService = productService; + } + + @GetMapping + public String getStores(Model model) { + model.addAttribute("stores", + storeService.getAllStores().stream() + .map(StoreDTO::new) + .toList()); + return "store"; + } + + @GetMapping(value = {"/edit/", "/edit/{id}"}) + public String editStore(@PathVariable(required = false) Long id, + Model model) { + if (id == null || id <= 0) { + model.addAttribute("storeDTO", new StoreDTO()); + } else { + model.addAttribute("storeId", id); + model.addAttribute("storeDTO", new StoreDTO(storeService.getStore(id))); + } + return "store-edit"; + } + + @GetMapping(value = "/addToStore") + public String addToStore(@PathVariable(required = false) Long id, + Model model) { + model.addAttribute("stores", storeService.getAllStores().stream().map(StoreDTO::new).toList()); + model.addAttribute("products", productService.getAllProductsWithoutStores().stream().map(ProductDTO::new).toList()); + return "addToStore"; + } + + @PostMapping(value = {"/", "/{id}"}) + public String saveStore(@PathVariable(required = false) Long id, + @ModelAttribute @Valid StoreDTO storeDto, + BindingResult bindingResult, + Model model) { + if (bindingResult.hasErrors()) { + model.addAttribute("errors", bindingResult.getAllErrors()); + return "store-edit"; + } + if (id == null || id <= 0) { + storeService.addStore(storeDto.getstoreName()); + } else { + storeService.updateStore(id, storeDto.getstoreName()); + } + return "redirect:/store"; + } + + @PostMapping("/add") + public String addProduct(@RequestParam(value = "storeId") Long storeId, + @RequestParam(value = "productId") Long productId + ){ + storeService.addProduct(storeId, productId); + return "redirect:/product"; + } + + @PostMapping("/delete/{id}") + public String deleteStore(@PathVariable Long id) { + storeService.deleteStore(id); + return "redirect:/store"; + } +} diff --git a/backend/ipLab/src/main/resources/public/logo.png b/backend/ipLab/src/main/resources/public/logo.png new file mode 100644 index 0000000..f7c2e6e Binary files /dev/null and b/backend/ipLab/src/main/resources/public/logo.png differ diff --git a/backend/ipLab/src/main/resources/templates/addToStore.html b/backend/ipLab/src/main/resources/templates/addToStore.html new file mode 100644 index 0000000..720e9c1 --- /dev/null +++ b/backend/ipLab/src/main/resources/templates/addToStore.html @@ -0,0 +1,35 @@ + + + + + +
+
+
+
+ + +
+
+ + +
+
+ +
+
+
+ + \ 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 index c04f4cd..e56935f 100644 --- a/backend/ipLab/src/main/resources/templates/default.html +++ b/backend/ipLab/src/main/resources/templates/default.html @@ -21,10 +21,16 @@ aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation"> +
+ + * + +
+ boxStore +
+
diff --git a/backend/ipLab/src/main/resources/templates/order-edit.html b/backend/ipLab/src/main/resources/templates/order-edit.html new file mode 100644 index 0000000..e05a360 --- /dev/null +++ b/backend/ipLab/src/main/resources/templates/order-edit.html @@ -0,0 +1,42 @@ + + + + + +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + + Назад + +
+
+
+ + \ No newline at end of file diff --git a/backend/ipLab/src/main/resources/templates/order.html b/backend/ipLab/src/main/resources/templates/order.html new file mode 100644 index 0000000..0c14220 --- /dev/null +++ b/backend/ipLab/src/main/resources/templates/order.html @@ -0,0 +1,37 @@ + + + + + +
+
+ + Добавить + +
+
+ + + + + + + + + + + + + +
#ФИО покупателяМагазинТовар
+ + + +
+
+
+ + \ No newline at end of file diff --git a/backend/ipLab/src/main/resources/templates/product-edit.html b/backend/ipLab/src/main/resources/templates/product-edit.html new file mode 100644 index 0000000..d318452 --- /dev/null +++ b/backend/ipLab/src/main/resources/templates/product-edit.html @@ -0,0 +1,27 @@ + + + + + +
+
+
+
+ + +
+
+ + + Назад + +
+
+
+ + \ No newline at end of file diff --git a/backend/ipLab/src/main/resources/templates/product.html b/backend/ipLab/src/main/resources/templates/product.html new file mode 100644 index 0000000..3211ccb --- /dev/null +++ b/backend/ipLab/src/main/resources/templates/product.html @@ -0,0 +1,53 @@ + + + + + +
+
+ + Добавить + +
+
+ + + + + + + + + + + + + + +
#Название товараНазвание магазина
+ + + +
+ + Изменить + + +
+
+ +
+
+
+
+ + \ No newline at end of file diff --git a/backend/ipLab/src/main/resources/templates/store-edit.html b/backend/ipLab/src/main/resources/templates/store-edit.html new file mode 100644 index 0000000..a6d54a2 --- /dev/null +++ b/backend/ipLab/src/main/resources/templates/store-edit.html @@ -0,0 +1,27 @@ + + + + + +
+
+
+
+ + +
+
+ + + Назад + +
+
+
+ + \ No newline at end of file diff --git a/backend/ipLab/src/main/resources/templates/store.html b/backend/ipLab/src/main/resources/templates/store.html new file mode 100644 index 0000000..6d7f64a --- /dev/null +++ b/backend/ipLab/src/main/resources/templates/store.html @@ -0,0 +1,51 @@ + + + + + +
+
+ + Добавить + +
+
+ + + + + + + + + + + + + +
#Название магазина
+ + +
+ + Изменить + + +
+
+ +
+
+
+
+ + \ No newline at end of file diff --git a/frontend/src/services/DataService.js b/frontend/src/services/DataService.js index 7ed9068..6ce513c 100644 --- a/frontend/src/services/DataService.js +++ b/frontend/src/services/DataService.js @@ -17,6 +17,7 @@ export default class DataService { static async readAll(url, transformer) { const response = await axios.get(this.dataUrlPrefix + url); + console.log(response); return response.data.map(item => transformer(item)); }