mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-07-16 02:16:16 +00:00
notification mark as read api modified for clear all, list sorting set to updated at field, added same field
This commit is contained in:
@ -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)
|
||||
|
Reference in New Issue
Block a user