From af18666f092e9a07ea8e8aa550e62d9723deea71 Mon Sep 17 00:00:00 2001 From: Simon Date: Fri, 2 Aug 2024 15:35:12 +0200 Subject: [PATCH] post request notification --- tubearchivist/task/views.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tubearchivist/task/views.py b/tubearchivist/task/views.py index 8972b1bf..61d0a013 100644 --- a/tubearchivist/task/views.py +++ b/tubearchivist/task/views.py @@ -162,6 +162,7 @@ class ScheduleView(ApiBaseView): class ScheduleNotification(ApiBaseView): """resolves to /api/task/notification/ GET: get all schedule notifications + POST: add notification url to task DEL: delete notification """ @@ -170,6 +171,24 @@ class ScheduleNotification(ApiBaseView): return Response(get_all_notifications()) + def post(self, request): + """handle create notification""" + task_name = request.data.get("task_name") + url = request.data.get("url") + + if not TASK_CONFIG.get(task_name): + message = {"message": "task_name not found"} + return Response(message, status=404) + + if not url: + message = {"message": "missing url key"} + return Response(message, status=400) + + Notifications(task_name).add_url(url) + message = {"task_name": task_name, "url": url} + + return Response(message) + def delete(self, request): """handle delete"""