source: src/main/java/com/example/autopartz/controller/PartController.java@ 60de3eb

main
Last change on this file since 60de3eb was 60de3eb, checked in by andrejtodorovski <82031894+andrejtodorovski@…>, 18 months ago

Added master template and added filtering parts by car and category

  • Property mode set to 100644
File size: 2.4 KB
Line 
1package com.example.autopartz.controller;
2
3import com.example.autopartz.model.Part;
4import com.example.autopartz.service.PartService;
5import com.example.autopartz.service.PriceService;
6import com.example.autopartz.service.RepairShopService;
7import jakarta.servlet.http.HttpServletResponse;
8import org.springframework.stereotype.Controller;
9import org.springframework.ui.Model;
10import org.springframework.web.bind.annotation.*;
11
12import java.io.IOException;
13
14@Controller
15@RequestMapping("/part")
16public 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}")
26 public String getPartPage(@PathVariable Long id, Model model){
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);
31 model.addAttribute("bodyContent","partinfo");
32 return "master-template";
33 }
34 @GetMapping("/delivery/{id}")
35 public String getDeliveryPage(@PathVariable Long id, Model model){
36 model.addAttribute("repairShops",repairShopService.findAll());
37 model.addAttribute("partId",id);
38 model.addAttribute("bodyContent","deliveryForPart");
39 return "master-template";
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}
Note: See TracBrowser for help on using the repository browser.