Commit 5facf2ab authored by John Red Medrano's avatar John Red Medrano

Merge pull request #26 in RMS/api-main-service from red-develop to dev

* commit '61861cb9':
  removed unused codes
  added queryparams ids on application endpoints
parents bc67b379 61861cb9
...@@ -2,7 +2,7 @@ from django.urls import path, include ...@@ -2,7 +2,7 @@ from django.urls import path, include
from rest_framework.routers import DefaultRouter from rest_framework.routers import DefaultRouter
from api.viewsets.services import APIServiceViewSet from api.viewsets.services import APIServiceViewSet
from api.viewsets.endpoints import APIEndpointViewSet from api.viewsets.endpoints import APIEndpointViewSet
from api.viewsets.applications import ApplicationViewSet, GroupDependentViewSet from api.viewsets.applications import ApplicationViewSet, MainApplicationViewSet
from api.views import ( from api.views import (
APIGatewayList, APIGatewaySlugDetail, APIGatewaySlugModelDetail APIGatewayList, APIGatewaySlugDetail, APIGatewaySlugModelDetail
) )
...@@ -10,8 +10,8 @@ from api.views import ( ...@@ -10,8 +10,8 @@ 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'group-dependent', GroupDependentViewSet) router.register(r'main-application', MainApplicationViewSet)
urlpatterns = [ urlpatterns = [
path('', include(router.urls)), path('', include(router.urls)),
......
...@@ -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
......
...@@ -50,11 +50,17 @@ class ApplicationViewSet(viewsets.ModelViewSet): ...@@ -50,11 +50,17 @@ class ApplicationViewSet(viewsets.ModelViewSet):
def list(self, request, *args, **kwargs): def list(self, request, *args, **kwargs):
try: try:
queryset = Application.objects.filter(deleted_at__exact=None) queryset = Application.objects.filter(deleted_at__exact=None)
ids = self.request.query_params.get(
'ids', None
)
if not queryset.exists(): if not queryset.exists():
message = status_message_response( message = status_message_response(
200, 'success', 'No records found', [] 200, 'success', 'No records found', []
) )
return Response(message) return Response(message)
if ids is not None:
ids = ids.split(',')
queryset = queryset.filter(id__in=ids)
page = self.paginate_queryset(queryset) page = self.paginate_queryset(queryset)
if page is not None: if page is not None:
...@@ -237,15 +243,6 @@ class ApplicationViewSet(viewsets.ModelViewSet): ...@@ -237,15 +243,6 @@ class ApplicationViewSet(viewsets.ModelViewSet):
status=status.HTTP_500_INTERNAL_SERVER_ERROR) status=status.HTTP_500_INTERNAL_SERVER_ERROR)
class GroupDependentViewSet(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)
......
...@@ -32,5 +32,5 @@ DATABASES = { ...@@ -32,5 +32,5 @@ DATABASES = {
AUTHENTICATOR_IP = config['SERVICE']['AUTHENTICATOR_IP'] AUTHENTICATOR_IP = config['SERVICE']['AUTHENTICATOR_IP']
AUTHENTICATOR_PATH = '/api/v1/authenticator' AUTHENTICATOR_PATH = '/api/v1/authenticator'
VALIDATE_TOKEN_URL = f'http://{AUTHENTICATOR_IP}{AUTHENTICATOR_PATH}/validate-token/' VALIDATE_TOKEN_URL = f'http://{AUTHENTICATOR_IP}{AUTHENTICATOR_PATH}/authenticator-validate-token/'
ACCOUNT_GROUP = f'http://{AUTHENTICATOR_IP}{AUTHENTICATOR_PATH}/application-dependent' ACCOUNT_GROUP = f'http://{AUTHENTICATOR_IP}{AUTHENTICATOR_PATH}/authenticator-group'
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