mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
also add a unread endpoint
This commit is contained in:
parent
06f6587050
commit
d57ebde265
@ -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()
|
queryset = common.models.NotificationMessage.objects.all()
|
||||||
@ -208,12 +208,26 @@ class NotificationRead(generics.CreateAPIView):
|
|||||||
def perform_create(self, serializer):
|
def perform_create(self, serializer):
|
||||||
message = self.get_object()
|
message = self.get_object()
|
||||||
try:
|
try:
|
||||||
message.read = True
|
message.read = self.target
|
||||||
message.save()
|
message.save()
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
raise serializers.ValidationError(detail=serializers.as_serializer_error(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 = [
|
settings_api_urls = [
|
||||||
# User settings
|
# User settings
|
||||||
url(r'^user/', include([
|
url(r'^user/', include([
|
||||||
@ -241,6 +255,7 @@ common_api_urls = [
|
|||||||
# Individual purchase order detail URLs
|
# Individual purchase order detail URLs
|
||||||
url(r'^(?P<pk>\d+)/', include([
|
url(r'^(?P<pk>\d+)/', include([
|
||||||
url(r'^read/', NotificationRead.as_view(), name='api-notifications-read'),
|
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'),
|
url(r'.*$', NotificationDetail.as_view(), name='api-notifications-detail'),
|
||||||
])),
|
])),
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user