Compare commits

...

3 Commits

37 changed files with 1177 additions and 83 deletions

View File

@ -1,6 +1,6 @@
plugins { plugins {
id 'java' 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' id 'io.spring.dependency-management' version '1.1.0'
} }
@ -23,6 +23,13 @@ dependencies {
testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'org.hibernate.validator:hibernate-validator' 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') { tasks.named('test') {

Binary file not shown.

View File

@ -3,12 +3,14 @@ package com.example.ipLab.StoreDataBase.Controllers;
import com.example.ipLab.StoreDataBase.DTO.CustomerDTO; import com.example.ipLab.StoreDataBase.DTO.CustomerDTO;
import com.example.ipLab.StoreDataBase.Model.Customer; import com.example.ipLab.StoreDataBase.Model.Customer;
import com.example.ipLab.StoreDataBase.Service.CustomerService; import com.example.ipLab.StoreDataBase.Service.CustomerService;
import com.example.ipLab.WebConfiguration;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.List;
@RestController @RestController
@RequestMapping("/customer") @RequestMapping(WebConfiguration.REST_API + "/customer")
public class CustomerController { public class CustomerController {
private final CustomerService customerService; private final CustomerService customerService;
@ -29,19 +31,15 @@ public class CustomerController {
} }
@PostMapping @PostMapping
public CustomerDTO createCustomer(@RequestParam("customerLastName") String customerLastName, public CustomerDTO createCustomer(@RequestBody @Valid CustomerDTO customerDTO){
@RequestParam("customerFirstName") String customerFirstName, final Customer customer = customerService.addCustomer(customerDTO.getlastName(), customerDTO.getfirstName(), customerDTO.getmiddleName());
@RequestParam("customerMiddleName") String customerMiddleName){
final Customer customer = customerService.addCustomer(customerLastName, customerFirstName, customerMiddleName);
return new CustomerDTO(customer); return new CustomerDTO(customer);
} }
@PutMapping("/{id}") @PutMapping("/{id}")
public CustomerDTO updateCustomer(@RequestParam("customerLastName") String customerLastName, public CustomerDTO updateCustomer(@RequestBody @Valid CustomerDTO customerDTO,
@RequestParam("customerFirstName") String customerFirstName,
@RequestParam("customerMiddleName") String customerMiddleName,
@PathVariable Long id){ @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}") @DeleteMapping("/{id}")

View File

@ -5,12 +5,14 @@ import com.example.ipLab.StoreDataBase.Model.Ordered;
import com.example.ipLab.StoreDataBase.Service.CustomerService; import com.example.ipLab.StoreDataBase.Service.CustomerService;
import com.example.ipLab.StoreDataBase.Service.OrderService; import com.example.ipLab.StoreDataBase.Service.OrderService;
import com.example.ipLab.StoreDataBase.Service.ProductService; import com.example.ipLab.StoreDataBase.Service.ProductService;
import com.example.ipLab.WebConfiguration;
import jakarta.validation.Valid;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.List;
@RestController @RestController
@RequestMapping("/order") @RequestMapping(WebConfiguration.REST_API + "/order")
public class OrderedController { public class OrderedController {
private final OrderService orderedService; private final OrderService orderedService;
private final ProductService productService; private final ProductService productService;
@ -35,17 +37,15 @@ public class OrderedController {
} }
@PostMapping @PostMapping
public OrderedDTO createOrdered(@RequestParam("productId") Long productId, public OrderedDTO createOrdered(@RequestBody @Valid OrderedDTO orderedDTO){
@RequestParam("customerId") Long customerId, final Ordered ordered = orderedService.addOrder(productService.getProduct(orderedDTO.getProductId()), customerService.getCustomer(orderedDTO.getCustomerId()), orderedDTO.quantity);
@RequestParam("quantity") Integer quantity){
final Ordered ordered = orderedService.addOrder(productService.getProduct(productId), customerService.getCustomer(customerId), quantity);
return new OrderedDTO(ordered); return new OrderedDTO(ordered);
} }
@PutMapping("/{id}") @PutMapping("/{id}")
public OrderedDTO updateOrdered(@RequestParam("quantity") Integer quantity, public OrderedDTO updateOrdered(@RequestBody @Valid OrderedDTO orderedDTO,
@PathVariable Long id){ @PathVariable Long id){
return new OrderedDTO(orderedService.updateOrder(id, quantity)); return new OrderedDTO(orderedService.updateOrder(id, orderedDTO.quantity));
} }
@DeleteMapping("/{id}") @DeleteMapping("/{id}")

View File

@ -3,12 +3,14 @@ package com.example.ipLab.StoreDataBase.Controllers;
import com.example.ipLab.StoreDataBase.DTO.ProductDTO; import com.example.ipLab.StoreDataBase.DTO.ProductDTO;
import com.example.ipLab.StoreDataBase.Model.Product; import com.example.ipLab.StoreDataBase.Model.Product;
import com.example.ipLab.StoreDataBase.Service.ProductService; import com.example.ipLab.StoreDataBase.Service.ProductService;
import com.example.ipLab.WebConfiguration;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.List;
@RestController @RestController
@RequestMapping("/product") @RequestMapping(WebConfiguration.REST_API + "/product")
public class ProductController { public class ProductController {
private final ProductService productService; private final ProductService productService;
@ -43,15 +45,15 @@ public class ProductController {
} }
@PostMapping @PostMapping
public ProductDTO createProduct(@RequestParam("productName") String productName){ public ProductDTO createProduct(@RequestBody @Valid ProductDTO productDTO){
final Product product = productService.addProduct(productName); final Product product = productService.addProduct(productDTO.getproductName());
return new ProductDTO(product); return new ProductDTO(product);
} }
@PutMapping("/{id}") @PutMapping("/{id}")
public ProductDTO updateProduct(@RequestParam("productName") String productName, public ProductDTO updateProduct(@RequestBody @Valid ProductDTO productDTO,
@PathVariable Long id){ @PathVariable Long id){
return new ProductDTO(productService.updateProduct(id, productName)); return new ProductDTO(productService.updateProduct(id, productDTO.getproductName()));
} }
@DeleteMapping("/{id}") @DeleteMapping("/{id}")

View File

@ -3,16 +3,16 @@ package com.example.ipLab.StoreDataBase.Controllers;
import com.example.ipLab.StoreDataBase.DTO.CustomerDTO; import com.example.ipLab.StoreDataBase.DTO.CustomerDTO;
import com.example.ipLab.StoreDataBase.DTO.ProductDTO; import com.example.ipLab.StoreDataBase.DTO.ProductDTO;
import com.example.ipLab.StoreDataBase.DTO.StoreDTO; 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.Model.Store;
import com.example.ipLab.StoreDataBase.Service.CustomerService;
import com.example.ipLab.StoreDataBase.Service.StoreService; import com.example.ipLab.StoreDataBase.Service.StoreService;
import com.example.ipLab.WebConfiguration;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.List;
@RestController @RestController
@RequestMapping("/store") @RequestMapping(WebConfiguration.REST_API + "/store")
public class StoreController { public class StoreController {
private final StoreService storeService; private final StoreService storeService;
@ -33,21 +33,21 @@ public class StoreController {
} }
@PostMapping @PostMapping
public StoreDTO createStore(@RequestParam("storeName") String storeName){ public StoreDTO createStore(@RequestBody @Valid StoreDTO storeDTO){
final Store store = storeService.addStore(storeName); final Store store = storeService.addStore(storeDTO.getstoreName());
return new StoreDTO(store); return new StoreDTO(store);
} }
@PutMapping("/{id}") @PutMapping("/{id}")
public StoreDTO updateStore(@RequestParam("storeName") String storeName, public StoreDTO updateStore(@RequestBody @Valid StoreDTO storeDTO,
@PathVariable Long id){ @PathVariable Long id){
return new StoreDTO(storeService.updateStore(id, storeName)); return new StoreDTO(storeService.updateStore(id, storeDTO.getstoreName()));
} }
@PutMapping("/add") @PutMapping("{id}/add")
public ProductDTO addProduct(@RequestParam("storeId") Long storeId, public ProductDTO addProduct(@PathVariable Long id,
@RequestParam("productId") Long productId){ @RequestBody @Valid CustomerDTO customerDTO){
return new ProductDTO(storeService.addProduct(storeId, productId)); return new ProductDTO(storeService.addProduct(id, customerDTO.getId()));
} }
@DeleteMapping("/{id}") @DeleteMapping("/{id}")

View File

@ -1,35 +1,60 @@
package com.example.ipLab.StoreDataBase.DTO; package com.example.ipLab.StoreDataBase.DTO;
import com.example.ipLab.StoreDataBase.Model.Customer; import com.example.ipLab.StoreDataBase.Model.Customer;
import jakarta.validation.constraints.NotBlank;
import java.util.List;
public class CustomerDTO { public class CustomerDTO {
public final Long id; public Long id;
public final String lastName; @NotBlank(message = "lastName can't be null or empty")
public final String firstName; public String lastName;
public final String middleName; @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 String customerFIO;
public CustomerDTO(){
}
public CustomerDTO(Customer customer){ public CustomerDTO(Customer customer){
this.id = customer.getId(); this.id = customer.getId();
this.lastName = customer.getLastName(); this.lastName = customer.getLastName();
this.firstName = customer.getFirstName(); this.firstName = customer.getFirstName();
this.middleName = customer.getMiddleName(); this.middleName = customer.getMiddleName();
this.customerFIO = lastName + " " + firstName + " " + middleName;
} }
public Long getId() { public Long getId() {
return id; return id;
} }
public void setId(Long id) {
public String getLastname() { this.id = id;
}
public String getlastName() {
return lastName; return lastName;
} }
public void setlastName(String lastName) {
public String getFirstname() { this.lastName = lastName;
}
public String getfirstName() {
return firstName; return firstName;
} }
public void setfirstName(String firstName) {
public String getMiddleName() { this.firstName = firstName;
}
public String getmiddleName() {
return middleName; return middleName;
} }
public void setmiddleName(String middleName) {
this.middleName = middleName;
}
public String getcustomerFIO() {
return customerFIO;
}
public void setcustomerFIO(String customerFIO) {
this.customerFIO = customerFIO;
}
} }

View File

@ -1,13 +1,21 @@
package com.example.ipLab.StoreDataBase.DTO; 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.Ordered;
import com.example.ipLab.StoreDataBase.Model.Product;
public class OrderedDTO { public class OrderedDTO {
public final Long id; public Long id;
public final int quantity; public int quantity;
public final String productName; public String productName;
public final String customerFIO; public String customerFIO;
public final String storeName; public String storeName;
public Long customerId;
public Long productId;
public OrderedDTO(){
}
public OrderedDTO(Ordered ordered){ public OrderedDTO(Ordered ordered){
this.id = ordered.getId(); this.id = ordered.getId();
@ -15,6 +23,8 @@ public class OrderedDTO {
this.productName = ordered.getProduct().getName(); this.productName = ordered.getProduct().getName();
this.storeName = ordered.getProduct().getStore().getStoreName(); this.storeName = ordered.getProduct().getStore().getStoreName();
this.customerFIO = ordered.getCustomer().getLastName() + " " + ordered.getCustomer().getFirstName() + " " + ordered.getCustomer().getMiddleName(); this.customerFIO = ordered.getCustomer().getLastName() + " " + ordered.getCustomer().getFirstName() + " " + ordered.getCustomer().getMiddleName();
this.customerId = ordered.getProduct().getId();
this.productId = ordered.getProduct().getId();
} }
public Long getId() { public Long getId() {
@ -25,15 +35,35 @@ public class OrderedDTO {
return quantity; return quantity;
} }
public String getProductName() { public String getproductName() {
return productName; return productName;
} }
public String getCustomerFIO() { public void setproductName(String productName) {
this.productName = productName;
}
public String getcustomerFIO() {
return customerFIO; return customerFIO;
} }
public String getStoreName() { public void setcustomerFIO(String customerFIO) {
this.customerFIO = customerFIO;
}
public String getstoreName() {
return storeName; return storeName;
} }
public void setstoreName(String storeName) {
this.storeName = storeName;
}
public Long getCustomerId() {
return customerId;
}
public Long getProductId() {
return productId;
}
} }

View File

@ -2,12 +2,13 @@ package com.example.ipLab.StoreDataBase.DTO;
import com.example.ipLab.StoreDataBase.Model.Product; import com.example.ipLab.StoreDataBase.Model.Product;
import java.util.List;
public class ProductDTO { public class ProductDTO {
public final Long id; public Long id;
public final String productName; public String productName;
public final String storeName; public String storeName;
public ProductDTO(){
}
public ProductDTO(Product product){ public ProductDTO(Product product){
this.id = product.getId(); this.id = product.getId();
@ -19,10 +20,14 @@ public class ProductDTO {
return id; return id;
} }
public String getName() { public String getproductName() {
return productName; return productName;
} }
public void setproductName(String productName) {
this.productName = productName;
}
public String getStoreName() { public String getStoreName() {
return storeName; return storeName;
} }

View File

@ -5,9 +5,13 @@ import com.example.ipLab.StoreDataBase.Model.Store;
import java.util.List; import java.util.List;
public class StoreDTO { public class StoreDTO {
public final Long id; public Long id;
public final String storeName; public String storeName;
public final List<ProductDTO> products; public List<ProductDTO> products;
public StoreDTO(){
}
public StoreDTO(Store store){ public StoreDTO(Store store){
this.id = store.getId(); this.id = store.getId();
@ -19,10 +23,14 @@ public class StoreDTO {
return id; return id;
} }
public String getStoreName() { public String getstoreName() {
return storeName; return storeName;
} }
public void setstoreName(String storeName) {
this.storeName = storeName;
}
public List<ProductDTO> getProducts() { public List<ProductDTO> getProducts() {
return products; return products;
} }

View File

@ -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";
}
}

View File

@ -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";
}
}

View File

@ -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";
}
}

View File

@ -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";
}
}

View File

@ -11,10 +11,11 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ControllerAdvice @ControllerAdvice(annotations = RestController.class)
public class AdviceController { public class AdviceController {
@ExceptionHandler({ @ExceptionHandler({
CustomerNotFoundException.class, CustomerNotFoundException.class,

View File

@ -6,6 +6,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration @Configuration
public class WebConfiguration implements WebMvcConfigurer { public class WebConfiguration implements WebMvcConfigurer {
public static final String REST_API = "/api";
@Override @Override
public void addCorsMappings(CorsRegistry registry){ public void addCorsMappings(CorsRegistry registry){
registry.addMapping("/**").allowedMethods("*"); registry.addMapping("/**").allowedMethods("*");

View File

@ -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;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.7 KiB

View File

@ -0,0 +1,35 @@
<!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 th:text="${errors}" class="margin-bottom alert-danger"></div>
<form action="#" th:action="@{/store/add}" method="post">
<div class="mb-3">
<label for="store" class="form-label">Покупатель</label>
<select id="store" class="form-select" th:name="storeId">
<option th:each="value: ${stores}" th:value="${value.id}" th:selected="${storeId} == ${value}">
<span th:text="${value.storeName}"></span>
</option>
</select>
</div>
<div class="mb-3">
<label for="product" class="form-label">Продукт</label>
<select id="product" class="form-select" th:name="productId">
<option th:each="value: ${products}" th:value="${value.id}" th:selected="${productId} == ${value}">
<span th:text="${value.productName}"></span>
</option>
</select>
</div>
<div class="mb-3">
<button type="submit" class="btn btn-primary button-fixed">
<span>Добавить</span>
</button>
</div>
</form>
</div>
</body>
</html>

View File

@ -0,0 +1,35 @@
<!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 th:text="${errors}" class="margin-bottom alert-danger"></div>
<form action="#" th:action="@{/customer/{id}(id=${id})}" th:object="${customerDTO}" method="post">
<div class="mb-3">
<label for="lastName" class="form-label">Фамилия</label>
<input type="text" class="form-control" id="lastName" th:field="${customerDTO.lastName}" required="true">
</div>
<div class="mb-3">
<label for="firstName" class="form-label">Имя</label>
<input type="text" class="form-control" id="firstName" th:field="${customerDTO.firstName}" required="true">
</div>
<div class="mb-3">
<label for="middleName" class="form-label">Отчество</label>
<input type="text" class="form-control" id="middleName" th:field="${customerDTO.middleName}" required="true">
</div>
<div class="mb-3">
<button type="submit" class="btn btn-primary button-fixed">
<span th:if="${id == null}">Добавить</span>
<span th:if="${id != null}">Обновить</span>
</button>
<a class="btn btn-secondary button-fixed" th:href="@{/customer}">
Назад
</a>
</div>
</form>
</div>
</body>
</html>

View File

@ -0,0 +1,55 @@
<!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="@{/customer/edit/}">
<i class="fa-solid fa-plus"></i> Добавить
</a>
</div>
<div class="table-responsive">
<table class="table table-success table-hover">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Фамилия</th>
<th scope="col">Имя</th>
<th scope="col">Отчество</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
<tr th:each="customer, iterator: ${customers}">
<th scope="row" th:text="${iterator.index} + 1"/>
<td th:text="${customer.lastName}"/>
<td th:text="${customer.firstName}"/>
<td th:text="${customer.middleName}"/>
<td style="width: 10%">
<div class="btn-group" role="group" aria-label="Basic example">
<a class="btn btn-warning button-fixed button-sm"
th:href="@{/customer/edit/{id}(id=${customer.id})}">
<i class="fa fa-pencil" aria-hidden="true"></i> Изменить
</a>
<button type="button" class="btn btn-danger button-fixed button-sm"
th:attr="onclick=|confirm('Удалить запись?') && document.getElementById('remove-${customer.id}').click()|">
<i class="fa fa-trash" aria-hidden="true"></i> Удалить
</button>
</div>
<form th:action="@{/customer/delete/{id}(id=${customer.id})}" method="post">
<button th:id="'remove-' + ${customer.id}" type="submit" style="display: none">
Удалить
</button>
</form>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>

View File

@ -0,0 +1,57 @@
<!DOCTYPE html>
<html lang="ru"
xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<head>
<meta charset="UTF-8"/>
<title>IP Example</title>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link rel="icon" href="/favicon.ico">
<script type="text/javascript" src="/webjars/bootstrap/5.1.3/js/bootstrap.bundle.min.js"></script>
<link rel="stylesheet" href="/webjars/bootstrap/5.1.3/css/bootstrap.min.css"/>
<link rel="stylesheet" href="/webjars/font-awesome/6.1.0/css/all.min.css"/>
<link rel="stylesheet" href="/css/styleSite.css"/>
</head>
<body>
<header>
<div class="d-flex flex-row headerContainer">
<nav class="navbar navbar-expand-md">
<div class="container-fluid" id="navigationMenu">
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="d-flex flex-row ml-3 ms-3 mt-auto mb-auto align-items-center">
<a>
<img src="/logo.png" alt="*" width="60" height="60" class="align-text-top"></img>
</a>
<div id="logoName">
<a href="/">boxStore</a>
</div>
</div>
<div class="navbar-collapse collapse justify-content-end" id="navbarNav">
<ul class="navbar-nav" id="headerNavigation">
<a class="nav-link headNav" href="/customer"
th:classappend="${#strings.equals(activeLink, '/customer')} ? 'active' : ''">Клиенты</a>
<a class="nav-link headNav" href="/store"
th:classappend="${#strings.equals(activeLink, '/store')} ? 'active' : ''">Магазины</a>
<a class="nav-link headNav" href="/product"
th:classappend="${#strings.equals(activeLink, '/product')} ? 'active' : ''">Товары</a>
<a class="nav-link headNav" href="/order"
th:classappend="${#strings.equals(activeLink, '/order')} ? 'active' : ''">Заказы</a>
<a class="nav-link headNav" href="/store/addToStore"
th:classappend="${#strings.equals(activeLink, '/order')} ? 'active' : ''">Доставка</a>
</ul>
</div>
</div>
</nav>
</div>
</header>
<div class="container-fluid">
<div class="container container-padding" layout:fragment="content">
</div>
</div>
</body>
<th:block layout:fragment="scripts">
</th:block>
</html>

View File

@ -0,0 +1,13 @@
<!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><span th:text="${error}"></span></div>
<a href="/">На главную</a>
</div>
</body>
</html>

View File

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{default}">
<head>
</head>
<body>
<div layout:fragment="content">
<h2>Добро пожаловать!</h2>
</div>
</body>
</html>

View File

@ -0,0 +1,42 @@
<!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 th:text="${errors}" class="margin-bottom alert-danger"></div>
<form action="#" th:action="@{/order/}" th:object="${orderDTO}" method="post">
<div class="mb-3">
<label for="customer" class="form-label">Покупатель</label>
<select id="customer" class="form-select" th:name="customerId">
<option th:each="value: ${customers}" th:value="${value.id}" th:selected="${customerId} == ${value}">
<span th:text="${value.customerFIO}"></span>
</option>
</select>
</div>
<div class="mb-3">
<label for="product" class="form-label">Продукт</label>
<select id="product" class="form-select" th:name="productId">
<option th:each="value: ${products}" th:value="${value.id}" th:selected="${productId} == ${value}">
<span th:text="${value.productName}"></span>
</option>
</select>
</div>
<div class="mb-3">
<label for="quantity" class="form-label">Количество</label>
<input type="text" class="form-control" id="quantity" th:field="${orderDTO.quantity}" required="true">
</div>
<div class="mb-3">
<button type="submit" class="btn btn-primary button-fixed">
<span>Добавить</span>
</button>
<a class="btn btn-secondary button-fixed" th:href="@{/order}">
Назад
</a>
</div>
</form>
</div>
</body>
</html>

View File

@ -0,0 +1,37 @@
<!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/edit/}">
<i class="fa-solid fa-plus"></i> Добавить
</a>
</div>
<div class="table-responsive">
<table class="table table-success table-hover">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">ФИО покупателя</th>
<th scope="col">Магазин</th>
<th scope="col">Товар</th>
</tr>
</thead>
<tbody>
<tr th:each="order, iterator: ${orders}">
<th scope="row" th:text="${iterator.index} + 1"/>
<td th:text="${order.customerFIO}"/>
<td th:text="${order.storeName}"/>
<td th:text="${order.productName}"/>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>

View File

@ -0,0 +1,27 @@
<!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 th:text="${errors}" class="margin-bottom alert-danger"></div>
<form action="#" th:action="@{/product/{id}(id=${id})}" th:object="${productDTO}" method="post">
<div class="mb-3">
<label for="productName" class="form-label">Название товара</label>
<input type="text" class="form-control" id="productName" th:field="${productDTO.productName}" required="true">
</div>
<div class="mb-3">
<button type="submit" class="btn btn-primary button-fixed">
<span th:if="${id == null}">Добавить</span>
<span th:if="${id != null}">Обновить</span>
</button>
<a class="btn btn-secondary button-fixed" th:href="@{/product}">
Назад
</a>
</div>
</form>
</div>
</body>
</html>

View File

@ -0,0 +1,53 @@
<!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="@{/product/edit/}">
<i class="fa-solid fa-plus"></i> Добавить
</a>
</div>
<div class="table-responsive">
<table class="table table-success table-hover">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Название товара</th>
<th scope="col">Название магазина</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
<tr th:each="product, iterator: ${products}">
<th scope="row" th:text="${iterator.index} + 1"/>
<td th:text="${product.productName}"/>
<td th:text="${product.storeName}"/>
<td style="width: 10%">
<div class="btn-group" role="group" aria-label="Basic example">
<a class="btn btn-warning button-fixed button-sm"
th:href="@{/product/edit/{id}(id=${product.id})}">
<i class="fa fa-pencil" aria-hidden="true"></i> Изменить
</a>
<button type="button" class="btn btn-danger button-fixed button-sm"
th:attr="onclick=|confirm('Удалить запись?') && document.getElementById('remove-${product.id}').click()|">
<i class="fa fa-trash" aria-hidden="true"></i> Удалить
</button>
</div>
<form th:action="@{/product/delete/{id}(id=${product.id})}" method="post">
<button th:id="'remove-' + ${product.id}" type="submit" style="display: none">
Удалить
</button>
</form>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>

View File

@ -0,0 +1,27 @@
<!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 th:text="${errors}" class="margin-bottom alert-danger"></div>
<form action="#" th:action="@{/store/{id}(id=${id})}" th:object="${storeDTO}" method="post">
<div class="mb-3">
<label for="storeName" class="form-label">Название магазина</label>
<input type="text" class="form-control" id="storeName" th:field="${storeDTO.storeName}" required="true">
</div>
<div class="mb-3">
<button type="submit" class="btn btn-primary button-fixed">
<span th:if="${id == null}">Добавить</span>
<span th:if="${id != null}">Обновить</span>
</button>
<a class="btn btn-secondary button-fixed" th:href="@{/store}">
Назад
</a>
</div>
</form>
</div>
</body>
</html>

View File

@ -0,0 +1,51 @@
<!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="@{/store/edit/}">
<i class="fa-solid fa-plus"></i> Добавить
</a>
</div>
<div class="table-responsive">
<table class="table table-success table-hover">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Название магазина</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
<tr th:each="store, iterator: ${stores}">
<th scope="row" th:text="${iterator.index} + 1"/>
<td th:text="${store.storeName}"/>
<td style="width: 10%">
<div class="btn-group" role="group" aria-label="Basic example">
<a class="btn btn-warning button-fixed button-sm"
th:href="@{/store/edit/{id}(id=${store.id})}">
<i class="fa fa-pencil" aria-hidden="true"></i> Изменить
</a>
<button type="button" class="btn btn-danger button-fixed button-sm"
th:attr="onclick=|confirm('Удалить запись?') && document.getElementById('remove-${store.id}').click()|">
<i class="fa fa-trash" aria-hidden="true"></i> Удалить
</button>
</div>
<form th:action="@{/store/delete/{id}(id=${store.id})}" method="post">
<button th:id="'remove-' + ${store.id}" type="submit" style="display: none">
Удалить
</button>
</form>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>

View File

@ -23,14 +23,15 @@ export default function CustomerTable(props){
} }
function saveItem() { function saveItem() {
let customer = {
lastName: props.data.lastName,
firstName: props.data.firstName,
middleName: props.data.middleName
}
if (!isEdit) { if (!isEdit) {
DataService.create(props.url, "?customerLastName=" + props.data.lastName DataService.create(props.url, customer).then(() => loadItems());
+ "&customerFirstName=" + props.data.firstName
+ "&customerMiddleName=" + props.data.middleName).then(() => loadItems());
} else { } else {
DataService.update(props.getUrl + props.data.id, "?customerLastName=" + props.data.lastName DataService.update(props.getUrl + props.data.id, customer).then(() => loadItems());
+ "&customerFirstName=" + props.data.firstName
+ "&customerMiddleName=" + props.data.middleName).then(() => loadItems());
} }
} }

View File

@ -28,10 +28,15 @@ export default function CustomerTable(props){
} }
function saveItem() { function saveItem() {
let ordered = {
productId: props.data.productId,
customerId: props.data.customerId,
quantity: props.data.quantity
}
if (!isEdit) { 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 { } 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());
} }
} }

View File

@ -23,10 +23,13 @@ export default function CustomerTable(props){
} }
function saveItem() { function saveItem() {
let product = {
productName: props.data.productName
}
if (!isEdit) { if (!isEdit) {
DataService.create(props.url, "?productName=" + props.data.productName).then(() => loadItems()); DataService.create(props.url, product).then(() => loadItems());
} else { } else {
DataService.update(props.getUrl + props.data.id, "?productName=" + props.data.productName).then(() => loadItems()); DataService.update(props.getUrl + props.data.id, product).then(() => loadItems());
} }
} }

View File

@ -23,10 +23,13 @@ export default function CustomerTable(props){
} }
function saveItem() { function saveItem() {
let store = {
storeName: props.data.storeName
}
if (!isEdit) { if (!isEdit) {
DataService.create(props.url, "?storeName=" + props.data.storeName).then(() => loadItems()); DataService.create(props.url, store).then(() => loadItems());
} else { } else {
DataService.update(props.getUrl + props.data.id, "?storeName=" + props.data.storeName).then(() => loadItems()); DataService.update(props.getUrl + props.data.id, store).then(() => loadItems());
} }
} }

View File

@ -6,7 +6,7 @@ import { useState, useEffect} from "react";
export default function AddToStorePage(){ export default function AddToStorePage(){
const getStoreUrl = 'store'; const getStoreUrl = 'store';
const getProductUrl = 'product/getWithoutStores' const getProductUrl = 'product/getWithoutStores'
const url = 'store/add' const url = 'store/'
const [storeOptions, setStoreOptions] = useState([]) const [storeOptions, setStoreOptions] = useState([])
const [productOptions, setProductOptions] = useState([]) const [productOptions, setProductOptions] = useState([])
const transformerProduct = (data) => new Product(data); const transformerProduct = (data) => new Product(data);
@ -44,8 +44,10 @@ export default function AddToStorePage(){
function add(){ function add(){
var storeId = document.getElementById("storeId").value; var storeId = document.getElementById("storeId").value;
var productId = document.getElementById("productId").value; var productId = document.getElementById("productId").value;
let product = {
DataService.update(url, "?storeId=" + storeId + "&productId=" + productId); id: productId
}
DataService.update(url + storeId + "/add", product);
window.location.replace("/product"); window.location.replace("/product");
} }

View File

@ -13,10 +13,11 @@ function toJSON(data) {
} }
export default class DataService { export default class DataService {
static dataUrlPrefix = 'http://localhost:8080/'; static dataUrlPrefix = 'http://localhost:8080/api/';
static async readAll(url, transformer) { static async readAll(url, transformer) {
const response = await axios.get(this.dataUrlPrefix + url); const response = await axios.get(this.dataUrlPrefix + url);
console.log(response);
return response.data.map(item => transformer(item)); return response.data.map(item => transformer(item));
} }
@ -26,13 +27,12 @@ export default class DataService {
} }
static async create(url, data) { 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; return true;
} }
static async update(url, data) { 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; return true;
} }