diff --git a/build.gradle b/build.gradle index 3900d89..05e0582 100644 --- a/build.gradle +++ b/build.gradle @@ -17,7 +17,14 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'com.h2database:h2:2.1.210' implementation group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.6.5' + implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' + testImplementation 'org.springframework.boot:spring-boot-starter-test' + implementation 'org.hibernate.validator:hibernate-validator' + 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/data.mv.db b/data.mv.db index 282eca2..af896e9 100644 Binary files a/data.mv.db and b/data.mv.db differ diff --git a/data.trace.db b/data.trace.db new file mode 100644 index 0000000..7f6abca --- /dev/null +++ b/data.trace.db @@ -0,0 +1,4 @@ +2023-05-02 12:16:50 jdbc[13]: exception +org.h2.jdbc.JdbcSQLSyntaxErrorException: Синтаксическая ошибка в выражении SQL "SELECT * FROM BUYER CAR [*]CARS_STORES" +Syntax error in SQL statement "SELECT * FROM BUYER CAR [*]CARS_STORES"; SQL statement: +SELECT * FROM BUYER CAR CARS_STORES [42000-210] diff --git a/src/main/java/ru/ulsru/is/lab1/Lab1Application.java b/src/main/java/ru/ulsru/is/lab1/Lab1Application.java index 2ccea24..e2536f5 100644 --- a/src/main/java/ru/ulsru/is/lab1/Lab1Application.java +++ b/src/main/java/ru/ulsru/is/lab1/Lab1Application.java @@ -5,7 +5,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.web.bind.annotation.RestController; @SpringBootApplication -@RestController public class Lab1Application { public static void main(String[] args) { diff --git a/src/main/java/ru/ulsru/is/lab1/WebConfiguration.java b/src/main/java/ru/ulsru/is/lab1/WebConfiguration.java index 2ce9c7b..ad9c023 100644 --- a/src/main/java/ru/ulsru/is/lab1/WebConfiguration.java +++ b/src/main/java/ru/ulsru/is/lab1/WebConfiguration.java @@ -9,20 +9,15 @@ 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("*"); } @Override public void addViewControllers(ViewControllerRegistry registry) { - ViewControllerRegistration registration = registry.addViewController("/notFound"); - registration.setViewName("forward:/index.html"); - registration.setStatusCode(HttpStatus.OK); + WebMvcConfigurer.super.addViewControllers(registry); + registry.addViewController("rest-test"); } -// @Bean -// public WebServerFactoryCustomizer containerCustomizer() { -// return container -> { -// container.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/notFound")); -// }; -// } } diff --git a/src/main/java/ru/ulsru/is/lab1/lab3/controller/BuyerController.java b/src/main/java/ru/ulsru/is/lab1/lab3/controller/BuyerController.java index af8296d..357f9a9 100644 --- a/src/main/java/ru/ulsru/is/lab1/lab3/controller/BuyerController.java +++ b/src/main/java/ru/ulsru/is/lab1/lab3/controller/BuyerController.java @@ -7,7 +7,7 @@ import javax.validation.Valid; import java.util.List; @RestController -@RequestMapping("/buyer") +@RequestMapping("(WebConfiguration.REST_API + /buyer") public class BuyerController { private final BuyerService buyerService; public BuyerController(BuyerService buyerService){ diff --git a/src/main/java/ru/ulsru/is/lab1/lab3/controller/BuyerDTO.java b/src/main/java/ru/ulsru/is/lab1/lab3/controller/BuyerDTO.java index db27b35..057ffdf 100644 --- a/src/main/java/ru/ulsru/is/lab1/lab3/controller/BuyerDTO.java +++ b/src/main/java/ru/ulsru/is/lab1/lab3/controller/BuyerDTO.java @@ -1,10 +1,15 @@ package ru.ulsru.is.lab1.lab3.controller; +import com.fasterxml.jackson.annotation.JsonProperty; import ru.ulsru.is.lab1.lab3.model.Buyer; +import javax.validation.constraints.NotBlank; + public class BuyerDTO { private long id; + @NotBlank(message = "buyerFirstName can't be null or empty") private String buyerFirstName; + @NotBlank(message = "buyerSecondName can't be null or empty") private String buyerSecondName; public BuyerDTO(Buyer buyer){ this.id =buyer.getId(); @@ -13,13 +18,20 @@ public class BuyerDTO { } public BuyerDTO(){ } + @JsonProperty(access = JsonProperty.Access.READ_ONLY) public long getId() { return id; } public String getBuyerFirstName(){ return buyerFirstName; } + public void setBuyerFirstName(String buyerFirstName){ + this.buyerFirstName = buyerFirstName; + } public String getBuyerSecondName(){ return buyerSecondName; } + public void setBuyerSecondName(String buyerSecondName){ + this.buyerSecondName = buyerSecondName; + } } diff --git a/src/main/java/ru/ulsru/is/lab1/lab3/controller/BuyerMVCController.java b/src/main/java/ru/ulsru/is/lab1/lab3/controller/BuyerMVCController.java new file mode 100644 index 0000000..af2697d --- /dev/null +++ b/src/main/java/ru/ulsru/is/lab1/lab3/controller/BuyerMVCController.java @@ -0,0 +1,59 @@ +package ru.ulsru.is.lab1.lab3.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.*; +import ru.ulsru.is.lab1.lab3.service.BuyerService; + +import javax.validation.Valid; + +@Controller +@RequestMapping("/buyer") +public class BuyerMVCController { + private final BuyerService buyerService; + public BuyerMVCController(BuyerService buyerService){ + this.buyerService = buyerService; + } + @GetMapping + public String getBuyers(Model model){ + model.addAttribute("buyers", + buyerService.findAllBuyers().stream() + .map(BuyerDTO::new) + .toList()); + return "buyer"; + } + + @GetMapping(value = {"/edit", "/edit/{id}"}) + public String editBuyer(@PathVariable(required = false) Long id, + Model model) { + if (id == null || id <= 0) { + model.addAttribute("BuyerDTO", new BuyerDTO()); + } else { + model.addAttribute("buyerId", id); + model.addAttribute("BuyerDTO", new BuyerDTO(buyerService.findBuyer(id))); + } + return "buyer-edit"; + } + @PostMapping(value = {"", "/{id}"}) + public String saveBuyer(@PathVariable(required = false) Long id, + @ModelAttribute @Valid BuyerDTO buyerDTO, + BindingResult bindingResult, + Model model) { + if (bindingResult.hasErrors()) { + model.addAttribute("errors", bindingResult.getAllErrors()); + return "buyer-edit"; + } + if (id == null || id <= 0) { + buyerService.addBuyer(buyerDTO); + } else { + buyerService.updateBuyer(id, buyerDTO); + } + return "redirect:/buyer"; + } + @PostMapping("/delete/{id}") + public String deleteBuyer(@PathVariable Long id) { + buyerService.deleteBuyer(id); + return "redirect:/buyer"; + } +} diff --git a/src/main/java/ru/ulsru/is/lab1/lab3/controller/CarController.java b/src/main/java/ru/ulsru/is/lab1/lab3/controller/CarController.java index 4546113..5a7ff7a 100644 --- a/src/main/java/ru/ulsru/is/lab1/lab3/controller/CarController.java +++ b/src/main/java/ru/ulsru/is/lab1/lab3/controller/CarController.java @@ -7,7 +7,7 @@ import javax.validation.Valid; import java.util.List; @RestController -@RequestMapping("/car") +@RequestMapping("WebConfiguration.REST_API + /car") public class CarController { private final CarService carService; public CarController(CarService carService){ diff --git a/src/main/java/ru/ulsru/is/lab1/lab3/controller/CarDTO.java b/src/main/java/ru/ulsru/is/lab1/lab3/controller/CarDTO.java index 63a6bd3..1b9a890 100644 --- a/src/main/java/ru/ulsru/is/lab1/lab3/controller/CarDTO.java +++ b/src/main/java/ru/ulsru/is/lab1/lab3/controller/CarDTO.java @@ -1,11 +1,14 @@ package ru.ulsru.is.lab1.lab3.controller; +import com.fasterxml.jackson.annotation.JsonProperty; import ru.ulsru.is.lab1.lab3.model.Car; +import javax.validation.constraints.NotBlank; import java.util.List; public class CarDTO { private long id; + @NotBlank(message = "carName can't be null or empty") private String carName; private List buyerDTOList; private List storeDTOList; @@ -23,6 +26,7 @@ public class CarDTO { .toList(); } public CarDTO(){} + @JsonProperty(access = JsonProperty.Access.READ_ONLY) public long getId() { return id; } @@ -32,6 +36,19 @@ public class CarDTO { public List getBuyerDTOList(){ return buyerDTOList; } + + public void setCarName(String carName) { + this.carName = carName; + } + + public void setBuyerDTOList(List buyerDTOList) { + this.buyerDTOList = buyerDTOList; + } + + public void setStoreDTOList(List storeDTOList) { + this.storeDTOList = storeDTOList; + } + public List getStoreDTOList(){ return storeDTOList; } diff --git a/src/main/java/ru/ulsru/is/lab1/lab3/controller/CarMVCController.java b/src/main/java/ru/ulsru/is/lab1/lab3/controller/CarMVCController.java new file mode 100644 index 0000000..fa93f1c --- /dev/null +++ b/src/main/java/ru/ulsru/is/lab1/lab3/controller/CarMVCController.java @@ -0,0 +1,119 @@ +package ru.ulsru.is.lab1.lab3.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.*; +import ru.ulsru.is.lab1.lab3.service.StoreService; +import ru.ulsru.is.lab1.lab3.service.BuyerService; +import ru.ulsru.is.lab1.lab3.service.CarService; + +import javax.validation.Valid; +import java.util.List; + +@Controller +@RequestMapping("/car") +public class CarMVCController { + private final CarService carService; + private final BuyerService buyerService; + private final StoreService storeService; + public CarMVCController(CarService carService, BuyerService buyerService, StoreService storeService){ + this.carService = carService; + this.buyerService = buyerService; + this.storeService = storeService; + } + @GetMapping + public String getCars(Model model){ + model.addAttribute("cars", + carService.findAllCars().stream() + .map(CarDTO::new) + .toList()); + return "car"; + } + @GetMapping(value = {"/edit", "/edit/{id}"}) + public String editCar(@PathVariable(required = false) Long id, + Model model) { + if (id == null || id <= 0) { + List buyers = buyerService.findAllBuyers().stream() + .map(BuyerDTO::new).toList(); + List stores = storeService.findAllStores().stream() + .map(StoreDTO::new).toList(); + model.addAttribute("CarDTO", new CarDTO()); + model.addAttribute("buyers", buyers); + model.addAttribute("stores", stores); + return "car-create"; + } else { + String name = carService.findCar(id).getCarName(); + List buyers = buyerService.findAllBuyers().stream() + .map(BuyerDTO::new).toList(); + List carBuyers = carService + .findCar(id) + .getBuyers() + .stream() + .map(BuyerDTO::new) + .toList(); + List stores = storeService.findAllStores().stream() + .map(StoreDTO::new).toList(); + List carStores = carService + .findCar(id) + .getStores() + .stream() + .map(StoreDTO::new) + .toList(); + model.addAttribute("name", name); + model.addAttribute("carId", id); + model.addAttribute("carBuyers", carBuyers); + model.addAttribute("buyers", buyers); + model.addAttribute("carStores", carStores); + model.addAttribute("stores", stores); + model.addAttribute("CarDTO", new CarDTO(carService.findCar(id))); + } + return "car-set"; + } + @PostMapping(value = {"/"}) + public String saveCar(@ModelAttribute @Valid CarDTO carDTO, + BindingResult bindingResult, + Model model) { + if (bindingResult.hasErrors()) { + model.addAttribute("errors", bindingResult.getAllErrors()); + return "car-create"; + } + carService.addCar(carDTO); +// } else { +// carService.updateCar(id, carDTO); +// } + return "redirect:/car"; + } + @PostMapping(value = {"/{id}"}) + public String editCar(@PathVariable Long id, + @RequestParam("PW") String PW, + @RequestParam("wpName") String name, + @RequestParam(value="idPW", required = false) Long idPW, + @RequestParam(value = "delete", required = false) boolean del, + Model model) { + if(PW.equals("N")){ + carService.findCar(id).setCarName(name); + carService.updateCar(id, new CarDTO(carService.findCar(id))); + } + if (PW.equals("W")){ + if (del == true) { + carService.deleteBuyer(id, idPW); + } else { + carService.addBuyer(id, idPW); + } + } + else if(PW.equals("P")){ + if (del == true) { + carService.deleteStore(id, idPW); + } else { + carService.addStore(id, idPW); + } + } + return "redirect:/car/edit/" + id; + } + @PostMapping("/delete/{id}") + public String deleteCar(@PathVariable Long id) { + carService.deleteCar(id); + return "redirect:/car"; + } +} diff --git a/src/main/java/ru/ulsru/is/lab1/lab3/controller/StoreController.java b/src/main/java/ru/ulsru/is/lab1/lab3/controller/StoreController.java index 881c654..b8b63c6 100644 --- a/src/main/java/ru/ulsru/is/lab1/lab3/controller/StoreController.java +++ b/src/main/java/ru/ulsru/is/lab1/lab3/controller/StoreController.java @@ -7,7 +7,7 @@ import javax.validation.Valid; import java.util.List; @RestController -@RequestMapping("/store") +@RequestMapping("WebConfiguration.REST_API + /store") public class StoreController { private final StoreService storeService; public StoreController(StoreService storeService){ diff --git a/src/main/java/ru/ulsru/is/lab1/lab3/controller/StoreDTO.java b/src/main/java/ru/ulsru/is/lab1/lab3/controller/StoreDTO.java index 020041c..91656e6 100644 --- a/src/main/java/ru/ulsru/is/lab1/lab3/controller/StoreDTO.java +++ b/src/main/java/ru/ulsru/is/lab1/lab3/controller/StoreDTO.java @@ -1,11 +1,14 @@ package ru.ulsru.is.lab1.lab3.controller; +import com.fasterxml.jackson.annotation.JsonProperty; import ru.ulsru.is.lab1.lab3.model.Store; +import javax.validation.constraints.NotBlank; import java.util.List; public class StoreDTO { private long id; + @NotBlank(message = "storeName can't be null or empty") private String storeName; private List carDTOList; public StoreDTO(Store store){ @@ -19,13 +22,16 @@ public class StoreDTO { } public StoreDTO() { } - + @JsonProperty(access = JsonProperty.Access.READ_ONLY) public long getId() { return id; } public String getStoreName() { return storeName; } + public void setStoreName(String storeName){ + this.storeName = storeName; + } public List getCarDTOList(){ return carDTOList; diff --git a/src/main/java/ru/ulsru/is/lab1/lab3/controller/StoreMVCController.java b/src/main/java/ru/ulsru/is/lab1/lab3/controller/StoreMVCController.java new file mode 100644 index 0000000..8b25830 --- /dev/null +++ b/src/main/java/ru/ulsru/is/lab1/lab3/controller/StoreMVCController.java @@ -0,0 +1,68 @@ +package ru.ulsru.is.lab1.lab3.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.*; +import ru.ulsru.is.lab1.lab3.service.StoreService; + +import javax.validation.Valid; + +@Controller +@RequestMapping("/store") +public class StoreMVCController { + private final StoreService storeService; + public StoreMVCController(StoreService storeService){ + this.storeService = storeService; + } + @GetMapping + public String getStores(Model model){ + model.addAttribute("stores", + storeService.findAllStores().stream() + .map(StoreDTO::new) + .toList()); + return "store"; + } + @GetMapping("/info/{id}") + public String findBuyersOnWorkplace(@PathVariable(required = false) Long id, Model model){ + model.addAttribute("cathegory", "Кто производит " + storeService.findStore(id).getStoreName()); + model.addAttribute("buyers", storeService.findAllBuyersProducedStore(id) + .stream() + .map(BuyerDTO::new) + .toList()); + model.addAttribute("page", "store"); + return "buyer-info"; + } + @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.findStore(id))); + } + return "store-edit"; + } + @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); + } else { + storeService.updateStore(id, storeDTO); + } + return "redirect:/store"; + } + @PostMapping("/delete/{id}") + public String deleteStore(@PathVariable Long id) { + storeService.deleteStore(id); + return "redirect:/store"; + } +} diff --git a/src/main/java/ru/ulsru/is/lab1/lab3/service/BuyerService.java b/src/main/java/ru/ulsru/is/lab1/lab3/service/BuyerService.java index da86cc1..ea41135 100644 --- a/src/main/java/ru/ulsru/is/lab1/lab3/service/BuyerService.java +++ b/src/main/java/ru/ulsru/is/lab1/lab3/service/BuyerService.java @@ -6,6 +6,7 @@ import ru.ulsru.is.lab1.lab3.Respository.IBuyerRespository; import ru.ulsru.is.lab1.lab3.controller.BuyerDTO; import ru.ulsru.is.lab1.lab3.controller.CarDTO; import ru.ulsru.is.lab1.lab3.model.Buyer; +import ru.ulsru.is.lab1.util.validation.ValidatorUtil; import java.util.List; import java.util.Optional; @@ -13,12 +14,15 @@ import java.util.Optional; @Service public class BuyerService { private final IBuyerRespository buyerRespository; - public BuyerService(IBuyerRespository buyerRespositroy){ + private final ValidatorUtil validatorUtil; + public BuyerService(IBuyerRespository buyerRespositroy, ValidatorUtil validatorUtil){ this.buyerRespository = buyerRespositroy; + this.validatorUtil = validatorUtil; } @Transactional public Buyer addBuyer(BuyerDTO buyerDTO) { final Buyer buyer = new Buyer(buyerDTO.getBuyerFirstName(), buyerDTO.getBuyerSecondName()); + validatorUtil.validate(buyer); buyerRespository.save(buyer); return buyer; } @@ -29,6 +33,9 @@ public class BuyerService { } @Transactional(readOnly = true) public List findAllBuyerByid(CarDTO carDTO) { + if(carDTO.getBuyerDTOList() == null){ + return null; + } return buyerRespository .findAllById(carDTO .getBuyerDTOList() @@ -48,6 +55,7 @@ public class BuyerService { final Buyer currentBuyer = findBuyer(id); currentBuyer.setBuyerFirstName(buyer.getBuyerFirstName()); currentBuyer.setBuyerSecondName(buyer.getBuyerSecondName()); + validatorUtil.validate(currentBuyer); buyerRespository.save(currentBuyer); return currentBuyer; } diff --git a/src/main/java/ru/ulsru/is/lab1/lab3/service/CarService.java b/src/main/java/ru/ulsru/is/lab1/lab3/service/CarService.java index 84f1d3c..4e095a9 100644 --- a/src/main/java/ru/ulsru/is/lab1/lab3/service/CarService.java +++ b/src/main/java/ru/ulsru/is/lab1/lab3/service/CarService.java @@ -37,15 +37,28 @@ public class CarService { return car; } @Transactional - public Car addBuyer(CarDTO carDTO, List buyers){ - final Car currentCar = findCar(carDTO.getId()); - currentCar.setBuyers(buyers); + public Car addBuyer(Long id, Long idW){ + final Car currentCar = findCar(id); + currentCar.addBuyer(buyerService.findBuyer(idW)); return currentCar; } @Transactional - public Car addStore(CarDTO carDTO, List stores){ - final Car currentCar = findCar(carDTO.getId()); - currentCar.setStores(stores); + public Car deleteBuyer(Long id, Long idW){ + final Car currentCar = findCar(id); + currentCar.removeBuyer(buyerService.findBuyer(idW)); + return currentCar; + } + @Transactional + public Car addStore(Long id, Long idP) { + final Car currentCar = findCar(id); + currentCar.addStore(storeService.findStore(idP)); + return currentCar; + } + + @Transactional + public Car deleteStore(Long id, Long idP){ + final Car currentCar = findCar(id); + currentCar.removeStore(storeService.findStore(idP)); return currentCar; } @Transactional(readOnly = true) diff --git a/src/main/java/ru/ulsru/is/lab1/lab3/service/StoreService.java b/src/main/java/ru/ulsru/is/lab1/lab3/service/StoreService.java index cd0818b..7d21b98 100644 --- a/src/main/java/ru/ulsru/is/lab1/lab3/service/StoreService.java +++ b/src/main/java/ru/ulsru/is/lab1/lab3/service/StoreService.java @@ -36,6 +36,9 @@ public class StoreService { } @Transactional(readOnly = true) public List findAllStoresById(CarDTO carDTO) { + if(carDTO.getStoreDTOList() == null){ + return null; + } return storeRespository .findAllById(carDTO .getStoreDTOList() diff --git a/src/main/java/ru/ulsru/is/lab1/util/error/AdviceController.java b/src/main/java/ru/ulsru/is/lab1/util/error/AdviceController.java index 5b920eb..e69de29 100644 --- a/src/main/java/ru/ulsru/is/lab1/util/error/AdviceController.java +++ b/src/main/java/ru/ulsru/is/lab1/util/error/AdviceController.java @@ -1,41 +0,0 @@ -//package ru.ulsru.is.lab1.util.error; -// -//import org.springframework.context.support.DefaultMessageSourceResolvable; -//import org.springframework.http.HttpStatus; -//import org.springframework.http.ResponseEntity; -//import org.springframework.web.bind.MethodArgumentNotValidException; -//import org.springframework.web.bind.annotation.ControllerAdvice; -//import org.springframework.web.bind.annotation.ExceptionHandler; -//import ru.ulsru.is.lab1.lab3.service.ProductNotFoundException; -//import ru.ulsru.is.lab1.lab3.service.WorkerNotFoundException; -//import ru.ulsru.is.lab1.lab3.service.WorkplaceNotFoundException; -//import ru.ulsru.is.lab1.util.validation.ValidationException; -//import java.util.stream.Collectors; -// -// @ControllerAdvice -// public class AdviceController { -// @ExceptionHandler({ -// WorkerNotFoundException.class, -// ProductNotFoundException.class, -// WorkplaceNotFoundException.class, -// ValidationException.class -// }) -// public ResponseEntity handleException(Throwable e) { -// return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST); -// } -// -// @ExceptionHandler(MethodArgumentNotValidException.class) -// public ResponseEntity handleBindException(MethodArgumentNotValidException e) { -// final ValidationException validationException = new ValidationException( -// e.getBindingResult().getAllErrors().stream() -// .map(DefaultMessageSourceResolvable::getDefaultMessage) -// .collect(Collectors.toSet())); -// return handleException(validationException); -// } -// -// @ExceptionHandler(Exception.class) -// public ResponseEntity handleUnknownException(Throwable e) { -// e.printStackTrace(); -// return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); -// } -// } diff --git a/src/main/java/ru/ulsru/is/lab1/util/validation/ValidationException.java b/src/main/java/ru/ulsru/is/lab1/util/validation/ValidationException.java index 6cd6d02..f5ef7e3 100644 --- a/src/main/java/ru/ulsru/is/lab1/util/validation/ValidationException.java +++ b/src/main/java/ru/ulsru/is/lab1/util/validation/ValidationException.java @@ -1,9 +1,9 @@ -//package ru.ulsru.is.lab1.util.validation; -// -//import java.util.Set; -// -//public class ValidationException extends RuntimeException { -// public ValidationException(Set errors) { -// super(String.join("\n", errors)); -// } -//} +package ru.ulsru.is.lab1.util.validation; + +import java.util.Set; + +public class ValidationException extends RuntimeException { + public ValidationException(Set errors) { + super(String.join("\n", errors)); + } +} \ No newline at end of file diff --git a/src/main/java/ru/ulsru/is/lab1/util/validation/ValidatorUtil.java b/src/main/java/ru/ulsru/is/lab1/util/validation/ValidatorUtil.java index d39229f..735bb53 100644 --- a/src/main/java/ru/ulsru/is/lab1/util/validation/ValidatorUtil.java +++ b/src/main/java/ru/ulsru/is/lab1/util/validation/ValidatorUtil.java @@ -1,30 +1,30 @@ -//package ru.ulsru.is.lab1.util.validation; -// -//import org.springframework.stereotype.Component; -// -//import javax.validation.ConstraintViolation; -//import javax.validation.Validation; -//import javax.validation.Validator; -//import javax.validation.ValidatorFactory; -//import java.util.Set; -//import java.util.stream.Collectors; -// -//@Component -//public class ValidatorUtil { -// private final Validator validator; -// -// public ValidatorUtil() { -// try (ValidatorFactory factory = Validation.buildDefaultValidatorFactory()) { -// this.validator = factory.getValidator(); -// } -// } -// -// public void validate(T object) { -// final Set> errors = validator.validate(object); -// if (!errors.isEmpty()) { -// throw new ValidationException(errors.stream() -// .map(ConstraintViolation::getMessage) -// .collect(Collectors.toSet())); -// } -// } -//} +package ru.ulsru.is.lab1.util.validation; + +import org.springframework.stereotype.Component; + +import javax.validation.ConstraintViolation; +import javax.validation.Validation; +import javax.validation.Validator; +import javax.validation.ValidatorFactory; +import java.util.Set; +import java.util.stream.Collectors; + +@Component +public class ValidatorUtil { + private final Validator validator; + + public ValidatorUtil() { + try (ValidatorFactory factory = Validation.buildDefaultValidatorFactory()) { + this.validator = factory.getValidator(); + } + } + + public void validate(T object) { + final Set> errors = validator.validate(object); + if (!errors.isEmpty()) { + throw new ValidationException(errors.stream() + .map(ConstraintViolation::getMessage) + .collect(Collectors.toSet())); + } + } +} \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 8c7476e..62a4c3f 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,6 +1,6 @@ spring.main.banner-mode=off server.port=8080 -server.tomcat.relaxed-query-chars=|,{,},[,] +#server.tomcat.relaxed-query-chars=|,{,},[,] spring.datasource.url=jdbc:h2:file:./data spring.datasource.driverClassName=org.h2.Driver spring.datasource.username=sa diff --git a/src/main/resources/static/css/style.css b/src/main/resources/static/css/style.css new file mode 100644 index 0000000..6ff5f08 --- /dev/null +++ b/src/main/resources/static/css/style.css @@ -0,0 +1,12 @@ + +.footer { + position: fixed; + left: 0; + bottom: 0; + width: 100%; + background-color: #f5f5f5; + color: #333; + text-align: center; + padding: 10px; +} + diff --git a/src/main/resources/templates/buyer-edit.html b/src/main/resources/templates/buyer-edit.html new file mode 100644 index 0000000..2848fd5 --- /dev/null +++ b/src/main/resources/templates/buyer-edit.html @@ -0,0 +1,34 @@ + + + + + +
+
+
+
+ + +
+
+ + +
+
+ + + Назад + +
+
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/buyer-info.html b/src/main/resources/templates/buyer-info.html new file mode 100644 index 0000000..d9deb02 --- /dev/null +++ b/src/main/resources/templates/buyer-info.html @@ -0,0 +1,35 @@ + + + + + +
+
+
+ + + + + + + + + + + + + + + + + +
#IDИмяФамилия
+
+ + Назад + +
+ + \ No newline at end of file diff --git a/src/main/resources/templates/buyer.html b/src/main/resources/templates/buyer.html new file mode 100644 index 0000000..c64ef36 --- /dev/null +++ b/src/main/resources/templates/buyer.html @@ -0,0 +1,55 @@ + + + + + +
+ +
+ + + + + + + + + + + + + + + + + + +
#IDИмяФамилия
+
+ + Изменить + + +
+
+ +
+
+
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/car-create.html b/src/main/resources/templates/car-create.html new file mode 100644 index 0000000..4a00d22 --- /dev/null +++ b/src/main/resources/templates/car-create.html @@ -0,0 +1,27 @@ + + + + + +
+
+
+
+ + +
+
+ + + Назад + +
+
+
+ + diff --git a/src/main/resources/templates/car-set.html b/src/main/resources/templates/car-set.html new file mode 100644 index 0000000..bc107e5 --- /dev/null +++ b/src/main/resources/templates/car-set.html @@ -0,0 +1,132 @@ + + + + + +
+
+
+
+ + + +
+ +
+ +
+
+
+
+
+ + +
+ + +
+
+ +
+
+ + + + + + + + + + + + + + + + + +
idИмяФамилия
+
+ + + +
+
+ +
+
+
+
+
+ + +
+ + +
+
+ + +
+
+ + + + + + + + + + + + + + + + +
idНазваниеЦена
+
+ + + +
+
+ +
+
+
+
+ +
+ + \ No newline at end of file diff --git a/src/main/resources/templates/car.html b/src/main/resources/templates/car.html new file mode 100644 index 0000000..e114859 --- /dev/null +++ b/src/main/resources/templates/car.html @@ -0,0 +1,53 @@ + + + + + +
+ +
+ + + + + + + + + + + + + + +
#IDНавание
+ + + +
+ + Изменить + + +
+
+ +
+
+
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/default.html b/src/main/resources/templates/default.html new file mode 100644 index 0000000..fe5959a --- /dev/null +++ b/src/main/resources/templates/default.html @@ -0,0 +1,38 @@ + + + + + Кашин Максим ПИбд-22 + + + + + + + + + +
+
+
+
+
+ Кашин Максим ПИбд-22 +
+ + \ No newline at end of file diff --git a/src/main/resources/templates/error.html b/src/main/resources/templates/error.html new file mode 100644 index 0000000..429c06e --- /dev/null +++ b/src/main/resources/templates/error.html @@ -0,0 +1,9 @@ + + + + + + + \ No newline at end of file diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html new file mode 100644 index 0000000..7ba7ccd --- /dev/null +++ b/src/main/resources/templates/index.html @@ -0,0 +1,9 @@ + + + + + + + \ No newline at end of file diff --git a/src/main/resources/templates/store-edit.html b/src/main/resources/templates/store-edit.html new file mode 100644 index 0000000..e2a3d29 --- /dev/null +++ b/src/main/resources/templates/store-edit.html @@ -0,0 +1,27 @@ + + + + + +
+
+
+
+ + +
+
+ + + Назад + +
+
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/store.html b/src/main/resources/templates/store.html new file mode 100644 index 0000000..833078a --- /dev/null +++ b/src/main/resources/templates/store.html @@ -0,0 +1,57 @@ + + + + + +
+ +
+ + + + + + + + + + + + + + + +
#IDНазваниеЦена
+ + +
+ + Инфо + + + Изменить + + +
+
+ +
+
+
+
+ + \ No newline at end of file