Changeset 84652fb for src/main/java/com/example/autopartz/controller
- Timestamp:
- 01/07/23 18:37:26 (23 months ago)
- Branches:
- main
- Children:
- 5e7345e
- Parents:
- 37966cf
- Location:
- src/main/java/com/example/autopartz/controller
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/com/example/autopartz/controller/AdminController.java
r37966cf r84652fb 5 5 import com.example.autopartz.model.manytomany.PartIsFromCategory; 6 6 import com.example.autopartz.model.manytomany.PartIsInStockInWarehouse; 7 import com.example.autopartz.model.manytomany.RsForCm; 7 8 import com.example.autopartz.repository.*; 8 9 import com.example.autopartz.service.PriceService; … … 15 16 import java.io.IOException; 16 17 import java.time.LocalDate; 17 import java.time.LocalDateTime;18 18 import java.util.List; 19 19 import java.util.Objects; … … 23 23 public class AdminController { 24 24 private final UserService userService; 25 private final CarManufacturerRepository carManufacturerRepository; 25 26 private final PartIsFromCategoryRepository partIsFromCategoryRepository; 26 27 private final PartIsAppropriateForCarRepository partIsAppropriateForCarRepository; … … 34 35 private final PartManufacturerRepository partManufacturerRepository; 35 36 private final PriceService priceService; 36 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) { 37 private final RepairShopRepository repairShopRepository; 38 private final RsForCmRepository rsForCmRepository; 39 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) { 38 41 this.userService = userService; 42 this.carManufacturerRepository = carManufacturerRepository; 39 43 this.partIsFromCategoryRepository = partIsFromCategoryRepository; 40 44 this.partIsAppropriateForCarRepository = partIsAppropriateForCarRepository; … … 48 52 this.partManufacturerRepository = partManufacturerRepository; 49 53 this.priceService = priceService; 54 this.repairShopRepository = repairShopRepository; 55 this.rsForCmRepository = rsForCmRepository; 50 56 } 51 57 … … 115 121 } 116 122 } 123 @GetMapping("/addCarManufacturer") 124 public String getCarManView(Model model){ 125 model.addAttribute("bodyContent","addCarManufacturer"); 126 return "master-template"; 127 } 128 @PostMapping("/addCarManufacturer") 129 public void saveCarManufacturer(@RequestParam String name,@RequestParam String location, 130 Model model, HttpServletResponse response) { 131 carManufacturerRepository.save(new CarManufacturer(name,location)); 132 try { 133 response.sendRedirect("/"); 134 } catch (IOException e) { 135 throw new RuntimeException(e); 136 } 137 } 138 @GetMapping("/addPartManufacturer") 139 public String getPartManView(Model model){ 140 model.addAttribute("bodyContent","addPartManufacturer"); 141 return "master-template"; 142 } 143 @PostMapping("/addPartManufacturer") 144 public void savePartManufacturer(@RequestParam String name,@RequestParam String location, 145 Model model, HttpServletResponse response) { 146 partManufacturerRepository.save(new PartManufacturer(name,location)); 147 try { 148 response.sendRedirect("/"); 149 } catch (IOException e) { 150 throw new RuntimeException(e); 151 } 152 } 153 @GetMapping("/addCategory") 154 public String getCategoryView(Model model){ 155 model.addAttribute("bodyContent","addCategory"); 156 return "master-template"; 157 } 158 @PostMapping("/addCategory") 159 public void saveCategory(@RequestParam String name, 160 Model model, HttpServletResponse response) { 161 categoryRepository.save(new Category(name)); 162 try { 163 response.sendRedirect("/"); 164 } catch (IOException e) { 165 throw new RuntimeException(e); 166 } 167 } 168 @GetMapping("/addCar") 169 public String getCarView(Model model){ 170 model.addAttribute("bodyContent","addCar"); 171 model.addAttribute("manufacturers",carManufacturerRepository.findAll()); 172 return "master-template"; 173 } 174 @PostMapping("/addCar") 175 public void saveCar(@RequestParam Integer since,@RequestParam Integer till, 176 @RequestParam String name,@RequestParam Integer mId, 177 HttpServletResponse response) { 178 carRepository.save(new Car(since,till,name,carManufacturerRepository.findById(mId).get())); 179 try { 180 response.sendRedirect("/"); 181 } catch (IOException e) { 182 throw new RuntimeException(e); 183 } 184 } 185 @GetMapping("/addRepairShop") 186 public String getRepairShopView(Model model){ 187 model.addAttribute("bodyContent","addRepairShop"); 188 model.addAttribute("manufacturers",carManufacturerRepository.findAll()); 189 return "master-template"; 190 } 191 @PostMapping("/addRepairShop") 192 public void saveRepairShop(@RequestParam String name,@RequestParam String location, 193 @RequestParam String number,@RequestParam Integer carMId, 194 HttpServletResponse response) { 195 RepairShop newRs = new RepairShop(name,location,number, 196 List.of(carManufacturerRepository.findById(carMId).get())); 197 repairShopRepository.save(newRs); 198 rsForCmRepository.save(new RsForCm(newRs.getId(), carMId)); 199 try { 200 response.sendRedirect("/"); 201 } catch (IOException e) { 202 throw new RuntimeException(e); 203 } 204 } 205 @GetMapping("/addWarehouse") 206 public String getWarehouseView(Model model){ 207 model.addAttribute("bodyContent","addWarehouse"); 208 return "master-template"; 209 } 210 @PostMapping("/addWarehouse") 211 public void saveWarehouse(@RequestParam String name, 212 HttpServletResponse response) { 213 warehouseRepository.save(new Warehouse(name)); 214 try { 215 response.sendRedirect("/"); 216 } catch (IOException e) { 217 throw new RuntimeException(e); 218 } 219 } 117 220 } -
src/main/java/com/example/autopartz/controller/PartController.java
r37966cf r84652fb 89 89 model.addAttribute("hasError", false); 90 90 CarSample cs = carSampleRepository.findById((Integer) session.getAttribute("carVin")).get(); 91 Integer idCM = cs.getCar().getCar_manufacturer().getI D_car_manufacturer();91 Integer idCM = cs.getCar().getCar_manufacturer().getId(); 92 92 List<RsForCm> rsForCm = rsForCmRepository.findAllByCmid(idCM); 93 93 List<RepairShop> newRepairShopList = new ArrayList<>();
Note:
See TracChangeset
for help on using the changeset viewer.