Changeset 4d67d70 for src/main/java/com/example/autopartz/controller
- Timestamp:
- 01/07/23 01:51:16 (23 months ago)
- Branches:
- main
- Children:
- ed7ef92
- Parents:
- 89865ae
- Location:
- src/main/java/com/example/autopartz/controller
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/com/example/autopartz/controller/AdminController.java
r89865ae r4d67d70 1 1 package com.example.autopartz.controller; 2 2 3 import com.example.autopartz.model. Deliveryman;4 import com.example.autopartz.model. Role;5 import com.example.autopartz.model. User;6 import com.example.autopartz.model. Warehouseman;7 import com.example.autopartz.repository. DeliverymanRepository;8 import com.example.autopartz. repository.WarehousemanRepository;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.repository.*; 8 import com.example.autopartz.service.PriceService; 9 9 import com.example.autopartz.service.UserService; 10 10 import org.springframework.stereotype.Controller; 11 11 import org.springframework.ui.Model; 12 import org.springframework.web.bind.annotation.GetMapping; 13 import org.springframework.web.bind.annotation.PathVariable; 14 import org.springframework.web.bind.annotation.PostMapping; 15 import org.springframework.web.bind.annotation.RequestMapping; 12 import org.springframework.web.bind.annotation.*; 16 13 17 14 import javax.servlet.http.HttpServletResponse; 18 15 import java.io.IOException; 19 16 import java.time.LocalDate; 17 import java.time.LocalDateTime; 20 18 import java.util.List; 21 19 import java.util.Objects; … … 25 23 public class AdminController { 26 24 private final UserService userService; 25 private final PartIsFromCategoryRepository partIsFromCategoryRepository; 26 private final PartIsAppropriateForCarRepository partIsAppropriateForCarRepository; 27 27 private final WarehousemanRepository warehousemanRepository; 28 private final PartIsInStockInWarehouseRepository partIsInStockInWarehouseRepository; 28 29 private final DeliverymanRepository deliverymanRepository; 30 private final CategoryRepository categoryRepository; 31 private final PartRepository partRepository; 32 private final WarehouseRepository warehouseRepository; 33 private final CarRepository carRepository; 34 private final PartManufacturerRepository partManufacturerRepository; 35 private final PriceService priceService; 29 36 30 public AdminController(UserService userService, WarehousemanRepository warehousemanRepository, DeliverymanRepository deliverymanRepository) {37 public AdminController(UserService userService, PartIsFromCategoryRepository partIsFromCategoryRepository, PartIsAppropriateForCarRepository partIsAppropriateForCarRepository, WarehousemanRepository warehousemanRepository, PartIsInStockInWarehouseRepository partIsInStockInWarehouseRepository, DeliverymanRepository deliverymanRepository, CategoryRepository categoryRepository, PartRepository partRepository, WarehouseRepository warehouseRepository, CarRepository carRepository, PartManufacturerRepository partManufacturerRepository, PriceService priceService) { 31 38 this.userService = userService; 39 this.partIsFromCategoryRepository = partIsFromCategoryRepository; 40 this.partIsAppropriateForCarRepository = partIsAppropriateForCarRepository; 32 41 this.warehousemanRepository = warehousemanRepository; 42 this.partIsInStockInWarehouseRepository = partIsInStockInWarehouseRepository; 33 43 this.deliverymanRepository = deliverymanRepository; 44 this.categoryRepository = categoryRepository; 45 this.partRepository = partRepository; 46 this.warehouseRepository = warehouseRepository; 47 this.carRepository = carRepository; 48 this.partManufacturerRepository = partManufacturerRepository; 49 this.priceService = priceService; 34 50 } 35 51 … … 66 82 } 67 83 } 84 @GetMapping("/addPart") 85 public String addPart(Model model){ 86 model.addAttribute("categories",categoryRepository.findAll()); 87 model.addAttribute("warehouses",warehouseRepository.findAll()); 88 model.addAttribute("cars",carRepository.findAll()); 89 model.addAttribute("manufacturers",partManufacturerRepository.findAll()); 90 model.addAttribute("bodyContent","addPart"); 91 return "master-template"; 92 } 93 @PostMapping("/addPart") 94 public void addPart(@RequestParam String name, @RequestParam(required = false) String description, 95 @RequestParam Integer manufacturer, @RequestParam List<Car> cars, 96 @RequestParam List<Category> categories, @RequestParam Integer warehouse, 97 @RequestParam Integer quantity, @RequestParam Integer amount, HttpServletResponse response){ 98 // Part(String name, String description, PartManufacturer manufacturer, List<Category> categoryList, List<Warehouse> warehouseList, List<Car> carList) { 99 Part newPart = new Part(name, description==null ? "" : description, partManufacturerRepository.findById(manufacturer).get(), 100 categories, List.of(warehouseRepository.findById(warehouse).get()),cars); 101 partRepository.save(newPart); 102 priceService.save(new Price(amount, LocalDate.now(),newPart)); 103 partIsInStockInWarehouseRepository.save(new PartIsInStockInWarehouse(newPart.getId(),warehouse,quantity)); 104 for (Category c:categories 105 ) { 106 partIsFromCategoryRepository.save(new PartIsFromCategory(newPart.getId(),c.getId())); 107 } 108 for (Car car:cars){ 109 partIsAppropriateForCarRepository.save(new PartIsAppropriateForCar(newPart.getId(),car.getId())); 110 } 111 try { 112 response.sendRedirect("/"); 113 } catch (IOException e) { 114 throw new RuntimeException(e); 115 } 116 } 68 117 } -
src/main/java/com/example/autopartz/controller/HomeController.java
r89865ae r4d67d70 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; 8 9 import com.example.autopartz.model.views.DeliveriesInProgress; 9 10 import com.example.autopartz.model.views.PartsForCarTypeAndCategory; … … 42 43 private final MostPurchasedPartRepository mostPurchasedPartRepository; 43 44 private final PriceService priceService; 45 private final WarehousemanReportRepository warehousemanReportRepository; 46 private final PartRepository partRepository; 44 47 public HomeController(LoginService loginService, PartService partService, PartsForCarTypeAndCategoryRepository partsForCarTypeAndCategoryRepository, CarService carService, CategoryService categoryService, RepairShopReviewSummaryRepository repairShopReviewSummaryRepository, WarehouseRepository warehouseRepository, 45 OrderContainsPartRepository orderContainsPartRepository, OrderService orderService, UserService userService, DeliveriesInProgressRepository deliveriesInProgressRepository, DeliveryService deliveryService, PartIsInStockInWarehouseRepository partIsInStockInWarehouseRepository, CarCategoryReportRepository carCategoryReportRepository, PartManufacturersReportRepository partManufacturersReportRepository, MostPurchasedPartRepository mostPurchasedPartRepository, PriceService priceService ) {48 OrderContainsPartRepository orderContainsPartRepository, OrderService orderService, UserService userService, DeliveriesInProgressRepository deliveriesInProgressRepository, DeliveryService deliveryService, PartIsInStockInWarehouseRepository partIsInStockInWarehouseRepository, CarCategoryReportRepository carCategoryReportRepository, PartManufacturersReportRepository partManufacturersReportRepository, MostPurchasedPartRepository mostPurchasedPartRepository, PriceService priceService, WarehousemanReportRepository warehousemanReportRepository, PartRepository partRepository) { 46 49 this.loginService = loginService; 47 50 this.partService = partService; … … 61 64 this.mostPurchasedPartRepository = mostPurchasedPartRepository; 62 65 this.priceService = priceService; 66 this.warehousemanReportRepository = warehousemanReportRepository; 67 this.partRepository = partRepository; 63 68 } 64 69 … … 201 206 Warehouseman whm = (Warehouseman) userService.findByUsername(request.getRemoteUser()); 202 207 Warehouse warehouse = whm.getWarehouse(); 203 List<PartIsInStockInWarehouse> partIsInStockInWarehouseList = partIsInStockInWarehouseRepository.findAllByWarehouseid(warehouse.getI D_warehouse());208 List<PartIsInStockInWarehouse> partIsInStockInWarehouseList = partIsInStockInWarehouseRepository.findAllByWarehouseid(warehouse.getId()); 204 209 model.addAttribute("bodyContent","myWarehouse"); 205 210 model.addAttribute("warehouse",warehouse); … … 274 279 return "master-template"; 275 280 } 281 @GetMapping("/myWarehouseReport") 282 public String getMyWarehouseReport(Model model, HttpServletRequest request){ 283 Warehouseman whm = (Warehouseman) userService.findByUsername(request.getRemoteUser()); 284 Warehouse wh = whm.getWarehouse(); 285 Integer whId = wh.getId(); 286 model.addAttribute("data", warehousemanReportRepository.findByWid(whId)); 287 model.addAttribute("bodyContent","myWarehouseReport"); 288 return "master-template"; 289 } 290 @PostMapping("/myWarehouse/{pname}") 291 public void addPartToWarehouse(@PathVariable String pname,@RequestParam Integer quantity, HttpServletRequest request, HttpServletResponse response){ 292 Integer pId = partRepository.findAllByName(pname).stream().findFirst().get().getId(); 293 Warehouseman whm = (Warehouseman) userService.findByUsername(request.getRemoteUser()); 294 Warehouse wh = whm.getWarehouse(); 295 Integer whId = wh.getId(); 296 PartIsInStockInWarehouseId tmp = new PartIsInStockInWarehouseId(pId,whId); 297 PartIsInStockInWarehouse temp = partIsInStockInWarehouseRepository.findById(tmp).get(); 298 temp.setQuantity(temp.getQuantity()+quantity); 299 partIsInStockInWarehouseRepository.save(temp); 300 try { 301 response.sendRedirect("/myWarehouseReport"); 302 } catch (IOException e) { 303 throw new RuntimeException(e); 304 } 305 } 276 306 }
Note:
See TracChangeset
for help on using the changeset viewer.