From 836c33fc94dbb75d241717b7db6a3718edcc0464 Mon Sep 17 00:00:00 2001
From: Christian Heller <c.heller@plomlompom.de>
Date: Wed, 20 Mar 2024 03:33:17 +0100
Subject: [PATCH] Collect GET /calendar range from "?start=" and "?end=".

---
 plomtask/http.py   | 8 +++++---
 tests/test_days.py | 8 ++++++++
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/plomtask/http.py b/plomtask/http.py
index 0af96e7..b698fcb 100644
--- a/plomtask/http.py
+++ b/plomtask/http.py
@@ -29,7 +29,9 @@ class TaskHandler(BaseHTTPRequestHandler):
         try:
             conn, site, params = self._init_handling()
             if 'calendar' == site:
-                html = self.do_GET_calendar(conn)
+                start = params.get('start', [''])[0]
+                end = params.get('end', [''])[0]
+                html = self.do_GET_calendar(conn, start, end)
             elif 'day' == site:
                 date = params.get('date', [todays_date()])[0]
                 html = self.do_GET_day(conn, date)
@@ -41,10 +43,10 @@ class TaskHandler(BaseHTTPRequestHandler):
         except HandledException as error:
             self._send_msg(error)
 
-    def do_GET_calendar(self, conn: DatabaseConnection):
+    def do_GET_calendar(self, conn: DatabaseConnection, start: str, end: str):
         """Show Days."""
         return self.server.jinja.get_template('calendar.html').render(
-                days=Day.all(conn))
+                days=Day.all(conn, date_range=(start, end)))
 
     def do_GET_day(self, conn: DatabaseConnection, date: str):
         """Show single Day."""
diff --git a/tests/test_days.py b/tests/test_days.py
index e25eafd..2adf765 100644
--- a/tests/test_days.py
+++ b/tests/test_days.py
@@ -145,6 +145,14 @@ class TestsWithServer(TestsWithDB):
         self.assertEqual(http_conn.getresponse().status, 400)
         http_conn.request('GET', '/calendar')
         self.assertEqual(http_conn.getresponse().status, 200)
+        http_conn.request('GET', '/calendar?start=&end=')
+        self.assertEqual(http_conn.getresponse().status, 200)
+        http_conn.request('GET', '/calendar?start=today&end=today')
+        self.assertEqual(http_conn.getresponse().status, 200)
+        http_conn.request('GET', '/calendar?start=2024-01-01&end=2025-01-01')
+        self.assertEqual(http_conn.getresponse().status, 200)
+        http_conn.request('GET', '/calendar?start=foo')
+        self.assertEqual(http_conn.getresponse().status, 400)
 
     def tearDown(self):
         self.httpd.shutdown()
-- 
2.30.2