[feffc2f] | 1 | package com.example.autopartz.controller;
|
---|
| 2 |
|
---|
| 3 | import com.example.autopartz.model.Part;
|
---|
| 4 | import com.example.autopartz.service.PartService;
|
---|
| 5 | import com.example.autopartz.service.PriceService;
|
---|
| 6 | import com.example.autopartz.service.RepairShopService;
|
---|
| 7 | import org.springframework.stereotype.Controller;
|
---|
| 8 | import org.springframework.ui.Model;
|
---|
| 9 | import org.springframework.web.bind.annotation.*;
|
---|
| 10 |
|
---|
[ae042f4] | 11 | import javax.servlet.http.HttpServletResponse;
|
---|
[feffc2f] | 12 | import java.io.IOException;
|
---|
| 13 |
|
---|
| 14 | @Controller
|
---|
| 15 | @RequestMapping("/part")
|
---|
| 16 | public class PartController {
|
---|
| 17 | private final PartService partService;
|
---|
| 18 | private final RepairShopService repairShopService;
|
---|
| 19 | private final PriceService priceService;
|
---|
| 20 | public PartController(PartService partService, RepairShopService repairShopService, PriceService priceService) {
|
---|
| 21 | this.partService = partService;
|
---|
| 22 | this.repairShopService = repairShopService;
|
---|
| 23 | this.priceService = priceService;
|
---|
| 24 | }
|
---|
| 25 | @GetMapping("/{id}")
|
---|
[ae042f4] | 26 | public String getPartPage(@PathVariable Integer id, Model model){
|
---|
[feffc2f] | 27 | Part temp = partService.findById(id);
|
---|
| 28 | Integer amount = priceService.findPriceForPart(temp).stream().findFirst().orElseThrow(RuntimeException::new).getAmount();
|
---|
| 29 | model.addAttribute("part",temp);
|
---|
| 30 | model.addAttribute("amount",amount);
|
---|
[60de3eb] | 31 | model.addAttribute("bodyContent","partinfo");
|
---|
| 32 | return "master-template";
|
---|
[feffc2f] | 33 | }
|
---|
| 34 | @GetMapping("/delivery/{id}")
|
---|
[ae042f4] | 35 | public String getDeliveryPage(@PathVariable Integer id, Model model){
|
---|
[feffc2f] | 36 | model.addAttribute("repairShops",repairShopService.findAll());
|
---|
| 37 | model.addAttribute("partId",id);
|
---|
[60de3eb] | 38 | model.addAttribute("bodyContent","deliveryForPart");
|
---|
| 39 | return "master-template";
|
---|
[feffc2f] | 40 | }
|
---|
| 41 | @PostMapping("/repairshopdelivery")
|
---|
| 42 | public void setRepairShopDelivery(@RequestParam String name, HttpServletResponse response){
|
---|
| 43 | // insert into project.repair (vin, id_repair_shop, id_service_book) values (1111,3,1)
|
---|
| 44 | try {
|
---|
| 45 | response.sendRedirect("/");
|
---|
| 46 | } catch (IOException e) {
|
---|
| 47 | throw new RuntimeException(e);
|
---|
| 48 | }
|
---|
| 49 | }
|
---|
| 50 | @PostMapping("/homedelivery")
|
---|
| 51 | public void setHomeDelivery(@RequestParam String address, HttpServletResponse response){
|
---|
| 52 | // insert into delivery (delivery_status, delivery_address,id_user,id_order) values ('in progress','Aerodrom',4,1)
|
---|
| 53 | try {
|
---|
| 54 | response.sendRedirect("/");
|
---|
| 55 | } catch (IOException e) {
|
---|
| 56 | throw new RuntimeException(e);
|
---|
| 57 | }
|
---|
| 58 | }
|
---|
| 59 | }
|
---|