notification mark as read api modified for clear all, list sorting set to updated at field, added same field

This commit is contained in:
abutalib-kiwi
2023-09-29 14:58:06 +05:30
parent e121c92fb4
commit bd7eddb275
4 changed files with 32 additions and 5 deletions

View File

@ -33,7 +33,7 @@ class NotificationViewSet(viewsets.GenericViewSet):
:return:
"""
queryset = Notification.objects.filter(notification_to_id=request.auth.payload['user_id']
).select_related('notification_to').order_by('-id')
).select_related('notification_to').order_by('-updated_at', '-id')
paginator = CustomPageNumberPagination()
paginated_queryset = paginator.paginate_queryset(queryset, request)
serializer = self.serializer_class(paginated_queryset, many=True)
@ -61,6 +61,8 @@ class NotificationViewSet(viewsets.GenericViewSet):
notification_type = request.query_params.get('type', TEST_NOTIFICATION)
send_notification(int(notification_type), None, None, request.auth.payload['user_id'],
{})
if notification_type and request.query_params.get('clear_all'):
Notification.objects.filter(notification_type=notification_type).delete()
return custom_response(SUCCESS_CODE["3000"])
@action(methods=['patch'], url_path='mark-as-read', url_name='mark-as-read', detail=False,
@ -69,8 +71,14 @@ class NotificationViewSet(viewsets.GenericViewSet):
"""
notification list
"""
if request.query_params.get('all'):
Notification.objects.filter(notification_to_id=request.auth.payload['user_id']).update(is_read=True)
elif request.data.get('id'):
if request.data.get('id'):
Notification.objects.filter(id__in=request.data.get('id')).update(is_read=True)
elif request.query_params.get('mark_all'):
Notification.objects.filter(notification_to_id=request.auth.payload['user_id']).update(is_read=True)
elif request.query_params.get('clear_all'):
Notification.objects.filter(notification_to_id=request.auth.payload['user_id']).delete()
return custom_response(SUCCESS_CODE['3039'], response_status=status.HTTP_200_OK)