/** * Requests a list of all data from given car park * * <p>Request example: GET http://localhost:8080/carparks/carParkLoads/renoma * * @return */ @RequestMapping(value = "/carParkLoads/{name}", method = RequestMethod.GET) public Page<CarParkLoad> getCarParkLoad( @PathVariable final String name, @RequestParam(defaultValue = DEFAULT_PAGE) int page, @RequestParam(defaultValue = DEFAULT_SIZE) int size, @RequestParam(defaultValue = DEFAULT_SORT_ITEM) String sort, @RequestParam(defaultValue = DEFAULT_SORT_ORDER) String sortOrder) { LOGGER.infof("Entering getCarParkLoad(%s)", name); final CarPark carPark = carParkRep.findByName(name); final Page<CarParkLoad> carkParkLoad = carParkLoadRep.findByCarPark(carPark, createPageRequest(page, size, sort, sortOrder)); if (LOGGER.isTraceEnabled()) { LOGGER.tracef("Leaving getCarParkLoad(): %s", carkParkLoad); } else { LOGGER.info("Leaving getCarParkLoad()"); } return carkParkLoad; }
/** * Requests the latest (the closest before the "now") entries for all carparks from the * carparkload table * * <p>Request example: GET http://localhost:8080/carparks/latestEntries * * @return */ @RequestMapping(value = "/latestEntries", method = RequestMethod.GET) public List<CarParkLoad> getLatestEntries() { LOGGER.infof("Entering getLatestEntries()"); List<CarParkLoad> latestEntries = new LinkedList<CarParkLoad>(); Iterable<CarPark> carParks = carParkRep.findAll(); for (CarPark carPark : carParks) { final CarParkLoad carParkLoad = carParkLoadRep.getLatestEntry(carPark.getCarParkid(), createPageRequest(0, 1)).get(0); if (carParkLoad.getTimestamp().getTime() > System.currentTimeMillis() - MILIS_IN_DAY) { latestEntries.add(carParkLoad); } } if (LOGGER.isTraceEnabled()) { LOGGER.tracef("Leaving getLatestEntries(): %s", latestEntries); } else { LOGGER.info("Leaving getLatestEntries()"); } return latestEntries; }