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
from rest_framework.routers import DefaultRouter
from api.viewsets.services import APIServiceViewSet
from api.viewsets.endpoints import APIEndpointViewSet
from api.viewsets.applications import ApplicationViewSet, GroupDependentViewSet
from api.viewsets.applications import ApplicationViewSet, MainApplicationViewSet
from api.views import (
APIGatewayList, APIGatewaySlugDetail, APIGatewaySlugModelDetail
)
......@@ -10,8 +10,8 @@ from api.views import (
router = DefaultRouter()
router.register(r'applications', ApplicationViewSet)
router.register(r'services', APIServiceViewSet)
router.register(r'endpoint', APIEndpointViewSet)
router.register(r'group-dependent', GroupDependentViewSet)
router.register(r'endpoints', APIEndpointViewSet)
router.register(r'main-application', MainApplicationViewSet)
urlpatterns = [
path('', include(router.urls)),
......
......@@ -9,7 +9,6 @@ from .models import APIEndpoint
from rest_framework.pagination import PageNumberPagination
from rest_framework.response import Response
import datetime
from functools import wraps
VALIDATE_TOKEN_URL = settings.VALIDATE_TOKEN_URL
......
......@@ -50,11 +50,17 @@ class ApplicationViewSet(viewsets.ModelViewSet):
def list(self, request, *args, **kwargs):
try:
queryset = Application.objects.filter(deleted_at__exact=None)
ids = self.request.query_params.get(
'ids', None
)
if not queryset.exists():
message = status_message_response(
200, 'success', 'No records found', []
)
return Response(message)
if ids is not None:
ids = ids.split(',')
queryset = queryset.filter(id__in=ids)
page = self.paginate_queryset(queryset)
if page is not None:
......@@ -237,15 +243,6 @@ class ApplicationViewSet(viewsets.ModelViewSet):
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
class GroupDependentViewSet(viewsets.ModelViewSet):
class MainApplicationViewSet(viewsets.ModelViewSet):
queryset = Application.objects.all()
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
from rest_framework.response import Response
from api.models import APIEndpoint
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
......@@ -24,11 +27,10 @@ class APIEndpointViewSet(viewsets.ModelViewSet):
serializer = self.get_serializer(data=request.data)
serializer.is_valid(raise_exception=True)
self.perform_create(serializer)
headers = self.get_success_headers(serializer.data)
message = status_message_response(201, 'success', 'New endpoint created', serializer.data)
return Response(message)
except BadRequestException as e:
message = status_message_response(400, 'failed', str(e), [])
return Response(message, status=status.HTTP_400_BAD_REQUEST)
......@@ -45,7 +47,7 @@ class APIEndpointViewSet(viewsets.ModelViewSet):
if not queryset.exists():
message = status_message_response(200, 'success', 'No records found', [])
return Response(message)
page = self.paginate_queryset(queryset)
if page is not None:
serializer = self.get_serializer(page, many=True)
......@@ -67,14 +69,14 @@ class APIEndpointViewSet(viewsets.ModelViewSet):
id = self.kwargs['pk']
queryset = APIEndpoint.objects.filter(id=id)
serializer = self.get_serializer(queryset, many=True)
if not queryset.exists():
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', 'Endpoint retrieved', serializer.data)
return Response(message, status=status.HTTP_200_OK)
except Exception as 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)
......@@ -89,10 +91,10 @@ class APIEndpointViewSet(viewsets.ModelViewSet):
self.perform_update(serializer)
if getattr(instance, '_prefetched_objects_cache', None):
instance._prefetched_objects_cache = {}
message = status_message_response(200, 'success', 'Endpoint updated', serializer.data)
return Response(message)
except Exception as 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)
......@@ -102,13 +104,13 @@ class APIEndpointViewSet(viewsets.ModelViewSet):
try:
instance = self.get_object()
self.perform_destroy(instance)
message = status_message_response(200, 'success', 'Endpoint deleted', [])
return Response(message, status=status.HTTP_200_OK)
except Exception as 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
......@@ -125,14 +127,14 @@ class APIEndpointViewSet(viewsets.ModelViewSet):
except Exception as 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)
# /archived - show list of archived endpoints
@action(methods=["GET"], detail=False)
def archived(self, request, pk=None):
try:
queryset = APIEndpoint.objects.filter(deleted_at__isnull=False)
if not queryset.exists():
message = status_message_response(200, 'success', 'No archived endpoints', [])
return Response(message)
......
......@@ -21,11 +21,10 @@ class APIServiceViewSet(viewsets.ModelViewSet):
serializer = self.get_serializer(data=request.data)
serializer.is_valid(raise_exception=True)
self.perform_create(serializer)
headers = self.get_success_headers(serializer.data)
message = status_message_response(201, 'success', 'New service created', serializer.data)
return Response(message)
except BadRequestException as e:
message = status_message_response(400, 'failed', str(e), [])
return Response(message, status=status.HTTP_400_BAD_REQUEST)
......@@ -42,7 +41,7 @@ class APIServiceViewSet(viewsets.ModelViewSet):
if not queryset.exists():
message = status_message_response(200, 'success', 'No records found', [])
return Response(message)
page = self.paginate_queryset(queryset)
if page is not None:
serializer = self.get_serializer(page, many=True)
......@@ -71,7 +70,7 @@ class APIServiceViewSet(viewsets.ModelViewSet):
else:
message = status_message_response(200, 'success', 'Service retrieved', serializer.data)
return Response(message, status=status.HTTP_200_OK)
except Exception as 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)
......@@ -86,10 +85,10 @@ class APIServiceViewSet(viewsets.ModelViewSet):
self.perform_update(serializer)
if getattr(instance, '_prefetched_objects_cache', None):
instance._prefetched_objects_cache = {}
message = status_message_response(200, 'success', 'Service updated', serializer.data)
return Response(message)
except Exception as 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)
......@@ -105,7 +104,7 @@ class APIServiceViewSet(viewsets.ModelViewSet):
except Exception as 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
......@@ -122,14 +121,14 @@ class APIServiceViewSet(viewsets.ModelViewSet):
except Exception as 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)
# /archived - show list of archived services
@action(methods=["GET"], detail=False)
def archived(self, request, pk=None):
try:
queryset = APIService.objects.filter(deleted_at__isnull=False)
if not queryset.exists():
message = status_message_response(200, 'success', 'No archived services', [])
return Response(message)
......@@ -154,7 +153,7 @@ class APIServiceViewSet(viewsets.ModelViewSet):
def endpoints(self, request, pk):
try:
endpoints = APIEndpoint.objects.filter(service=pk)
page = self.paginate_queryset(endpoints)
if page is not None:
serializer = APIEndpointSerializer(page, many=True)
......
......@@ -32,5 +32,5 @@ DATABASES = {
AUTHENTICATOR_IP = config['SERVICE']['AUTHENTICATOR_IP']
AUTHENTICATOR_PATH = '/api/v1/authenticator'
VALIDATE_TOKEN_URL = f'http://{AUTHENTICATOR_IP}{AUTHENTICATOR_PATH}/validate-token/'
ACCOUNT_GROUP = f'http://{AUTHENTICATOR_IP}{AUTHENTICATOR_PATH}/application-dependent'
VALIDATE_TOKEN_URL = f'http://{AUTHENTICATOR_IP}{AUTHENTICATOR_PATH}/authenticator-validate-token/'
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