Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
R
red-ci-cd
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
red-group-test
red-ci-cd
Commits
76dfa862
Commit
76dfa862
authored
Jun 19, 2019
by
Ristylou Dolar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Application theme not required. Set default. Removed extra spaces and lines.
parent
0708dab4
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
185 additions
and
70 deletions
+185
-70
api/models.py
api/models.py
+1
-1
api/serializers.py
api/serializers.py
+21
-9
api/urls.py
api/urls.py
+3
-1
api/utils.py
api/utils.py
+5
-3
api/viewsets/applications.py
api/viewsets/applications.py
+0
-2
api/viewsets/endpoints.py
api/viewsets/endpoints.py
+73
-26
api/viewsets/services.py
api/viewsets/services.py
+82
-28
No files found.
api/models.py
View file @
76dfa862
...
@@ -5,7 +5,7 @@ from django.utils import timezone
...
@@ -5,7 +5,7 @@ from django.utils import timezone
class
Application
(
models
.
Model
):
class
Application
(
models
.
Model
):
application_no
=
models
.
CharField
(
max_length
=
250
)
application_no
=
models
.
CharField
(
max_length
=
250
)
name
=
models
.
CharField
(
max_length
=
200
,
unique
=
True
)
name
=
models
.
CharField
(
max_length
=
200
,
unique
=
True
)
theme
=
models
.
IntegerField
(
null
=
True
,
blank
=
True
,
default
=
1
)
theme
=
models
.
IntegerField
(
blank
=
True
,
default
=
1
)
code
=
models
.
CharField
(
max_length
=
300
)
code
=
models
.
CharField
(
max_length
=
300
)
created_at
=
models
.
DateTimeField
(
auto_now_add
=
True
)
created_at
=
models
.
DateTimeField
(
auto_now_add
=
True
)
updated_at
=
models
.
DateTimeField
(
auto_now
=
True
)
updated_at
=
models
.
DateTimeField
(
auto_now
=
True
)
...
...
api/serializers.py
View file @
76dfa862
...
@@ -46,7 +46,7 @@ class ApplicationSerializer(serializers.ModelSerializer):
...
@@ -46,7 +46,7 @@ class ApplicationSerializer(serializers.ModelSerializer):
else
:
else
:
self
.
_errors
=
{}
self
.
_errors
=
{}
#if validation failed
#
if validation failed
if
self
.
_errors
and
raise_exception
:
if
self
.
_errors
and
raise_exception
:
error_message
=
{}
error_message
=
{}
message
=
str
(
self
.
errors
)
message
=
str
(
self
.
errors
)
...
@@ -66,7 +66,9 @@ class ApplicationSerializer(serializers.ModelSerializer):
...
@@ -66,7 +66,9 @@ class ApplicationSerializer(serializers.ModelSerializer):
def
create
(
self
,
validated_data
):
def
create
(
self
,
validated_data
):
new_application
=
Application
.
objects
.
create
(
**
validated_data
)
new_application
=
Application
.
objects
.
create
(
**
validated_data
)
new_application
.
application_no
=
number_generator
(
'APP'
,
new_application
.
id
)
new_application
.
application_no
=
number_generator
(
'APP'
,
new_application
.
id
)
new_application
.
save
()
new_application
.
save
()
return
new_application
return
new_application
...
@@ -74,8 +76,15 @@ class ApplicationSerializer(serializers.ModelSerializer):
...
@@ -74,8 +76,15 @@ class ApplicationSerializer(serializers.ModelSerializer):
class
APIServiceSerializer
(
serializers
.
ModelSerializer
):
class
APIServiceSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
class
Meta
:
model
=
APIService
model
=
APIService
fields
=
(
'id'
,
'api_service_no'
,
'name'
,
'service_token'
,
'base_url'
,
'service_url'
,
'application'
,
'created_at'
,
'updated_at'
,
'deleted_at'
)
fields
=
(
read_only_fields
=
(
'id'
,
'api_service_no'
,
'service_token'
,
'created_at'
,
'updated_at'
,
'deleted_at'
)
'id'
,
'api_service_no'
,
'name'
,
'service_token'
,
'base_url'
,
'service_url'
,
'application'
,
'created_at'
,
'updated_at'
,
'deleted_at'
)
read_only_fields
=
(
'id'
,
'api_service_no'
,
'service_token'
,
'created_at'
,
'updated_at'
,
'deleted_at'
)
def
is_valid
(
self
,
raise_exception
=
False
):
def
is_valid
(
self
,
raise_exception
=
False
):
...
@@ -100,7 +109,7 @@ class APIServiceSerializer(serializers.ModelSerializer):
...
@@ -100,7 +109,7 @@ class APIServiceSerializer(serializers.ModelSerializer):
else
:
else
:
self
.
_errors
=
{}
self
.
_errors
=
{}
#if validation failed
#
if validation failed
if
self
.
_errors
and
raise_exception
:
if
self
.
_errors
and
raise_exception
:
error_message
=
{}
error_message
=
{}
message
=
str
(
self
.
errors
)
message
=
str
(
self
.
errors
)
...
@@ -131,10 +140,13 @@ class APIEndpointSerializer(serializers.ModelSerializer):
...
@@ -131,10 +140,13 @@ class APIEndpointSerializer(serializers.ModelSerializer):
class
Meta
:
class
Meta
:
model
=
APIEndpoint
model
=
APIEndpoint
fields
=
(
fields
=
(
'id'
,
'api_endpoint_no'
,
'service'
,
'service_name'
,
'name'
,
'description'
,
'id'
,
'api_endpoint_no'
,
'service'
,
'service_name'
,
'name'
,
'http_method'
,
'endpoint_url'
,
'is_need_auth'
,
'is_active'
,
'created_at'
,
'updated_at'
,
'deleted_at'
'description'
,
'http_method'
,
'endpoint_url'
,
'is_need_auth'
,
'is_active'
,
'created_at'
,
'updated_at'
,
'deleted_at'
)
read_only_fields
=
(
'id'
,
'api_endpoint_no'
,
'created_at'
,
'updated_at'
,
'deleted_at'
)
)
read_only_fields
=
(
'id'
,
'api_endpoint_no'
,
'created_at'
,
'updated_at'
,
'deleted_at'
)
def
is_valid
(
self
,
raise_exception
=
False
):
def
is_valid
(
self
,
raise_exception
=
False
):
...
@@ -159,7 +171,7 @@ class APIEndpointSerializer(serializers.ModelSerializer):
...
@@ -159,7 +171,7 @@ class APIEndpointSerializer(serializers.ModelSerializer):
else
:
else
:
self
.
_errors
=
{}
self
.
_errors
=
{}
#if validation failed
#
if validation failed
if
self
.
_errors
and
raise_exception
:
if
self
.
_errors
and
raise_exception
:
error_message
=
{}
error_message
=
{}
message
=
str
(
self
.
errors
)
message
=
str
(
self
.
errors
)
...
...
api/urls.py
View file @
76dfa862
...
@@ -2,7 +2,9 @@ from django.urls import path, include
...
@@ -2,7 +2,9 @@ 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
,
MainApplicationViewSet
from
api.viewsets.applications
import
(
ApplicationViewSet
,
MainApplicationViewSet
)
from
api.views
import
(
from
api.views
import
(
APIGatewayList
,
APIGatewaySlugDetail
,
APIGatewaySlugModelDetail
APIGatewayList
,
APIGatewaySlugDetail
,
APIGatewaySlugModelDetail
)
)
...
...
api/utils.py
View file @
76dfa862
...
@@ -119,9 +119,11 @@ class Helper:
...
@@ -119,9 +119,11 @@ class Helper:
return
self
.
_request_method
(
request
,
final_endpoint
,
return
self
.
_request_method
(
request
,
final_endpoint
,
self
.
_headers
)
self
.
_headers
)
else
:
else
:
return
self
.
_response_data
({
'message'
:
'Invalid'
},
return
self
.
_response_data
(
status
.
HTTP_500_INTERNAL_SERVER_ERROR
,
{
'message'
:
'Invalid'
},
self
.
_headers
)
status
.
HTTP_500_INTERNAL_SERVER_ERROR
,
self
.
_headers
)
except
APIEndpoint
.
DoesNotExist
:
except
APIEndpoint
.
DoesNotExist
:
raise
Http404
raise
Http404
except
Exception
as
e
:
except
Exception
as
e
:
...
...
api/viewsets/applications.py
View file @
76dfa862
...
@@ -161,7 +161,6 @@ class ApplicationViewSet(viewsets.ModelViewSet):
...
@@ -161,7 +161,6 @@ class ApplicationViewSet(viewsets.ModelViewSet):
return
Response
(
message
,
return
Response
(
message
,
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
# PATCH - RESTORE archived application
# PATCH - RESTORE archived application
def
partial_update
(
self
,
request
,
*
args
,
**
kwargs
):
def
partial_update
(
self
,
request
,
*
args
,
**
kwargs
):
try
:
try
:
...
@@ -184,7 +183,6 @@ class ApplicationViewSet(viewsets.ModelViewSet):
...
@@ -184,7 +183,6 @@ class ApplicationViewSet(viewsets.ModelViewSet):
return
Response
(
message
,
return
Response
(
message
,
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
# /archived - show list of archived application
# /archived - show list of archived application
@
action
(
methods
=
[
"GET"
],
detail
=
False
)
@
action
(
methods
=
[
"GET"
],
detail
=
False
)
def
archived
(
self
,
request
,
pk
=
None
):
def
archived
(
self
,
request
,
pk
=
None
):
...
...
api/viewsets/endpoints.py
View file @
76dfa862
...
@@ -28,7 +28,10 @@ class APIEndpointViewSet(viewsets.ModelViewSet):
...
@@ -28,7 +28,10 @@ class APIEndpointViewSet(viewsets.ModelViewSet):
serializer
.
is_valid
(
raise_exception
=
True
)
serializer
.
is_valid
(
raise_exception
=
True
)
self
.
perform_create
(
serializer
)
self
.
perform_create
(
serializer
)
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
:
...
@@ -36,8 +39,12 @@ class APIEndpointViewSet(viewsets.ModelViewSet):
...
@@ -36,8 +39,12 @@ class APIEndpointViewSet(viewsets.ModelViewSet):
return
Response
(
message
,
status
=
status
.
HTTP_400_BAD_REQUEST
)
return
Response
(
message
,
status
=
status
.
HTTP_400_BAD_REQUEST
)
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
(
return
Response
(
message
,
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
500
,
'failed'
,
'Request was not able to process'
+
str
(
e
),
[]
)
return
Response
(
message
,
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
# SHOW LIST of endpoints
# SHOW LIST of endpoints
def
list
(
self
,
request
,
*
args
,
**
kwargs
):
def
list
(
self
,
request
,
*
args
,
**
kwargs
):
...
@@ -45,7 +52,9 @@ class APIEndpointViewSet(viewsets.ModelViewSet):
...
@@ -45,7 +52,9 @@ class APIEndpointViewSet(viewsets.ModelViewSet):
queryset
=
APIEndpoint
.
objects
.
filter
(
deleted_at__exact
=
None
)
queryset
=
APIEndpoint
.
objects
.
filter
(
deleted_at__exact
=
None
)
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
)
...
@@ -60,8 +69,12 @@ class APIEndpointViewSet(viewsets.ModelViewSet):
...
@@ -60,8 +69,12 @@ class APIEndpointViewSet(viewsets.ModelViewSet):
return
self
.
get_paginated_response
(
message
)
return
self
.
get_paginated_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
(
return
Response
(
message
,
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
500
,
'failed'
,
'Request was not able to process'
+
str
(
e
),
[]
)
return
Response
(
message
,
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
# SHOW endpoint details
# SHOW endpoint details
def
retrieve
(
self
,
request
,
*
args
,
**
kwargs
):
def
retrieve
(
self
,
request
,
*
args
,
**
kwargs
):
...
@@ -71,47 +84,69 @@ class APIEndpointViewSet(viewsets.ModelViewSet):
...
@@ -71,47 +84,69 @@ class APIEndpointViewSet(viewsets.ModelViewSet):
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
(
return
Response
(
message
,
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
500
,
'failed'
,
'Request was not able to process'
+
str
(
e
),
[]
)
return
Response
(
message
,
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
# UPDATE endpoint
# UPDATE endpoint
def
update
(
self
,
request
,
*
args
,
**
kwargs
):
def
update
(
self
,
request
,
*
args
,
**
kwargs
):
try
:
try
:
partial
=
kwargs
.
pop
(
'partial'
,
False
)
partial
=
kwargs
.
pop
(
'partial'
,
False
)
instance
=
self
.
get_object
()
instance
=
self
.
get_object
()
serializer
=
self
.
get_serializer
(
instance
,
data
=
request
.
data
,
partial
=
partial
)
serializer
=
self
.
get_serializer
(
instance
,
data
=
request
.
data
,
partial
=
partial
)
serializer
.
is_valid
(
raise_exception
=
True
)
serializer
.
is_valid
(
raise_exception
=
True
)
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
(
return
Response
(
message
,
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
500
,
'failed'
,
'Request was not able to process'
+
str
(
e
),
[]
)
return
Response
(
message
,
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
# SOFT DELETE / ARCHIVED
# SOFT DELETE / ARCHIVED
def
destroy
(
self
,
request
,
*
args
,
**
kwargs
):
def
destroy
(
self
,
request
,
*
args
,
**
kwargs
):
try
:
try
:
instance
=
self
.
get_object
()
instance
=
self
.
get_object
()
self
.
perform_destroy
(
instance
)
self
.
perform_destroy
(
instance
)
message
=
status_message_response
(
message
=
status_message_response
(
200
,
'success'
,
'Endpoint deleted'
,
[])
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
(
return
Response
(
message
,
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
500
,
'failed'
,
'Request was not able to process'
+
str
(
e
),
[]
)
return
Response
(
message
,
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
# PATCH - RESTORE archived endpoint
# PATCH - RESTORE archived endpoint
def
partial_update
(
self
,
request
,
*
args
,
**
kwargs
):
def
partial_update
(
self
,
request
,
*
args
,
**
kwargs
):
...
@@ -120,14 +155,20 @@ class APIEndpointViewSet(viewsets.ModelViewSet):
...
@@ -120,14 +155,20 @@ class APIEndpointViewSet(viewsets.ModelViewSet):
instance
=
self
.
get_object
()
instance
=
self
.
get_object
()
instance
.
deleted_at
=
None
instance
.
deleted_at
=
None
serializer
=
self
.
get_serializer
(
instance
)
serializer
=
self
.
get_serializer
(
instance
)
message
=
status_message_response
(
200
,
'success'
,
'Archived endpoint restored'
,
serializer
.
data
)
message
=
status_message_response
(
200
,
'success'
,
'Archived endpoint restored'
,
serializer
.
data
)
instance
.
save
()
instance
.
save
()
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
(
return
Response
(
message
,
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
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
# /archived - show list of archived endpoints
@
action
(
methods
=
[
"GET"
],
detail
=
False
)
@
action
(
methods
=
[
"GET"
],
detail
=
False
)
...
@@ -136,7 +177,9 @@ class APIEndpointViewSet(viewsets.ModelViewSet):
...
@@ -136,7 +177,9 @@ class APIEndpointViewSet(viewsets.ModelViewSet):
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
)
page
=
self
.
paginate_queryset
(
queryset
)
page
=
self
.
paginate_queryset
(
queryset
)
...
@@ -151,5 +194,9 @@ class APIEndpointViewSet(viewsets.ModelViewSet):
...
@@ -151,5 +194,9 @@ class APIEndpointViewSet(viewsets.ModelViewSet):
return
self
.
get_paginated_response
(
message
)
return
self
.
get_paginated_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
(
return
Response
(
message
,
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
500
,
'failed'
,
'Request was not able to process'
+
str
(
e
),
[]
)
return
Response
(
message
,
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
api/viewsets/services.py
View file @
76dfa862
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment