Exemplo n.º 1
0
 @RequestMapping(value = "/voteStatistics", method = RequestMethod.GET)
 public DTOContainer getVotes() {
   List<VoteEntity> byVoteDate =
       voteRepository.findByVoteDate(DateController.getInstance().getCurrentDay());
   DTOContainer result = new DTOContainer();
   Map<Integer, Integer> statistics = new HashMap<Integer, Integer>();
   for (VoteEntity entity : byVoteDate) {
     int restaurantId = entity.getRestaurantId();
     int count = 0;
     if (statistics.containsKey(restaurantId)) {
       count = statistics.get(restaurantId);
     }
     count++;
     statistics.put(restaurantId, count);
   }
   List<StatisticItemDTO> statisticsList = new LinkedList<StatisticItemDTO>();
   for (Integer key : statistics.keySet()) {
     StatisticItemDTO item = new StatisticItemDTO();
     item.setRestaurantId(key);
     item.setVotesCount(statistics.get(key));
     statisticsList.add(item);
   }
   result.setData(statisticsList);
   result.setSuccess(true);
   return result;
 }
Exemplo n.º 2
0
 @RequestMapping(
     value = "/voteStatistics",
     method = RequestMethod.GET,
     params = {"restaurantId", "currentTime"})
 public DTOContainer getVoteStatisticsAtTime(
     @RequestParam Integer restaurantId, @RequestParam Long currentTime) {
   List<VoteEntity> byVoteDate =
       voteRepository.findByVoteDateAndRestaurantId(
           DateController.getInstance().getCurrentDay(currentTime), restaurantId);
   DTOContainer result = new DTOContainer();
   StatisticItemDTO dto = new StatisticItemDTO();
   dto.setRestaurantId(restaurantId);
   dto.setVotesCount(byVoteDate.size());
   result.setData(dto);
   result.setSuccess(true);
   return result;
 }