Advertisement
Guest User

Untitled

a guest
Sep 11th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.32 KB | None | 0 0
  1. package pl.utp.edu.workshop2.rest;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.LinkedHashMap;
  5. import java.util.List;
  6. import java.util.Map;
  7.  
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.web.bind.annotation.RequestMapping;
  10. import org.springframework.web.bind.annotation.RestController;
  11.  
  12. import pl.utp.edu.workshop2.entity.Inspection;
  13. import pl.utp.edu.workshop2.service.InspectionService;
  14.  
  15. @RestController
  16. public class WorkshopReportController {
  17.    
  18.     @Autowired
  19.     private InspectionService theInspectionService;
  20.    
  21.     @RequestMapping("/report")
  22.     public List<WorkshopReport> inspectionsReport() {
  23.        
  24.         List<WorkshopReport> theInspectionReports = new ArrayList<>();
  25.        
  26.         List<Inspection> theInspections = theInspectionService.findAll();
  27.        
  28.         Map<Integer, Integer> reportInspections = new LinkedHashMap<>();
  29.        
  30.         theInspections.forEach(e -> {
  31.             Integer inspectionId = e.getInspectionId();
  32.             Integer carId = e.getCar().getCarId();
  33.            
  34.             System.out.println(inspectionId);
  35.             System.out.println(carId);
  36.            
  37.             if (reportInspections.get(inspectionId) != null) {
  38.                 reportInspections.put(inspectionId, reportInspections.get(inspectionId) + carId);
  39.         } else {
  40.             reportInspections.put(inspectionId, carId);
  41.         }
  42.            
  43.         });
  44.        
  45.         return theInspectionReports;
  46.        
  47.     }
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement