Changeset 89865ae for src/main/java/com


Ignore:
Timestamp:
01/06/23 21:29:06 (23 months ago)
Author:
andrejtodorovski <82031894+andrejtodorovski@…>
Branches:
main
Children:
4d67d70
Parents:
cab5859
Message:

Added price and total price in currentOrder

Location:
src/main/java/com/example/autopartz
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/com/example/autopartz/controller/HomeController.java

    rcab5859 r89865ae  
    22
    33import com.example.autopartz.model.*;
     4import com.example.autopartz.model.DTO.CurrentOrderDTO;
    45import com.example.autopartz.model.DTO.OrderInfo;
    56import com.example.autopartz.model.manytomany.OrderContainsPart;
     
    4041    private final PartManufacturersReportRepository partManufacturersReportRepository;
    4142    private final MostPurchasedPartRepository mostPurchasedPartRepository;
     43    private final PriceService priceService;
    4244    public HomeController(LoginService loginService, PartService partService, PartsForCarTypeAndCategoryRepository partsForCarTypeAndCategoryRepository, CarService carService, CategoryService categoryService, RepairShopReviewSummaryRepository repairShopReviewSummaryRepository, WarehouseRepository warehouseRepository,
    43                           OrderContainsPartRepository orderContainsPartRepository, OrderService orderService, UserService userService, DeliveriesInProgressRepository deliveriesInProgressRepository, DeliveryService deliveryService, PartIsInStockInWarehouseRepository partIsInStockInWarehouseRepository, CarCategoryReportRepository carCategoryReportRepository, PartManufacturersReportRepository partManufacturersReportRepository, MostPurchasedPartRepository mostPurchasedPartRepository) {
     45                          OrderContainsPartRepository orderContainsPartRepository, OrderService orderService, UserService userService, DeliveriesInProgressRepository deliveriesInProgressRepository, DeliveryService deliveryService, PartIsInStockInWarehouseRepository partIsInStockInWarehouseRepository, CarCategoryReportRepository carCategoryReportRepository, PartManufacturersReportRepository partManufacturersReportRepository, MostPurchasedPartRepository mostPurchasedPartRepository, PriceService priceService) {
    4446        this.loginService = loginService;
    4547        this.partService = partService;
     
    5860        this.partManufacturersReportRepository = partManufacturersReportRepository;
    5961        this.mostPurchasedPartRepository = mostPurchasedPartRepository;
     62        this.priceService = priceService;
    6063    }
    6164
     
    9093            model.addAttribute("hasError",false);
    9194            model.addAttribute("order",o);
    92             model.addAttribute("parts",orderService.findById(o.getOrderid()).getPartList());
     95            List<CurrentOrderDTO> list = new ArrayList<>();
     96            int total = 0;
     97            List<OrderContainsPart> qList = orderContainsPartRepository.findAllByOrderid(o.getOrderid());
     98            for (int i = 0; i < qList.size(); i++) {
     99                int pr = qList.get(i).getQuantity_order()*
     100                        priceService.findPriceForPart(partService.findById(qList.get(i).getPartid())).stream().findFirst().get().getAmount();
     101                CurrentOrderDTO temp = new CurrentOrderDTO(
     102                        partService.findById(qList.get(i).getPartid()).getName(),
     103                        partService.findById(qList.get(i).getPartid()).getManufacturer().getName(),
     104                        qList.get(i).getQuantity_order(),
     105                        pr);
     106                list.add(temp);
     107                total+=pr;
     108            }
     109            model.addAttribute("total",total);
     110            model.addAttribute("parts",list);
    93111        }
    94112        model.addAttribute("bodyContent","currentOrder");
Note: See TracChangeset for help on using the changeset viewer.