Changeset 2a552fe for src/main/java/com/example/autopartz/controller
- Timestamp:
- 07/26/23 19:26:35 (16 months ago)
- Branches:
- main
- Parents:
- e02787e
- Location:
- src/main/java/com/example/autopartz/controller
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/com/example/autopartz/controller/AdminController.java
re02787e r2a552fe 2 2 3 3 import com.example.autopartz.model.*; 4 import com.example.autopartz.model.manytomany.PartIsAppropriateForCar;5 import com.example.autopartz.model.manytomany.PartIsFromCategory;6 import com.example.autopartz.model.manytomany.PartIsInStockInWarehouse;7 import com.example.autopartz.model.manytomany.RsForCm;8 4 import com.example.autopartz.repository.*; 9 import com.example.autopartz.service.PriceService; 5 import com.example.autopartz.service.PartService; 6 import com.example.autopartz.service.RepairShopService; 10 7 import com.example.autopartz.service.UserService; 11 8 import org.springframework.stereotype.Controller; … … 24 21 private final UserService userService; 25 22 private final CarManufacturerRepository carManufacturerRepository; 26 private final PartIsFromCategoryRepository partIsFromCategoryRepository;27 private final PartIsAppropriateForCarRepository partIsAppropriateForCarRepository;28 23 private final WarehousemanRepository warehousemanRepository; 29 private final PartIsInStockInWarehouseRepository partIsInStockInWarehouseRepository;30 24 private final DeliverymanRepository deliverymanRepository; 31 25 private final CategoryRepository categoryRepository; 32 private final PartRepository partRepository;33 26 private final WarehouseRepository warehouseRepository; 34 27 private final CarRepository carRepository; 35 28 private final PartManufacturerRepository partManufacturerRepository; 36 private final PriceService priceService; 37 private final RepairShopRepository repairShopRepository; 38 private final RsForCmRepository rsForCmRepository; 29 private final PartService partService; 30 private final RepairShopService repairShopService; 39 31 40 public AdminController(UserService userService, CarManufacturerRepository carManufacturerRepository, PartIsFromCategoryRepository partIsFromCategoryRepository, PartIsAppropriateForCarRepository partIsAppropriateForCarRepository, WarehousemanRepository warehousemanRepository, PartIsInStockInWarehouseRepository partIsInStockInWarehouseRepository, DeliverymanRepository deliverymanRepository, CategoryRepository categoryRepository, PartRepository partRepository, WarehouseRepository warehouseRepository, CarRepository carRepository, PartManufacturerRepository partManufacturerRepository, PriceService priceService, RepairShopRepository repairShopRepository, RsForCmRepository rsForCmRepository) {32 public AdminController(UserService userService, CarManufacturerRepository carManufacturerRepository, WarehousemanRepository warehousemanRepository, DeliverymanRepository deliverymanRepository, CategoryRepository categoryRepository, WarehouseRepository warehouseRepository, CarRepository carRepository, PartManufacturerRepository partManufacturerRepository, PartService partService, RepairShopService repairShopService) { 41 33 this.userService = userService; 42 34 this.carManufacturerRepository = carManufacturerRepository; 43 this.partIsFromCategoryRepository = partIsFromCategoryRepository;44 this.partIsAppropriateForCarRepository = partIsAppropriateForCarRepository;45 35 this.warehousemanRepository = warehousemanRepository; 46 this.partIsInStockInWarehouseRepository = partIsInStockInWarehouseRepository;47 36 this.deliverymanRepository = deliverymanRepository; 48 37 this.categoryRepository = categoryRepository; 49 this.partRepository = partRepository;50 38 this.warehouseRepository = warehouseRepository; 51 39 this.carRepository = carRepository; 52 40 this.partManufacturerRepository = partManufacturerRepository; 53 this.priceService = priceService; 54 this.repairShopRepository = repairShopRepository; 55 this.rsForCmRepository = rsForCmRepository; 41 this.partService = partService; 42 this.repairShopService = repairShopService; 56 43 } 57 44 … … 107 94 @RequestParam List<Category> categories, @RequestParam Integer warehouse, 108 95 @RequestParam Integer quantity, @RequestParam Integer amount, HttpServletResponse response){ 109 // Part(String name, String description, PartManufacturer manufacturer, List<Category> categoryList, List<Warehouse> warehouseList, List<Car> carList) { 110 Part newPart = new Part(name, description==null ? "" : description, partManufacturerRepository.findById(manufacturer).get(), 111 categories, List.of(warehouseRepository.findById(warehouse).get()),cars); 112 partRepository.save(newPart); 113 priceService.save(new Price(amount, LocalDate.now(),newPart)); 114 partIsInStockInWarehouseRepository.save(new PartIsInStockInWarehouse(newPart.getId(),warehouse,quantity)); 115 for (Category c:categories 116 ) { 117 partIsFromCategoryRepository.save(new PartIsFromCategory(newPart.getId(),c.getId())); 118 } 119 for (Car car:cars){ 120 partIsAppropriateForCarRepository.save(new PartIsAppropriateForCar(newPart.getId(),car.getId())); 121 } 96 partService.addPart(name,description,manufacturer,cars,categories,warehouse,quantity,amount); 122 97 try { 123 98 response.sendRedirect("/"); … … 133 108 @PostMapping("/addCarManufacturer") 134 109 public void saveCarManufacturer(@RequestParam String name,@RequestParam String location, 135 Model model,HttpServletResponse response) {110 HttpServletResponse response) { 136 111 carManufacturerRepository.save(new CarManufacturer(name,location)); 137 112 try { … … 148 123 @PostMapping("/addPartManufacturer") 149 124 public void savePartManufacturer(@RequestParam String name,@RequestParam String location, 150 Model model,HttpServletResponse response) {125 HttpServletResponse response) { 151 126 partManufacturerRepository.save(new PartManufacturer(name,location)); 152 127 try { … … 163 138 @PostMapping("/addCategory") 164 139 public void saveCategory(@RequestParam String name, 165 Model model,HttpServletResponse response) {140 HttpServletResponse response) { 166 141 categoryRepository.save(new Category(name)); 167 142 try { … … 198 173 @RequestParam String number,@RequestParam Integer carMId, 199 174 HttpServletResponse response) { 200 RepairShop newRs = new RepairShop(name,location,number, 201 List.of(carManufacturerRepository.findById(carMId).get())); 202 repairShopRepository.save(newRs); 203 rsForCmRepository.save(new RsForCm(newRs.getId(), carMId)); 175 repairShopService.save(name,location,number,carMId); 204 176 try { 205 177 response.sendRedirect("/"); -
src/main/java/com/example/autopartz/controller/HomeController.java
re02787e r2a552fe 1 1 package com.example.autopartz.controller; 2 2 3 import com.example.autopartz.model.*;4 3 import com.example.autopartz.model.DTO.CurrentOrderDTO; 5 4 import com.example.autopartz.model.DTO.OrderInfo; 5 import com.example.autopartz.model.*; 6 6 import com.example.autopartz.model.manytomany.OrderContainsPart; 7 7 import com.example.autopartz.model.manytomany.PartIsInStockInWarehouse; 8 import com.example.autopartz.model.manytomany.PartIsInStockInWarehouseId;9 8 import com.example.autopartz.model.views.DeliveriesInProgress; 10 9 import com.example.autopartz.model.views.PartsForCarTypeAndCategory; … … 20 19 import java.io.IOException; 21 20 import java.util.ArrayList; 22 import java.util.Comparator;23 21 import java.util.List; 24 22 import java.util.Objects; … … 103 101 int total = 0; 104 102 List<OrderContainsPart> qList = orderContainsPartRepository.findAllByOrderid(o.getOrderid()); 105 for ( int i = 0; i < qList.size(); i++) {106 int pr = qList.get(i).getQuantity_order()*107 priceService.findPriceForPart(partService.findById( qList.get(i).getPartid())).stream().findFirst().get().getAmount();103 for (OrderContainsPart orderContainsPart : qList) { 104 int pr = orderContainsPart.getQuantity_order() * 105 priceService.findPriceForPart(partService.findById(orderContainsPart.getPartid())).stream().findFirst().get().getAmount(); 108 106 CurrentOrderDTO temp = new CurrentOrderDTO( 109 partService.findById( qList.get(i).getPartid()).getName(),110 partService.findById( qList.get(i).getPartid()).getManufacturer().getName(),111 qList.get(i).getQuantity_order(),107 partService.findById(orderContainsPart.getPartid()).getName(), 108 partService.findById(orderContainsPart.getPartid()).getManufacturer().getName(), 109 orderContainsPart.getQuantity_order(), 112 110 pr); 113 111 list.add(temp); 114 total +=pr;112 total += pr; 115 113 } 116 114 model.addAttribute("total",total); … … 188 186 } 189 187 @PostMapping("/finishRegister") 190 public void handleWarehousemanRegister(@RequestParam String location, Model model,HttpServletResponse response, HttpSession session){188 public void handleWarehousemanRegister(@RequestParam String location, HttpServletResponse response, HttpSession session){ 191 189 System.out.println("here?"); 192 190 String username = (String) session.getAttribute("username"); … … 243 241 } 244 242 @PostMapping("/finishDelivery/{id}") 245 public void finishDelivery(@PathVariable Integer id, Model model,HttpServletResponse response){243 public void finishDelivery(@PathVariable Integer id, HttpServletResponse response){ 246 244 Delivery d = deliveryService.findByOrder(orderService.findById(id)); 247 245 d.setStatus("finished"); … … 257 255 List<OrderContainsPart> list = orderContainsPartRepository.findAllByOrderid(id); 258 256 List<OrderInfo> partList = new ArrayList<>(); 259 for ( int i = 0; i < list.size(); i++) {260 OrderInfo oi = new OrderInfo(partService.findById( list.get(i).getPartid()).getName(),261 list.get(i).getQuantity_order(),partService.findById(list.get(i).getPartid()).getManufacturer().getName());257 for (OrderContainsPart orderContainsPart : list) { 258 OrderInfo oi = new OrderInfo(partService.findById(orderContainsPart.getPartid()).getName(), 259 orderContainsPart.getQuantity_order(), partService.findById(orderContainsPart.getPartid()).getManufacturer().getName()); 262 260 partList.add(oi); 263 261 } … … 301 299 Warehouse wh = whm.getWarehouse(); 302 300 Integer whId = wh.getId(); 303 PartIsInStockInWarehouseId tmp = new PartIsInStockInWarehouseId(pId,whId); 304 PartIsInStockInWarehouse temp = partIsInStockInWarehouseRepository.findById(tmp).get(); 305 temp.setQuantity(temp.getQuantity()+quantity); 306 partIsInStockInWarehouseRepository.save(temp); 301 partService.addPartToWarehouse(pId,quantity,whId); 307 302 try { 308 303 response.sendRedirect("/myWarehouseReport"); -
src/main/java/com/example/autopartz/controller/PartController.java
re02787e r2a552fe 71 71 } 72 72 @PostMapping("/repairshopdelivery") 73 public void setRepairShopDelivery(@RequestParam Integer vin, HttpServletResponse response, HttpSession session , HttpServletRequest request){73 public void setRepairShopDelivery(@RequestParam Integer vin, HttpServletResponse response, HttpSession session){ 74 74 // insert into project.repair (vin, id_repair_shop, id_service_book) values (1111,3,1) 75 75 session.setAttribute("carVin",vin); … … 107 107 RepairShop repairShop = repairShopService.getById(rs); 108 108 repairRepository.save(new Repair(o,repairShop,sb)); 109 // o.setOrder_status("finished");110 // orderService.save(o);111 109 session.removeAttribute("order"); 112 110 try { … … 125 123 Deliveryman dm = deliverymanList.get(deliverer); 126 124 deliveryRepository.save(new Delivery("in progress",address,dm,o)); 127 // o.setOrder_status("finished");128 // orderService.save(o);129 125 session.removeAttribute("order"); 130 126 try { … … 138 134 if(session.getAttribute("order")==null){ 139 135 User u = userService.findByUsername(request.getRemoteUser()); 140 Order newOrder = orderService.create ((Client) u);136 Order newOrder = orderService.createOrderAndAddPartToOrder((Client) u, id, quantity); 141 137 session.setAttribute("order",newOrder); 138 } else { 139 Order order = (Order) session.getAttribute("order"); 140 orderContainsPartRepository.save(new OrderContainsPart(id, order.getOrderid(), quantity)); 142 141 } 143 Order order = (Order) session.getAttribute("order");144 orderContainsPartRepository.save(new OrderContainsPart(id,order.getOrderid(),quantity));145 142 try { 146 143 response.sendRedirect("/products"); -
src/main/java/com/example/autopartz/controller/UserController.java
re02787e r2a552fe 25 25 private final UserService userService; 26 26 private final CarService carService; 27 private final CarSampleRepository carSampleRepository;28 private final ServiceBookRepository serviceBookRepository;29 27 private final RepairService repairService; 30 28 private final ReviewRepository reviewRepository; 31 private final RepairRepository repairRepository;32 29 private final OrderRepository orderRepository; 33 30 34 public UserController(OrdersForUserRepository ordersForUserRepository, RepairsForUserRepository repairsForUserRepository, ReviewsForUserRepository reviewsForUserRepository, UserService userService, CarService carService, CarSampleRepository carSampleRepository, ServiceBookRepository serviceBookRepository, RepairService repairService, ReviewRepository reviewRepository, 35 RepairRepository repairRepository, 31 public UserController(OrdersForUserRepository ordersForUserRepository, RepairsForUserRepository repairsForUserRepository, ReviewsForUserRepository reviewsForUserRepository, UserService userService, CarService carService, RepairService repairService, ReviewRepository reviewRepository, 36 32 OrderRepository orderRepository) { 37 33 this.ordersForUserRepository = ordersForUserRepository; … … 40 36 this.userService = userService; 41 37 this.carService = carService; 42 this.carSampleRepository = carSampleRepository;43 this.serviceBookRepository = serviceBookRepository;44 38 this.repairService = repairService; 45 39 this.reviewRepository = reviewRepository; 46 this.repairRepository = repairRepository;47 40 this.orderRepository = orderRepository; 48 41 } … … 92 85 @RequestParam Integer km, @RequestParam Integer cartype, 93 86 HttpServletRequest request, HttpServletResponse response){ 94 CarSample cs = new CarSample(vin,year,power,displacement,fuel,km, (Client) userService.findByUsername(request.getRemoteUser()),carService.findById(cartype)); 95 carSampleRepository.save(cs); 96 serviceBookRepository.save(new ServiceBook(cs)); 87 userService.addCarSampleForUser(vin,year,power,displacement,fuel,km,cartype,request.getRemoteUser()); 97 88 try { 98 89 response.sendRedirect("/"); … … 109 100 @PostMapping("/repairs/addReview/{id}") 110 101 public void addReview(@PathVariable Integer id, @RequestParam Integer rating, @RequestParam(required = false) String comment, 111 Model model,HttpServletResponse response, HttpServletRequest request){102 HttpServletResponse response, HttpServletRequest request){ 112 103 Client client = (Client) userService.findByUsername(request.getRemoteUser()); 113 104 Repair repair = repairService.findById(id);
Note:
See TracChangeset
for help on using the changeset viewer.