- Timestamp:
- 01/05/23 01:31:58 (23 months ago)
- Branches:
- main
- Children:
- 676144b
- Parents:
- ab952ab
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/com/example/autopartz/controller/PartController.java
rab952ab r7d43957 1 1 package com.example.autopartz.controller; 2 2 3 import com.example.autopartz.model.Client; 4 import com.example.autopartz.model.Order; 3 5 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; 6 import com.example.autopartz.model.User; 7 import com.example.autopartz.model.manytomany.OrderContainsPart; 8 import com.example.autopartz.repository.OrderContainsPartRepository; 9 import com.example.autopartz.service.*; 7 10 import org.springframework.stereotype.Controller; 8 11 import org.springframework.ui.Model; 9 12 import org.springframework.web.bind.annotation.*; 10 13 14 import javax.servlet.http.HttpServletRequest; 11 15 import javax.servlet.http.HttpServletResponse; 16 import javax.servlet.http.HttpSession; 12 17 import java.io.IOException; 13 18 … … 18 23 private final RepairShopService repairShopService; 19 24 private final PriceService priceService; 20 public PartController(PartService partService, RepairShopService repairShopService, PriceService priceService) { 25 private final OrderService orderService; 26 private final UserService userService; 27 private final OrderContainsPartRepository orderContainsPartRepository; 28 public PartController(PartService partService, RepairShopService repairShopService, PriceService priceService, OrderService orderService, UserService userService, OrderContainsPartRepository orderContainsPartRepository) { 21 29 this.partService = partService; 22 30 this.repairShopService = repairShopService; 23 31 this.priceService = priceService; 32 this.orderService = orderService; 33 this.userService = userService; 34 this.orderContainsPartRepository = orderContainsPartRepository; 24 35 } 25 36 @GetMapping("/{id}") … … 32 43 return "master-template"; 33 44 } 34 @GetMapping("/delivery /{id}")35 public String getDeliveryPage( @PathVariable Integer id,Model model){45 @GetMapping("/delivery") 46 public String getDeliveryPage(Model model){ 36 47 model.addAttribute("repairShops",repairShopService.findAll()); 37 model.addAttribute("partId",id);38 48 model.addAttribute("bodyContent","deliveryForPart"); 39 49 return "master-template"; … … 57 67 } 58 68 } 69 @PostMapping("/addToOrder/{id}") 70 public void addToOrder(@PathVariable Integer id,@RequestParam Integer quantity, HttpSession session, HttpServletResponse response, HttpServletRequest request){ 71 if(session.getAttribute("order")==null){ 72 User u = userService.findByUsername(request.getRemoteUser()); 73 Order newOrder = orderService.create((Client) u); 74 session.setAttribute("order",newOrder); 75 } 76 Order order = (Order) session.getAttribute("order"); 77 orderContainsPartRepository.save(new OrderContainsPart(id,order.getID_order(),quantity)); 78 try { 79 response.sendRedirect("/products"); 80 } catch (IOException e) { 81 throw new RuntimeException(e); 82 } 83 } 59 84 }
Note:
See TracChangeset
for help on using the changeset viewer.