From d57ebde265f29af19c821df1c11da8cb86acc645 Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 29 Nov 2021 01:08:54 +0100 Subject: [PATCH] also add a unread endpoint --- InvenTree/common/api.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/InvenTree/common/api.py b/InvenTree/common/api.py index 2f468702a2..904567f75c 100644 --- a/InvenTree/common/api.py +++ b/InvenTree/common/api.py @@ -187,9 +187,9 @@ class NotificationDetail(generics.RetrieveDestroyAPIView): ] -class NotificationRead(generics.CreateAPIView): +class NotificationReadEdit(generics.CreateAPIView): """ - API endpoint to mark a notification as read. + general API endpoint to manipulate read state of a notification """ queryset = common.models.NotificationMessage.objects.all() @@ -208,12 +208,26 @@ class NotificationRead(generics.CreateAPIView): def perform_create(self, serializer): message = self.get_object() try: - message.read = True + message.read = self.target message.save() except Exception as exc: raise serializers.ValidationError(detail=serializers.as_serializer_error(exc)) +class NotificationRead(NotificationReadEdit): + """ + API endpoint to mark a notification as read. + """ + target = True + + +class NotificationUnread(NotificationReadEdit): + """ + API endpoint to mark a notification as unread. + """ + target = False + + settings_api_urls = [ # User settings url(r'^user/', include([ @@ -241,6 +255,7 @@ common_api_urls = [ # Individual purchase order detail URLs url(r'^(?P\d+)/', include([ url(r'^read/', NotificationRead.as_view(), name='api-notifications-read'), + url(r'^unread/', NotificationUnread.as_view(), name='api-notifications-unread'), url(r'.*$', NotificationDetail.as_view(), name='api-notifications-detail'), ])),