diff --git a/pom.xml b/pom.xml index 05e4d63..8011301 100644 --- a/pom.xml +++ b/pom.xml @@ -68,18 +68,28 @@ org.webjars bootstrap - 3.4.0 + 4.3.1 + + + org.webjars + bootstrap-datetimepicker + 2.4.2 org.webjars jquery - 3.3.1 + 3.4.0 org.webjars jQuery-Autocomplete 1.4.9 + + org.webjars + font-awesome + 5.8.1 + diff --git a/src/main/java/com/github/prominence/carrepair/controller/OrderController.java b/src/main/java/com/github/prominence/carrepair/controller/OrderController.java index a6aac95..a70888d 100644 --- a/src/main/java/com/github/prominence/carrepair/controller/OrderController.java +++ b/src/main/java/com/github/prominence/carrepair/controller/OrderController.java @@ -14,9 +14,9 @@ import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.ui.ModelMap; import org.springframework.validation.BindingResult; +import org.springframework.validation.SmartValidator; import org.springframework.web.bind.annotation.*; -import javax.validation.Valid; import java.util.Optional; @Controller @@ -26,17 +26,18 @@ public class OrderController { private OrderService orderService; private ClientService clientService; private MechanicService mechanicService; + private SmartValidator smartValidator; - public OrderController(OrderService orderService, ClientService clientService, MechanicService mechanicService) { + public OrderController(OrderService orderService, ClientService clientService, MechanicService mechanicService, SmartValidator smartValidator) { this.orderService = orderService; this.clientService = clientService; this.mechanicService = mechanicService; + this.smartValidator = smartValidator; } @GetMapping public String index(@PageableDefault Pageable pageable, @RequestParam(required = false) String client, @RequestParam(required = false) String description, @RequestParam(required = false) OrderStatus orderStatus, ModelMap modelMap) { - Page orderList = orderService.findAll(OrderSpecifications.search(client, description, orderStatus), pageable); modelMap.addAttribute("orderList", orderList.getContent()); @@ -61,8 +62,6 @@ public class OrderController { Optional orderOptional = orderService.findById(id); if (orderOptional.isPresent()) { model.addAttribute("order", orderOptional.get()); - model.addAttribute("clientIdsList", clientService.getAllClientIds()); - model.addAttribute("mechanicIdsList", mechanicService.getAllMechanicIds()); model.addAttribute("orderStatuses", OrderStatus.values()); return "order/edit"; } else { @@ -72,11 +71,16 @@ public class OrderController { } @PostMapping(value = "/update/{id}") - public String update(@Valid Order order, BindingResult bindingResult, @PathVariable long id, Model model) { + public String update(Order order, BindingResult bindingResult, @PathVariable long id, Long clientId, Long mechanicId, Model model) { + if (clientId != null) { + clientService.findById(clientId).ifPresent(order::setClient); + } + if (mechanicId != null) { + mechanicService.findById(mechanicId).ifPresent(order::setMechanic); + } + smartValidator.validate(order, bindingResult); if (bindingResult.hasErrors()) { order.setId(id); // why should we do this? - model.addAttribute("clientIdsList", clientService.getAllClientIds()); - model.addAttribute("mechanicIdsList", mechanicService.getAllMechanicIds()); model.addAttribute("orderStatuses", OrderStatus.values()); return "order/edit"; } @@ -86,10 +90,15 @@ public class OrderController { } @PostMapping(value = "/create") - public String save(@Valid Order order, BindingResult bindingResult, Model model) { + public String save(Order order, BindingResult bindingResult, Long clientId, Long mechanicId, Model model) { + if (clientId != null) { + clientService.findById(clientId).ifPresent(order::setClient); + } + if (mechanicId != null) { + mechanicService.findById(mechanicId).ifPresent(order::setMechanic); + } + smartValidator.validate(order, bindingResult); if (bindingResult.hasErrors()) { - model.addAttribute("clientIdsList", clientService.getAllClientIds()); - model.addAttribute("mechanicIdsList", mechanicService.getAllMechanicIds()); model.addAttribute("orderStatuses", OrderStatus.values()); return "order/edit"; } diff --git a/src/main/java/com/github/prominence/carrepair/model/Order.java b/src/main/java/com/github/prominence/carrepair/model/Order.java index a352c9d..111cfb5 100644 --- a/src/main/java/com/github/prominence/carrepair/model/Order.java +++ b/src/main/java/com/github/prominence/carrepair/model/Order.java @@ -16,16 +16,18 @@ public class Order { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - private long id; + private Long id; @NotNull @Size(max = 1024) private String description; + @NotNull @ManyToOne(fetch = FetchType.EAGER) // change to LAZY after DTO implementation @JoinColumn(name = "client_id", nullable = false) private Client client; + @NotNull @ManyToOne(fetch = FetchType.EAGER) // change to LAZY after DTO implementation @JoinColumn(name = "mechanic_id", nullable = false) private Mechanic mechanic; @@ -58,11 +60,11 @@ public class Order { public Order() { } - public long getId() { + public Long getId() { return id; } - public void setId(long id) { + public void setId(Long id) { this.id = id; } diff --git a/src/main/java/com/github/prominence/carrepair/model/Person.java b/src/main/java/com/github/prominence/carrepair/model/Person.java index d877caa..1d79e37 100644 --- a/src/main/java/com/github/prominence/carrepair/model/Person.java +++ b/src/main/java/com/github/prominence/carrepair/model/Person.java @@ -10,7 +10,7 @@ abstract public class Person { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - protected long id; + protected Long id; @NotNull @Size(max = 64) diff --git a/src/main/resources/static/css/main.css b/src/main/resources/static/css/main.css index d684996..a8e5f3e 100644 --- a/src/main/resources/static/css/main.css +++ b/src/main/resources/static/css/main.css @@ -1,18 +1,7 @@ -body { -} - -.fieldError { - border: 1px solid red; -} - .word-breakable { word-break: break-all; } -.btn-group { - display: flex; -} - .autocomplete-suggestions { border: 1px solid #999; background: #FFF; overflow: auto; } .autocomplete-suggestion { padding: 2px 5px; white-space: nowrap; overflow: hidden; } .autocomplete-selected { background: #F0F0F0; } diff --git a/src/main/resources/templates/client/edit.html b/src/main/resources/templates/client/edit.html index 38b92fd..8ab2f2a 100644 --- a/src/main/resources/templates/client/edit.html +++ b/src/main/resources/templates/client/edit.html @@ -5,41 +5,42 @@ -
+

- +
+
- +
- +
- +
- +
-
+
- +
diff --git a/src/main/resources/templates/client/index.html b/src/main/resources/templates/client/index.html index cf31b2b..19c32ef 100644 --- a/src/main/resources/templates/client/index.html +++ b/src/main/resources/templates/client/index.html @@ -22,10 +22,11 @@ -
+

- -
+
+
+
@@ -47,7 +48,7 @@
- +
diff --git a/src/main/resources/templates/common.html b/src/main/resources/templates/common.html index 3bbf210..7ab9cda 100644 --- a/src/main/resources/templates/common.html +++ b/src/main/resources/templates/common.html @@ -3,23 +3,23 @@ xmlns:th="http://www.thymeleaf.org">
-
-
+
-
+ diff --git a/src/main/resources/templates/home.html b/src/main/resources/templates/home.html index c7bfc3c..552998b 100644 --- a/src/main/resources/templates/home.html +++ b/src/main/resources/templates/home.html @@ -5,8 +5,10 @@ -
+

Car Repair test project

+
+

:

diff --git a/src/main/resources/templates/main.html b/src/main/resources/templates/main.html index e669dfa..daaaad2 100644 --- a/src/main/resources/templates/main.html +++ b/src/main/resources/templates/main.html @@ -7,52 +7,60 @@ " - + + -