Commit 033f710d authored by Ristylou Dolar's avatar Ristylou Dolar

Modified Application, Endpoint and Service retrieve method

parent 510a53e5
...@@ -94,23 +94,23 @@ class ApplicationViewSet(viewsets.ModelViewSet): ...@@ -94,23 +94,23 @@ class ApplicationViewSet(viewsets.ModelViewSet):
def retrieve(self, request, *args, **kwargs): def retrieve(self, request, *args, **kwargs):
try: try:
id = self.kwargs['pk'] id = self.kwargs['pk']
queryset = Application.objects.filter(id=id) instance = Application.objects.get(id=id)
serializer = self.get_serializer(queryset, many=True) serializer = self.get_serializer(instance)
if not queryset.exists(): message = status_message_response(
message = status_message_response(404, 'failed',
'No record found', [])
return Response(message, status=status.HTTP_404_NOT_FOUND)
else:
message = status_message_response(
200, 'success', 200, 'success',
'Application retrieved', serializer.data 'Application retrieved', serializer.data
) )
return Response(message, status=status.HTTP_200_OK) return Response(message, status=status.HTTP_200_OK)
except Application.DoesNotExist:
message = status_message_response(404, 'failed',
'No record found', [])
return Response(message, status=status.HTTP_404_NOT_FOUND)
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,
......
...@@ -80,24 +80,23 @@ class APIEndpointViewSet(viewsets.ModelViewSet): ...@@ -80,24 +80,23 @@ class APIEndpointViewSet(viewsets.ModelViewSet):
def retrieve(self, request, *args, **kwargs): def retrieve(self, request, *args, **kwargs):
try: try:
id = self.kwargs['pk'] id = self.kwargs['pk']
queryset = APIEndpoint.objects.filter(id=id) instance = APIEndpoint.objects.get(id=id)
serializer = self.get_serializer(queryset, many=True) serializer = self.get_serializer(instance)
message = status_message_response(
200, 'success',
'Endpoint retrieved', serializer.data
)
return Response(message, status=status.HTTP_200_OK)
if not queryset.exists(): except APIEndpoint.DoesNotExist:
message = status_message_response( message = status_message_response(404, 'failed',
404, 'failed', 'No record found', [] 'No record found', [])
) return Response(message, status=status.HTTP_404_NOT_FOUND)
return Response(message, status=status.HTTP_404_NOT_FOUND)
else:
message = status_message_response(
200, 'success',
'Endpoint retrieved', serializer.data
)
return Response(message, status=status.HTTP_200_OK)
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,
......
...@@ -76,24 +76,23 @@ class APIServiceViewSet(viewsets.ModelViewSet): ...@@ -76,24 +76,23 @@ class APIServiceViewSet(viewsets.ModelViewSet):
def retrieve(self, request, *args, **kwargs): def retrieve(self, request, *args, **kwargs):
try: try:
id = self.kwargs['pk'] id = self.kwargs['pk']
queryset = APIService.objects.filter(id=id) instance = APIService.objects.get(id=id)
serializer = self.get_serializer(queryset, many=True) serializer = self.get_serializer(instance)
message = status_message_response(
200, 'success',
'Service retrieved', serializer.data
)
return Response(message, status=status.HTTP_200_OK)
if not queryset.exists(): except APIService.DoesNotExist:
message = status_message_response( message = status_message_response(404, 'failed',
404, 'failed', 'No record found', [] 'No record found', [])
) return Response(message, status=status.HTTP_404_NOT_FOUND)
return Response(message, status=status.HTTP_404_NOT_FOUND)
else:
message = status_message_response(
200, 'success',
'Service retrieved', serializer.data
)
return Response(message, status=status.HTTP_200_OK)
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,
......
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