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

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

Added some views and functionalities

  • Property mode set to 100644
File size: 2.3 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 return "partinfo";
32 }
33 @GetMapping("/delivery/{id}")
34 public String getDeliveryPage(@PathVariable Long id, Model model){
35 model.addAttribute("repairShops",repairShopService.findAll());
36 model.addAttribute("partId",id);
37 return "deliveryForPart";
38 }
39 @PostMapping("/repairshopdelivery")
40 public void setRepairShopDelivery(@RequestParam String name, HttpServletResponse response){
41 // insert into project.repair (vin, id_repair_shop, id_service_book) values (1111,3,1)
42 try {
43 response.sendRedirect("/");
44 } catch (IOException e) {
45 throw new RuntimeException(e);
46 }
47 }
48 @PostMapping("/homedelivery")
49 public void setHomeDelivery(@RequestParam String address, HttpServletResponse response){
50 // insert into delivery (delivery_status, delivery_address,id_user,id_order) values ('in progress','Aerodrom',4,1)
51 try {
52 response.sendRedirect("/");
53 } catch (IOException e) {
54 throw new RuntimeException(e);
55 }
56 }
57}
Note: See TracBrowser for help on using the repository browser.