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
a740e8cf
Commit
a740e8cf
authored
May 15, 2019
by
Ristylou Dolar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added status response in utils, CRUD for services and endpoint models
parent
f7da0abd
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
260 additions
and
211 deletions
+260
-211
api/serializers.py
api/serializers.py
+46
-0
api/utils.py
api/utils.py
+11
-0
api/views.py
api/views.py
+202
-210
config/urls.py
config/urls.py
+1
-1
No files found.
api/serializers.py
View file @
a740e8cf
...
@@ -123,3 +123,49 @@ class APIEndpointSerializer(serializers.ModelSerializer):
...
@@ -123,3 +123,49 @@ class APIEndpointSerializer(serializers.ModelSerializer):
'http_method'
,
'endpoint_url'
,
'is_need_auth'
,
'is_active'
,
'created_at'
,
'updated_at'
,
'deleted_at'
'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
):
assert
not
hasattr
(
self
,
'restore_object'
),
(
'Serializer `
%
s.
%
s` has old-style version 2 `.restore_object()` '
'that is no longer compatible with REST framework 3. '
'Use the new-style `.create()` and `.update()` methods instead.'
%
(
self
.
__class__
.
__module__
,
self
.
__class__
.
__name__
)
)
assert
hasattr
(
self
,
'initial_data'
),
(
'Cannot call `.is_valid()` as no `data=` keyword argument was '
'passed when instantiating the serializer instance.'
)
if
not
hasattr
(
self
,
'_validated_data'
):
try
:
self
.
_validated_data
=
self
.
run_validation
(
self
.
initial_data
)
except
ValidationError
as
exc
:
self
.
_validated_data
=
{}
self
.
_errors
=
exc
.
detail
else
:
self
.
_errors
=
{}
#if validation failed
if
self
.
_errors
and
raise_exception
:
error_message
=
{}
message
=
str
(
self
.
errors
)
for
k
,
v
in
self
.
errors
.
items
():
message
=
str
(
v
)
start
=
message
.
find
(
'string='
)
+
8
end
=
message
.
find
(
', code='
)
-
1
message
=
message
[
start
:
end
]
error_message
[
str
(
k
)]
=
message
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/utils.py
View file @
a740e8cf
...
@@ -148,3 +148,14 @@ def number_generator(prefix, id):
...
@@ -148,3 +148,14 @@ def number_generator(prefix, id):
autogenerated_no
=
prefix
+
'-'
+
date
+
'-'
+
id_num
autogenerated_no
=
prefix
+
'-'
+
date
+
'-'
+
id_num
return
autogenerated_no
return
autogenerated_no
# status message
def
status_message_response
(
code
,
status
,
message
,
results
):
message
=
{
'code'
:
code
,
'status'
:
status
,
'message'
:
message
,
'results'
:
results
}
return
message
api/views.py
View file @
a740e8cf
This diff is collapsed.
Click to expand it.
config/urls.py
View file @
a740e8cf
...
@@ -20,5 +20,5 @@ swagger = get_swagger_view(title='API Main End Point')
...
@@ -20,5 +20,5 @@ swagger = get_swagger_view(title='API Main End Point')
urlpatterns
=
[
urlpatterns
=
[
path
(
'docs/'
,
swagger
),
path
(
'docs/'
,
swagger
),
path
(
''
,
include
(
'api.urls'
)),
path
(
'
api/v1/
'
,
include
(
'api.urls'
)),
]
]
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