Commit 884a930d authored by Gladys Forte's avatar Gladys Forte

Merge branch 'dev' of http://42.61.118.105:7990/scm/rms/api-main-service into gladys-develop

parents d1b9d732 5418bf4e
...@@ -10,6 +10,7 @@ from rest_framework.pagination import PageNumberPagination ...@@ -10,6 +10,7 @@ from rest_framework.pagination import PageNumberPagination
from rest_framework.response import Response from rest_framework.response import Response
import datetime import datetime
from django.db.models.functions import Lower from django.db.models.functions import Lower
import copy
VALIDATE_TOKEN_URL = settings.VALIDATE_TOKEN_URL VALIDATE_TOKEN_URL = settings.VALIDATE_TOKEN_URL
...@@ -46,16 +47,33 @@ class Helper: ...@@ -46,16 +47,33 @@ class Helper:
req.status_code, req.status_code,
self._headers) self._headers)
elif request.method == 'POST': elif request.method == 'POST':
data = request.data
data = copy.deepcopy(request.data)
filesBody = {}
if not request.FILES == {}:
for fileKey in request.FILES.keys():
filesBody[fileKey] = data[fileKey]
data.pop(fileKey, None)
# Content type will be set to default
# as MultiPart when files header is
# not empty
headers.pop('Content-Type', None)
json_body = data
else:
json_body = json.dumps(data) json_body = json.dumps(data)
req = requests.post( req = requests.post(
final_endpoint, final_endpoint,
data=json_body, data=json_body,
headers=headers headers=headers,
files=filesBody
) )
return self._response_data(req.json(), return self._response_data(req.json(),
req.status_code, req.status_code,
self._headers) self._headers)
elif request.method == 'PUT': elif request.method == 'PUT':
data = request.data data = request.data
json_body = json.dumps(data) json_body = json.dumps(data)
...@@ -96,6 +114,7 @@ class Helper: ...@@ -96,6 +114,7 @@ class Helper:
base_url = endpoint.service.base_url base_url = endpoint.service.base_url
full_path = request.get_full_path() full_path = request.get_full_path()
final_endpoint = f"{base_url}{full_path}" final_endpoint = f"{base_url}{full_path}"
# print(final_endpoint)
if endpoint.is_need_auth is True: if endpoint.is_need_auth is True:
# redirect to authenticator service # redirect to authenticator service
......
...@@ -9,13 +9,22 @@ from api.utils import ( ...@@ -9,13 +9,22 @@ from api.utils import (
CustomPagination, BadRequestException, CustomPagination, BadRequestException,
status_message_response, number_generator, tbl_ordering status_message_response, number_generator, tbl_ordering
) )
from django_filters.rest_framework import DjangoFilterBackend from django_filters.rest_framework import DjangoFilterBackend
from rest_framework.filters import SearchFilter from rest_framework.filters import SearchFilter
from django_filters import rest_framework as filters
AUTHENTICATOR_GROUP = settings.AUTHENTICATOR_GROUP AUTHENTICATOR_GROUP = settings.AUTHENTICATOR_GROUP
class ApplicationFilterSet(filters.FilterSet):
class Meta:
model = Application
fields = ('__all__')
class ApplicationViewSet(viewsets.ModelViewSet): class ApplicationViewSet(viewsets.ModelViewSet):
http_method_names = [ http_method_names = [
'get', 'post', 'put', 'patch', 'delete', 'head', 'options', 'trace' 'get', 'post', 'put', 'patch', 'delete', 'head', 'options', 'trace'
...@@ -25,6 +34,7 @@ class ApplicationViewSet(viewsets.ModelViewSet): ...@@ -25,6 +34,7 @@ class ApplicationViewSet(viewsets.ModelViewSet):
serializer_class = ApplicationSerializer serializer_class = ApplicationSerializer
pagination_class = CustomPagination pagination_class = CustomPagination
filter_backends = (DjangoFilterBackend, SearchFilter,) filter_backends = (DjangoFilterBackend, SearchFilter,)
filterset_class = ApplicationFilterSet
search_fields = ('application_no', 'name', 'code') search_fields = ('application_no', 'name', 'code')
# filter_class = APIEndpointFilter # filter_class = APIEndpointFilter
...@@ -70,7 +80,7 @@ class ApplicationViewSet(viewsets.ModelViewSet): ...@@ -70,7 +80,7 @@ class ApplicationViewSet(viewsets.ModelViewSet):
) )
# table ordering # table ordering
if 'sort_field' and 'sort_order' in request.query_params: if 'sort_order' in request.query_params and 'sort_field' in request.query_params:
queryset = tbl_ordering( queryset = tbl_ordering(
queryset, **request.query_params queryset, **request.query_params
) )
...@@ -91,17 +101,17 @@ class ApplicationViewSet(viewsets.ModelViewSet): ...@@ -91,17 +101,17 @@ class ApplicationViewSet(viewsets.ModelViewSet):
results = [] results = []
for item in serializer.data: for item in serializer.data:
# print(item['code']) # print(item['code'])
ids = item['code'] # ids = item['code']
# headers = { # headers = {
# 'content-type': 'application/json', # 'content-type': 'application/json',
# 'Authorization': request.META['HTTP_AUTHORIZATION'] # 'Authorization': request.META['HTTP_AUTHORIZATION']
# } # }
req = requests.get(f'{AUTHENTICATOR_GROUP}/{ids}/') # req = requests.get(f'{AUTHENTICATOR_GROUP}/{ids}/')
groups = req.json()['groups'] # groups = req.json()['groups']
modules = req.json()['modules'] # modules = req.json()['modules']
item['groups'] = groups # item['groups'] = groups
item['modules'] = modules # item['modules'] = modules
results.append(item) results.append(item)
message = { message = {
...@@ -217,6 +227,12 @@ class ApplicationViewSet(viewsets.ModelViewSet): ...@@ -217,6 +227,12 @@ class ApplicationViewSet(viewsets.ModelViewSet):
def archived(self, request, pk=None): def archived(self, request, pk=None):
try: try:
queryset = Application.objects.filter(deleted_at__isnull=False) queryset = Application.objects.filter(deleted_at__isnull=False)
# table ordering
if 'sort_order' in request.query_params and 'sort_field' in request.query_params:
queryset = tbl_ordering(
queryset, **request.query_params
)
queryset = self.filter_queryset(queryset)
if not queryset.exists(): if not queryset.exists():
message = status_message_response( message = status_message_response(
......
...@@ -64,7 +64,7 @@ class APIEndpointViewSet(viewsets.ModelViewSet): ...@@ -64,7 +64,7 @@ class APIEndpointViewSet(viewsets.ModelViewSet):
queryset = self.queryset.filter(deleted_at__exact=None) queryset = self.queryset.filter(deleted_at__exact=None)
# table ordering # table ordering
if 'sort_field' and 'sort_order' in request.query_params: if 'sort_order' in request.query_params and 'sort_field' in request.query_params:
queryset = tbl_ordering( queryset = tbl_ordering(
queryset, **request.query_params queryset, **request.query_params
) )
...@@ -199,6 +199,12 @@ class APIEndpointViewSet(viewsets.ModelViewSet): ...@@ -199,6 +199,12 @@ class APIEndpointViewSet(viewsets.ModelViewSet):
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)
# table ordering
if 'sort_order' in request.query_params and 'sort_field' in request.query_params:
queryset = tbl_ordering(
queryset, **request.query_params
)
queryset = self.filter_queryset(queryset)
if not queryset.exists(): if not queryset.exists():
message = status_message_response( message = status_message_response(
......
...@@ -65,7 +65,7 @@ class APIServiceViewSet(viewsets.ModelViewSet): ...@@ -65,7 +65,7 @@ class APIServiceViewSet(viewsets.ModelViewSet):
queryset = self.queryset.filter(deleted_at__exact=None) queryset = self.queryset.filter(deleted_at__exact=None)
# table ordering # table ordering
if 'sort_field' and 'sort_order' in request.query_params: if 'sort_order' in request.query_params and 'sort_field' in request.query_params:
queryset = tbl_ordering( queryset = tbl_ordering(
queryset, **request.query_params queryset, **request.query_params
) )
...@@ -201,6 +201,12 @@ class APIServiceViewSet(viewsets.ModelViewSet): ...@@ -201,6 +201,12 @@ class APIServiceViewSet(viewsets.ModelViewSet):
def archived(self, request, pk=None): def archived(self, request, pk=None):
try: try:
queryset = self.queryset.filter(deleted_at__isnull=False) queryset = self.queryset.filter(deleted_at__isnull=False)
# table ordering
if 'sort_order' in request.query_params and 'sort_field' in request.query_params:
queryset = tbl_ordering(
queryset, **request.query_params
)
queryset = self.filter_queryset(queryset) queryset = self.filter_queryset(queryset)
if not queryset.exists(): if not queryset.exists():
......
version: '3'
services:
rms_main:
build: .
command: python manage.py runserver 0.0.0.0:8000
container_name: rms_main-container
volumes:
- .:/code
ports:
- 7010:8000
networks:
rms_main_network:
ipv4_address: 172.169.70.10
networks:
rms_main_network:
driver: bridge
ipam:
config:
- subnet: 172.17.0.0/16
[PRODUCTION] [PRODUCTION]
DATABASE_ENGINE = django.db.backends.mysql DATABASE_ENGINE = django.db.backends.mysql
DATABASE_NAME = maindb DATABASE_NAME = authenticatordb
DATABASE_USER = root DATABASE_USER = root
DATABASE_PASSWORD = DATABASE_PASSWORD =
DATABASE_HOST = DATABASE_HOST =
...@@ -8,22 +8,22 @@ DATABASE_PORT = ...@@ -8,22 +8,22 @@ DATABASE_PORT =
[UAT] [UAT]
DATABASE_ENGINE = django.db.backends.mysql DATABASE_ENGINE = django.db.backends.mysql
DATABASE_NAME = maindb DATABASE_NAME = devrms_main_db
DATABASE_USER = root DATABASE_USER = oneberry
DATABASE_PASSWORD = DATABASE_PASSWORD = 0N3Berryt!r
DATABASE_HOST = DATABASE_HOST = 52.74.129.178
DATABASE_PORT = DATABASE_PORT = 3306
[LOCAL] [LOCAL]
DATABASE_ENGINE = django.db.backends.mysql DATABASE_ENGINE = django.db.backends.mysql
DATABASE_NAME = maindb DATABASE_NAME = authenticatordb
DATABASE_USER = root DATABASE_USER = root
DATABASE_PASSWORD = DATABASE_PASSWORD =
DATABASE_HOST = DATABASE_HOST =
DATABASE_PORT = DATABASE_PORT =
[SETTINGS] [SETTINGS]
CONFIG = config.settings.local CONFIG = config.settings.uat
[SERVICE] [SERVICE]
AUTHENTICATOR_IP = 10.0.75.1:8000 AUTHENTICATOR_IP = 172.17.0.1:7011
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