Commit 63a90cb8 authored by Gladys Forte's avatar Gladys Forte

Merge pull request #222 in RMS/api-main-service from gladys-dev2 to RMSv2

* commit '6d298a90':
  notif
parents 1a30ffd5 6d298a90
...@@ -29,60 +29,60 @@ class NotificationsViewset(meviewsets.ModelViewSet): ...@@ -29,60 +29,60 @@ class NotificationsViewset(meviewsets.ModelViewSet):
pagination_class = CustomPagination pagination_class = CustomPagination
def list(self, request, *args, **kwargs): def list(self, request, *args, **kwargs):
# try: try:
req = self.request req = self.request
account_no = req.query_params.get('account_no') account_no = req.query_params.get('account_no')
app = req.query_params.get('app') app = req.query_params.get('app')
if account_no:
queryset = models.Notification.objects.filter( if account_no:
account_no=account_no).order_by('-created')
queryset = self.filter_queryset(queryset)
unseen = models.Notification.objects.filter(
account_no=account_no, is_read=False).count()
if app:
queryset = models.Notification.objects.filter( queryset = models.Notification.objects.filter(
account_no=account_no, app=app).order_by('-created') account_no=account_no).order_by('-created')
queryset = self.filter_queryset(queryset) queryset = self.filter_queryset(queryset)
unseen = models.Notification.objects.filter( unseen = models.Notification.objects.filter(
account_no=account_no, app=app, is_read=False).count() account_no=account_no, is_read=False).count()
else: if app:
queryset = models.Notification.objects.all().order_by('-created')
queryset = self.filter_queryset(queryset) queryset = models.Notification.objects.filter(
unseen = models.Notification.objects.filter( account_no=account_no, app=app).order_by('-created')
is_read=False).count() queryset = self.filter_queryset(queryset)
unseen = models.Notification.objects.filter(
if not queryset: account_no=account_no, app=app, is_read=False).count()
message = status_message_response(
200, 'success', 'No records found', [] else:
) queryset = models.Notification.objects.all().order_by('-created')
queryset = self.filter_queryset(queryset)
return Response(message) unseen = models.Notification.objects.filter(
is_read=False).count()
serializer = self.get_serializer(queryset, many=True)
page = self.paginate_queryset(queryset) if not queryset:
if page is not None: message = status_message_response(
serializer = self.get_serializer(page, many=True) 200, 'success', 'No records found', []
message = { )
'unseen': unseen,
'code': 200, return Response(message)
'status': 'success',
'message': 'List of Notifications found', serializer = self.get_serializer(queryset, many=True)
'results': serializer.data page = self.paginate_queryset(queryset)
} if page is not None:
serializer = self.get_serializer(page, many=True)
return self.get_paginated_response(message) message = {
'unseen': unseen,
'code': 200,
'status': 'success',
'message': 'List of Notifications found',
'results': serializer.data
}
return self.get_paginated_response(message)
# except Exception as e: except Exception as e:
# message = status_message_response( message = status_message_response(
# 500, 'failed', 500, 'failed',
# 'Request was not able to process' + str(e), []) 'Request was not able to process' + str(e), [])
# return Response(message, return Response(message,
# status=status.HTTP_500_INTERNAL_SERVER_ERROR) status=status.HTTP_500_INTERNAL_SERVER_ERROR)
# comment # comment
@action(methods=["PATCH"], detail=True) @action(methods=["PATCH"], detail=True)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment