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
25c3b2ec
Commit
25c3b2ec
authored
Jun 20, 2019
by
Ristylou Dolar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved auto-generated number create from serializers to viewsets
parent
033f710d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
42 deletions
+45
-42
api/serializers.py
api/serializers.py
+1
-24
api/viewsets/applications.py
api/viewsets/applications.py
+15
-6
api/viewsets/endpoints.py
api/viewsets/endpoints.py
+14
-7
api/viewsets/services.py
api/viewsets/services.py
+15
-5
No files found.
api/serializers.py
View file @
25c3b2ec
from
rest_framework
import
serializers
from
.models
import
APIService
,
APIEndpoint
,
Application
from
api.utils
import
BadRequestException
,
number_generator
from
api.utils
import
BadRequestException
from
rest_framework.exceptions
import
ValidationError
from
django.utils.crypto
import
get_random_string
class
GroupDependentSerializer
(
serializers
.
ModelSerializer
):
...
...
@@ -63,15 +62,6 @@ class ApplicationSerializer(serializers.ModelSerializer):
return
not
bool
(
self
.
_errors
)
def
create
(
self
,
validated_data
):
new_application
=
Application
.
objects
.
create
(
**
validated_data
)
new_application
.
application_no
=
number_generator
(
'APP'
,
new_application
.
id
)
new_application
.
save
()
return
new_application
class
APIServiceSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
...
...
@@ -126,13 +116,6 @@ class APIServiceSerializer(serializers.ModelSerializer):
return
not
bool
(
self
.
_errors
)
def
create
(
self
,
validated_data
):
new_service
=
APIService
.
objects
.
create
(
**
validated_data
)
new_service
.
api_service_no
=
number_generator
(
'SVC'
,
new_service
.
id
)
new_service
.
service_token
=
get_random_string
(
length
=
16
)
new_service
.
save
()
return
new_service
class
APIEndpointSerializer
(
serializers
.
ModelSerializer
):
service_name
=
serializers
.
ReadOnlyField
(
source
=
'service.name'
)
...
...
@@ -187,9 +170,3 @@ class APIEndpointSerializer(serializers.ModelSerializer):
raise
BadRequestException
(
error_message
)
return
not
bool
(
self
.
_errors
)
def
create
(
self
,
validated_data
):
new_endpoint
=
APIEndpoint
.
objects
.
create
(
**
validated_data
)
new_endpoint
.
api_endpoint_no
=
number_generator
(
'ENP'
,
new_endpoint
.
id
)
new_endpoint
.
save
()
return
new_endpoint
api/viewsets/applications.py
View file @
25c3b2ec
...
...
@@ -5,8 +5,10 @@ from rest_framework.decorators import action
from
rest_framework.response
import
Response
from
api.models
import
Application
from
api.serializers
import
ApplicationSerializer
,
GroupDependentSerializer
from
api.utils
import
(
CustomPagination
,
BadRequestException
,
status_message_response
)
from
api.utils
import
(
CustomPagination
,
BadRequestException
,
status_message_response
,
number_generator
)
AUTHENTICATOR_GROUP
=
settings
.
AUTHENTICATOR_GROUP
...
...
@@ -26,7 +28,14 @@ class ApplicationViewSet(viewsets.ModelViewSet):
try
:
serializer
=
self
.
get_serializer
(
data
=
request
.
data
)
serializer
.
is_valid
(
raise_exception
=
True
)
self
.
perform_create
(
serializer
)
app_create
=
serializer
.
save
()
# for application_no
app_id
=
app_create
.
pk
app_create
.
application_no
=
number_generator
(
'APP'
,
app_id
)
app_create
.
save
()
message
=
status_message_response
(
201
,
'success'
,
...
...
@@ -94,9 +103,9 @@ class ApplicationViewSet(viewsets.ModelViewSet):
def
retrieve
(
self
,
request
,
*
args
,
**
kwargs
):
try
:
id
=
self
.
kwargs
[
'pk'
]
instance
=
Application
.
objects
.
get
(
id
=
id
)
instance
=
Application
.
objects
.
get
(
id
=
id
)
serializer
=
self
.
get_serializer
(
instance
)
message
=
status_message_response
(
200
,
'success'
,
'Application retrieved'
,
serializer
.
data
...
...
@@ -110,7 +119,7 @@ class ApplicationViewSet(viewsets.ModelViewSet):
except
Exception
as
e
:
message
=
status_message_response
(
500
,
'failed'
,
500
,
'failed'
,
'Request was not able to process'
+
str
(
e
),
[]
)
return
Response
(
message
,
...
...
api/viewsets/endpoints.py
View file @
25c3b2ec
...
...
@@ -4,9 +4,9 @@ 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
)
APIEndpointFilter
,
CustomPagination
,
BadRequestException
,
status_message_response
,
number_generator
)
from
django_filters.rest_framework
import
DjangoFilterBackend
...
...
@@ -26,7 +26,14 @@ class APIEndpointViewSet(viewsets.ModelViewSet):
try
:
serializer
=
self
.
get_serializer
(
data
=
request
.
data
)
serializer
.
is_valid
(
raise_exception
=
True
)
self
.
perform_create
(
serializer
)
endpoint_create
=
serializer
.
save
()
# for endpoint_no
endpoint_id
=
endpoint_create
.
pk
endpoint_create
.
api_endpoint_no
=
number_generator
(
'ENP'
,
endpoint_id
)
endpoint_create
.
save
()
message
=
status_message_response
(
201
,
'success'
,
...
...
@@ -80,9 +87,9 @@ class APIEndpointViewSet(viewsets.ModelViewSet):
def
retrieve
(
self
,
request
,
*
args
,
**
kwargs
):
try
:
id
=
self
.
kwargs
[
'pk'
]
instance
=
APIEndpoint
.
objects
.
get
(
id
=
id
)
instance
=
APIEndpoint
.
objects
.
get
(
id
=
id
)
serializer
=
self
.
get_serializer
(
instance
)
message
=
status_message_response
(
200
,
'success'
,
'Endpoint retrieved'
,
serializer
.
data
...
...
@@ -96,7 +103,7 @@ class APIEndpointViewSet(viewsets.ModelViewSet):
except
Exception
as
e
:
message
=
status_message_response
(
500
,
'failed'
,
500
,
'failed'
,
'Request was not able to process'
+
str
(
e
),
[]
)
return
Response
(
message
,
...
...
api/viewsets/services.py
View file @
25c3b2ec
...
...
@@ -4,8 +4,10 @@ from rest_framework.response import Response
from
api.models
import
APIService
from
api.serializers
import
APIServiceSerializer
from
api.utils
import
(
CustomPagination
,
BadRequestException
,
status_message_response
CustomPagination
,
BadRequestException
,
status_message_response
,
number_generator
)
from
django.utils.crypto
import
get_random_string
class
APIServiceViewSet
(
viewsets
.
ModelViewSet
):
...
...
@@ -22,7 +24,15 @@ class APIServiceViewSet(viewsets.ModelViewSet):
try
:
serializer
=
self
.
get_serializer
(
data
=
request
.
data
)
serializer
.
is_valid
(
raise_exception
=
True
)
self
.
perform_create
(
serializer
)
service_create
=
serializer
.
save
()
# for service_no
service_id
=
service_create
.
pk
service_create
.
api_service_no
=
number_generator
(
'SVC'
,
service_id
)
service_create
.
service_token
=
get_random_string
(
length
=
16
)
service_create
.
save
()
message
=
status_message_response
(
201
,
'success'
,
...
...
@@ -76,9 +86,9 @@ class APIServiceViewSet(viewsets.ModelViewSet):
def
retrieve
(
self
,
request
,
*
args
,
**
kwargs
):
try
:
id
=
self
.
kwargs
[
'pk'
]
instance
=
APIService
.
objects
.
get
(
id
=
id
)
instance
=
APIService
.
objects
.
get
(
id
=
id
)
serializer
=
self
.
get_serializer
(
instance
)
message
=
status_message_response
(
200
,
'success'
,
'Service retrieved'
,
serializer
.
data
...
...
@@ -92,7 +102,7 @@ class APIServiceViewSet(viewsets.ModelViewSet):
except
Exception
as
e
:
message
=
status_message_response
(
500
,
'failed'
,
500
,
'failed'
,
'Request was not able to process'
+
str
(
e
),
[]
)
return
Response
(
message
,
...
...
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