package de.kopis.timeclicker.controllers;

import de.kopis.timeclicker.api.TimeclickerAPI;
import de.kopis.timeclicker.exceptions.NotAuthenticatedException;
import de.kopis.timeclicker.model.TimeEntry;
import de.kopis.timeclicker.model.TimeSumWithDate;
import de.kopis.timeclicker.utils.TimeSumUtility;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

@Controller
@RequestMapping("/charts")
public class ChartController {
  public static final int LIMIT = 31 * 12;
  private final TimeclickerAPI api = new TimeclickerAPI();
  private final UserService userService = UserServiceFactory.getUserService();

  @GetMapping("/weekly")
  public String getWeeklyChart(Model model) throws NotAuthenticatedException {
    final User user = userService.getCurrentUser();

    final List<TimeEntry> allEntries = api.list(LIMIT, 0, user);
    final List<TimeSumWithDate> sortedPerWeek = new TimeSumUtility().calculateWeeklyTimeSum(allEntries);
    Collections.sort(sortedPerWeek, Comparator.comparing(TimeSumWithDate::getDate));
    model.addAttribute("weeklySums", sortedPerWeek);

    return "charts/weekly";
  }

  @GetMapping("/daily")
  public String getDailyChart(Model model) throws NotAuthenticatedException {
    final User user = userService.getCurrentUser();

    final List<TimeEntry> allEntries = api.list(LIMIT, 0, user);
    final List<TimeSumWithDate> sortedPerDay = new TimeSumUtility().calculateDailyTimeSum(allEntries);
    Collections.sort(sortedPerDay, Comparator.comparing(TimeSumWithDate::getDate));
    model.addAttribute("dailySums", sortedPerDay);

    return "charts/daily";
  }
}

@@ -505,16 +505,77 @@
 Mapping;
+%0Aimport org.springframework.web.bind.annotation.RequestParam;
 %0A%0Aimport
@@ -879,51 +879,8 @@
 r %7B%0A
-  public static final int LIMIT = 31 * 12;%0A
   pr
@@ -1073,32 +1073,184 @@
 hart(Model model
+,%0A                               @RequestParam(defaultValue = %2231%22) int limit,%0A                               @RequestParam(defaultValue = %220%22) int page
 ) throws NotAuth
@@ -1367,32 +1367,35 @@
  = api.list(
-LIMIT, 0
+limit, page
 , user);%0A   
@@ -1733,16 +1733,166 @@
 el model
+,%0A                              @RequestParam(defaultValue = %2231%22) int limit,%0A                              @RequestParam(defaultValue = %220%22) int page
 ) throws
@@ -2025,16 +2025,19 @@
 ist(
-LIMIT, 0
+limit, page
 , us

Add limit+page as RequestParam