Commit 61861cb9 authored by John Red Medrano's avatar John Red Medrano

removed unused codes

parent a9844ae2
...@@ -10,7 +10,7 @@ from api.views import ( ...@@ -10,7 +10,7 @@ from api.views import (
router = DefaultRouter() router = DefaultRouter()
router.register(r'applications', ApplicationViewSet) router.register(r'applications', ApplicationViewSet)
router.register(r'services', APIServiceViewSet) router.register(r'services', APIServiceViewSet)
router.register(r'endpoint', APIEndpointViewSet) router.register(r'endpoints', APIEndpointViewSet)
router.register(r'main-application', MainApplicationViewSet) router.register(r'main-application', MainApplicationViewSet)
urlpatterns = [ urlpatterns = [
......
...@@ -9,7 +9,6 @@ from .models import APIEndpoint ...@@ -9,7 +9,6 @@ from .models import APIEndpoint
from rest_framework.pagination import PageNumberPagination from rest_framework.pagination import PageNumberPagination
from rest_framework.response import Response from rest_framework.response import Response
import datetime import datetime
from functools import wraps
VALIDATE_TOKEN_URL = settings.VALIDATE_TOKEN_URL VALIDATE_TOKEN_URL = settings.VALIDATE_TOKEN_URL
......
...@@ -246,12 +246,3 @@ class ApplicationViewSet(viewsets.ModelViewSet): ...@@ -246,12 +246,3 @@ class ApplicationViewSet(viewsets.ModelViewSet):
class MainApplicationViewSet(viewsets.ModelViewSet): class MainApplicationViewSet(viewsets.ModelViewSet):
queryset = Application.objects.all() queryset = Application.objects.all()
serializer_class = GroupDependentSerializer serializer_class = GroupDependentSerializer
# def get_queryset(self):
# groups = self.request.query_params.get(
# 'groups', None
# )
# groups = groups.split(',')
# # print()
# app = Application.objects.filter(id__in=groups)
# return app
...@@ -3,7 +3,10 @@ from rest_framework.decorators import action ...@@ -3,7 +3,10 @@ from rest_framework.decorators import action
from rest_framework.response import Response from rest_framework.response import Response
from api.models import APIEndpoint from api.models import APIEndpoint
from api.serializers import APIEndpointSerializer from api.serializers import APIEndpointSerializer
from api.utils import (APIEndpointFilter, CustomPagination, BadRequestException, status_message_response) from api.utils import (
APIEndpointFilter, CustomPagination,
BadRequestException, status_message_response
)
from django_filters.rest_framework import DjangoFilterBackend from django_filters.rest_framework import DjangoFilterBackend
...@@ -24,11 +27,10 @@ class APIEndpointViewSet(viewsets.ModelViewSet): ...@@ -24,11 +27,10 @@ class APIEndpointViewSet(viewsets.ModelViewSet):
serializer = self.get_serializer(data=request.data) serializer = self.get_serializer(data=request.data)
serializer.is_valid(raise_exception=True) serializer.is_valid(raise_exception=True)
self.perform_create(serializer) self.perform_create(serializer)
headers = self.get_success_headers(serializer.data)
message = status_message_response(201, 'success', 'New endpoint created', serializer.data) message = status_message_response(201, 'success', 'New endpoint created', serializer.data)
return Response(message) return Response(message)
except BadRequestException as e: except BadRequestException as e:
message = status_message_response(400, 'failed', str(e), []) message = status_message_response(400, 'failed', str(e), [])
return Response(message, status=status.HTTP_400_BAD_REQUEST) return Response(message, status=status.HTTP_400_BAD_REQUEST)
...@@ -45,7 +47,7 @@ class APIEndpointViewSet(viewsets.ModelViewSet): ...@@ -45,7 +47,7 @@ class APIEndpointViewSet(viewsets.ModelViewSet):
if not queryset.exists(): if not queryset.exists():
message = status_message_response(200, 'success', 'No records found', []) message = status_message_response(200, 'success', 'No records found', [])
return Response(message) return Response(message)
page = self.paginate_queryset(queryset) page = self.paginate_queryset(queryset)
if page is not None: if page is not None:
serializer = self.get_serializer(page, many=True) serializer = self.get_serializer(page, many=True)
...@@ -67,14 +69,14 @@ class APIEndpointViewSet(viewsets.ModelViewSet): ...@@ -67,14 +69,14 @@ class APIEndpointViewSet(viewsets.ModelViewSet):
id = self.kwargs['pk'] id = self.kwargs['pk']
queryset = APIEndpoint.objects.filter(id=id) queryset = APIEndpoint.objects.filter(id=id)
serializer = self.get_serializer(queryset, many=True) serializer = self.get_serializer(queryset, many=True)
if not queryset.exists(): if not queryset.exists():
message = status_message_response(404, 'failed', 'No record found', []) message = status_message_response(404, 'failed', 'No record found', [])
return Response(message, status=status.HTTP_404_NOT_FOUND) return Response(message, status=status.HTTP_404_NOT_FOUND)
else: else:
message = status_message_response(200, 'success', 'Endpoint retrieved', serializer.data) message = status_message_response(200, 'success', 'Endpoint retrieved', serializer.data)
return Response(message, status=status.HTTP_200_OK) return Response(message, status=status.HTTP_200_OK)
except Exception as e: except Exception as e:
message = status_message_response(500, 'failed', 'Request was not able to process' + str(e), []) message = status_message_response(500, 'failed', 'Request was not able to process' + str(e), [])
return Response(message, status=status.HTTP_500_INTERNAL_SERVER_ERROR) return Response(message, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
...@@ -89,10 +91,10 @@ class APIEndpointViewSet(viewsets.ModelViewSet): ...@@ -89,10 +91,10 @@ class APIEndpointViewSet(viewsets.ModelViewSet):
self.perform_update(serializer) self.perform_update(serializer)
if getattr(instance, '_prefetched_objects_cache', None): if getattr(instance, '_prefetched_objects_cache', None):
instance._prefetched_objects_cache = {} instance._prefetched_objects_cache = {}
message = status_message_response(200, 'success', 'Endpoint updated', serializer.data) message = status_message_response(200, 'success', 'Endpoint updated', serializer.data)
return Response(message) return Response(message)
except Exception as e: except Exception as e:
message = status_message_response(500, 'failed', 'Request was not able to process' + str(e), []) message = status_message_response(500, 'failed', 'Request was not able to process' + str(e), [])
return Response(message, status=status.HTTP_500_INTERNAL_SERVER_ERROR) return Response(message, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
...@@ -102,13 +104,13 @@ class APIEndpointViewSet(viewsets.ModelViewSet): ...@@ -102,13 +104,13 @@ class APIEndpointViewSet(viewsets.ModelViewSet):
try: try:
instance = self.get_object() instance = self.get_object()
self.perform_destroy(instance) self.perform_destroy(instance)
message = status_message_response(200, 'success', 'Endpoint deleted', []) message = status_message_response(200, 'success', 'Endpoint deleted', [])
return Response(message, status=status.HTTP_200_OK) return Response(message, status=status.HTTP_200_OK)
except Exception as e: except Exception as e:
message = status_message_response(500, 'failed', 'Request was not able to process' + str(e), []) message = status_message_response(500, 'failed', 'Request was not able to process' + str(e), [])
return Response(message, status=status.HTTP_500_INTERNAL_SERVER_ERROR) return Response(message, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
# PATCH - RESTORE archived endpoint # PATCH - RESTORE archived endpoint
...@@ -125,14 +127,14 @@ class APIEndpointViewSet(viewsets.ModelViewSet): ...@@ -125,14 +127,14 @@ class APIEndpointViewSet(viewsets.ModelViewSet):
except Exception as e: except Exception as e:
message = status_message_response(500, 'failed', 'Request was not able to process' + str(e), []) message = status_message_response(500, 'failed', 'Request was not able to process' + str(e), [])
return Response(message, status=status.HTTP_500_INTERNAL_SERVER_ERROR) return Response(message, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
# /archived - show list of archived endpoints # /archived - show list of archived endpoints
@action(methods=["GET"], detail=False) @action(methods=["GET"], detail=False)
def archived(self, request, pk=None): def archived(self, request, pk=None):
try: try:
queryset = APIEndpoint.objects.filter(deleted_at__isnull=False) queryset = APIEndpoint.objects.filter(deleted_at__isnull=False)
if not queryset.exists(): if not queryset.exists():
message = status_message_response(200, 'success', 'No archived endpoints', []) message = status_message_response(200, 'success', 'No archived endpoints', [])
return Response(message) return Response(message)
......
...@@ -21,11 +21,10 @@ class APIServiceViewSet(viewsets.ModelViewSet): ...@@ -21,11 +21,10 @@ class APIServiceViewSet(viewsets.ModelViewSet):
serializer = self.get_serializer(data=request.data) serializer = self.get_serializer(data=request.data)
serializer.is_valid(raise_exception=True) serializer.is_valid(raise_exception=True)
self.perform_create(serializer) self.perform_create(serializer)
headers = self.get_success_headers(serializer.data)
message = status_message_response(201, 'success', 'New service created', serializer.data) message = status_message_response(201, 'success', 'New service created', serializer.data)
return Response(message) return Response(message)
except BadRequestException as e: except BadRequestException as e:
message = status_message_response(400, 'failed', str(e), []) message = status_message_response(400, 'failed', str(e), [])
return Response(message, status=status.HTTP_400_BAD_REQUEST) return Response(message, status=status.HTTP_400_BAD_REQUEST)
...@@ -42,7 +41,7 @@ class APIServiceViewSet(viewsets.ModelViewSet): ...@@ -42,7 +41,7 @@ class APIServiceViewSet(viewsets.ModelViewSet):
if not queryset.exists(): if not queryset.exists():
message = status_message_response(200, 'success', 'No records found', []) message = status_message_response(200, 'success', 'No records found', [])
return Response(message) return Response(message)
page = self.paginate_queryset(queryset) page = self.paginate_queryset(queryset)
if page is not None: if page is not None:
serializer = self.get_serializer(page, many=True) serializer = self.get_serializer(page, many=True)
...@@ -71,7 +70,7 @@ class APIServiceViewSet(viewsets.ModelViewSet): ...@@ -71,7 +70,7 @@ class APIServiceViewSet(viewsets.ModelViewSet):
else: else:
message = status_message_response(200, 'success', 'Service retrieved', serializer.data) message = status_message_response(200, 'success', 'Service retrieved', serializer.data)
return Response(message, status=status.HTTP_200_OK) return Response(message, status=status.HTTP_200_OK)
except Exception as e: except Exception as e:
message = status_message_response(500, 'failed', 'Request was not able to process' + str(e), []) message = status_message_response(500, 'failed', 'Request was not able to process' + str(e), [])
return Response(message, status=status.HTTP_500_INTERNAL_SERVER_ERROR) return Response(message, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
...@@ -86,10 +85,10 @@ class APIServiceViewSet(viewsets.ModelViewSet): ...@@ -86,10 +85,10 @@ class APIServiceViewSet(viewsets.ModelViewSet):
self.perform_update(serializer) self.perform_update(serializer)
if getattr(instance, '_prefetched_objects_cache', None): if getattr(instance, '_prefetched_objects_cache', None):
instance._prefetched_objects_cache = {} instance._prefetched_objects_cache = {}
message = status_message_response(200, 'success', 'Service updated', serializer.data) message = status_message_response(200, 'success', 'Service updated', serializer.data)
return Response(message) return Response(message)
except Exception as e: except Exception as e:
message = status_message_response(500, 'failed', 'Request was not able to process' + str(e), []) message = status_message_response(500, 'failed', 'Request was not able to process' + str(e), [])
return Response(message, status=status.HTTP_500_INTERNAL_SERVER_ERROR) return Response(message, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
...@@ -105,7 +104,7 @@ class APIServiceViewSet(viewsets.ModelViewSet): ...@@ -105,7 +104,7 @@ class APIServiceViewSet(viewsets.ModelViewSet):
except Exception as e: except Exception as e:
message = status_message_response(500, 'failed', 'Request was not able to process' + str(e), []) message = status_message_response(500, 'failed', 'Request was not able to process' + str(e), [])
return Response(message, status=status.HTTP_500_INTERNAL_SERVER_ERROR) return Response(message, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
# PATCH - RESTORE archived service # PATCH - RESTORE archived service
...@@ -122,14 +121,14 @@ class APIServiceViewSet(viewsets.ModelViewSet): ...@@ -122,14 +121,14 @@ class APIServiceViewSet(viewsets.ModelViewSet):
except Exception as e: except Exception as e:
message = status_message_response(500, 'failed', 'Request was not able to process' + str(e), []) message = status_message_response(500, 'failed', 'Request was not able to process' + str(e), [])
return Response(message, status=status.HTTP_500_INTERNAL_SERVER_ERROR) return Response(message, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
# /archived - show list of archived services # /archived - show list of archived services
@action(methods=["GET"], detail=False) @action(methods=["GET"], detail=False)
def archived(self, request, pk=None): def archived(self, request, pk=None):
try: try:
queryset = APIService.objects.filter(deleted_at__isnull=False) queryset = APIService.objects.filter(deleted_at__isnull=False)
if not queryset.exists(): if not queryset.exists():
message = status_message_response(200, 'success', 'No archived services', []) message = status_message_response(200, 'success', 'No archived services', [])
return Response(message) return Response(message)
...@@ -154,7 +153,7 @@ class APIServiceViewSet(viewsets.ModelViewSet): ...@@ -154,7 +153,7 @@ class APIServiceViewSet(viewsets.ModelViewSet):
def endpoints(self, request, pk): def endpoints(self, request, pk):
try: try:
endpoints = APIEndpoint.objects.filter(service=pk) endpoints = APIEndpoint.objects.filter(service=pk)
page = self.paginate_queryset(endpoints) page = self.paginate_queryset(endpoints)
if page is not None: if page is not None:
serializer = APIEndpointSerializer(page, many=True) serializer = APIEndpointSerializer(page, many=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