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
f7da0abd
Commit
f7da0abd
authored
May 15, 2019
by
Ristylou Dolar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added APIServices CRUD
parent
fd14d8de
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
244 additions
and
14 deletions
+244
-14
api/views.py
api/views.py
+244
-14
No files found.
api/views.py
View file @
f7da0abd
...
...
@@ -140,7 +140,7 @@ class ApplicationViewSet(viewsets.ModelViewSet):
}
return
Response
(
message
,
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
# SOFT DELETE
# SOFT DELETE
/ ARCHIVED
def
destroy
(
self
,
request
,
*
args
,
**
kwargs
):
try
:
instance
=
self
.
get_object
()
...
...
@@ -187,7 +187,7 @@ class ApplicationViewSet(viewsets.ModelViewSet):
return
Response
(
message
,
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
# /archived - show list of archived
marital status
# /archived - show list of archived
application
@
action
(
methods
=
[
"GET"
],
detail
=
False
)
def
archived
(
self
,
request
,
pk
=
None
):
try
:
...
...
@@ -220,28 +220,258 @@ class ApplicationViewSet(viewsets.ModelViewSet):
}
return
Response
(
message
,
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
# Show app services
@
action
(
methods
=
[
'GET'
],
detail
=
True
)
def
services
(
self
,
request
,
pk
):
services
=
APIService
.
objects
.
filter
(
application
=
pk
)
serializer
=
APIServiceSerializer
(
services
,
many
=
True
)
return
Response
(
serializer
.
data
,
status
=
status
.
HTTP_200_OK
)
try
:
services
=
APIService
.
objects
.
filter
(
application
=
pk
)
if
not
services
.
exists
():
message
=
{
'code'
:
404
,
'status'
:
'failed'
,
'message'
:
'No records found'
}
return
Response
(
message
,
status
=
status
.
HTTP_404_NOT_FOUND
)
page
=
self
.
paginate_queryset
(
services
)
if
page
is
not
None
:
serializer
=
APIServiceSerializer
(
page
,
many
=
True
)
message
=
{
'code'
:
200
,
'status'
:
'success'
,
'message'
:
'Archived applications found'
,
'results'
:
serializer
.
data
}
return
self
.
get_paginated_response
(
message
)
# serializer = APIServiceSerializer(services, many=True)
# return Response(serializer.data, status=status.HTTP_200_OK)
except
Exception
as
e
:
message
=
{
'code'
:
500
,
'status'
:
'failed'
,
'message'
:
'Request was not able to process'
+
str
(
e
),
}
return
Response
(
message
,
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
class
APIServiceViewSet
(
viewsets
.
ModelViewSet
):
http_method_names
=
[
'get'
,
'post'
,
'put'
,
'patch'
,
'head'
,
'options'
,
'trace'
'get'
,
'post'
,
'put'
,
'patch'
,
'
delete'
,
'
head'
,
'options'
,
'trace'
]
queryset
=
APIService
.
objects
.
all
()
serializer_class
=
APIServiceSerializer
lookup_field
=
'id'
lookup_field
=
'pk'
pagination_class
=
CustomPagination
# CREATE Application
def
create
(
self
,
request
,
*
args
,
**
kwargs
):
try
:
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
=
{
'code'
:
201
,
'status'
:
'success'
,
'message'
:
'New service created'
,
'results'
:
serializer
.
data
}
return
Response
(
message
)
except
BadRequestException
as
e
:
message
=
{
'code'
:
400
,
'status'
:
'failed'
,
'message'
:
''
+
str
(
e
),
}
return
Response
(
message
,
status
=
status
.
HTTP_400_BAD_REQUEST
)
except
Exception
as
e
:
message
=
{
'code'
:
500
,
'status'
:
'failed'
,
'message'
:
'Request was not able to process'
+
str
(
e
),
}
return
Response
(
message
,
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
# SHOW LIST of Applications
def
list
(
self
,
request
,
*
args
,
**
kwargs
):
try
:
queryset
=
APIService
.
objects
.
filter
(
deleted_at__exact
=
None
)
if
not
queryset
.
exists
():
message
=
{
'code'
:
404
,
'status'
:
'failed'
,
'message'
:
'No records found'
}
return
Response
(
message
,
status
=
status
.
HTTP_404_NOT_FOUND
)
page
=
self
.
paginate_queryset
(
queryset
)
if
page
is
not
None
:
serializer
=
self
.
get_serializer
(
page
,
many
=
True
)
message
=
{
'code'
:
200
,
'status'
:
'success'
,
'message'
:
'List of services found'
,
'results'
:
serializer
.
data
}
return
self
.
get_paginated_response
(
message
)
except
Exception
as
e
:
message
=
{
'code'
:
500
,
'status'
:
'failed'
,
'message'
:
'Request was not able to process'
+
str
(
e
),
}
return
Response
(
message
,
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
# SHOW application details
def
retrieve
(
self
,
request
,
*
args
,
**
kwargs
):
try
:
id
=
self
.
kwargs
[
'pk'
]
queryset
=
APIService
.
objects
.
filter
(
id
=
id
)
serializer
=
self
.
get_serializer
(
queryset
,
many
=
True
)
if
not
queryset
.
exists
():
message
=
{
'code'
:
404
,
'status'
:
'failed'
,
'message'
:
'No records found'
}
return
Response
(
message
,
status
=
status
.
HTTP_404_NOT_FOUND
)
else
:
message
=
{
'code'
:
200
,
'status'
:
'success'
,
'message'
:
'Service retrieved'
,
'results'
:
serializer
.
data
}
return
Response
(
message
,
status
=
status
.
HTTP_200_OK
)
except
Exception
as
e
:
message
=
{
'code'
:
500
,
'status'
:
'failed'
,
'message'
:
'Request was not able to process'
+
str
(
e
),
}
return
Response
(
message
,
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
# UPDATE Application
def
update
(
self
,
request
,
*
args
,
**
kwargs
):
try
:
partial
=
kwargs
.
pop
(
'partial'
,
False
)
instance
=
self
.
get_object
()
serializer
=
self
.
get_serializer
(
instance
,
data
=
request
.
data
,
partial
=
partial
)
serializer
.
is_valid
(
raise_exception
=
True
)
self
.
perform_update
(
serializer
)
if
getattr
(
instance
,
'_prefetched_objects_cache'
,
None
):
instance
.
_prefetched_objects_cache
=
{}
message
=
{
'code'
:
200
,
'status'
:
'success'
,
'message'
:
'Application updated'
,
'results'
:
serializer
.
data
}
return
Response
(
message
)
except
Exception
as
e
:
message
=
{
'code'
:
500
,
'status'
:
'failed'
,
'message'
:
'Request was not able to process'
+
str
(
e
),
}
return
Response
(
message
,
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
# SOFT DELETE / ARCHIVED
def
destroy
(
self
,
request
,
*
args
,
**
kwargs
):
try
:
instance
=
self
.
get_object
()
self
.
perform_destroy
(
instance
)
message
=
{
'code'
:
200
,
'status'
:
'Success'
,
'message'
:
'Service deleted'
}
return
Response
(
message
,
status
=
status
.
HTTP_200_OK
)
except
Exception
as
e
:
message
=
{
'code'
:
500
,
'status'
:
'failed'
,
'message'
:
'Request was not able to process'
+
str
(
e
),
}
return
Response
(
message
,
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
# PATCH - RESTORE archived application
def
partial_update
(
self
,
request
,
*
args
,
**
kwargs
):
try
:
kwargs
[
'partial'
]
=
True
instance
=
self
.
get_object
()
instance
.
deleted_at
=
None
serializer
=
self
.
get_serializer
(
instance
)
message
=
{
'code'
:
200
,
'status'
:
'success'
,
'message'
:
'Archived service restored'
,
'results'
:
serializer
.
data
}
instance
.
save
()
return
Response
(
message
)
except
Exception
as
e
:
message
=
{
'code'
:
500
,
'status'
:
'failed'
,
'message'
:
'Request was not able to process'
+
str
(
e
),
}
return
Response
(
message
,
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
# /archived - show list of archived application
@
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
=
{
'code'
:
404
,
'status'
:
'failed'
,
'message'
:
'No records found'
}
return
Response
(
message
,
status
=
status
.
HTTP_404_NOT_FOUND
)
page
=
self
.
paginate_queryset
(
queryset
)
if
page
is
not
None
:
serializer
=
self
.
get_serializer
(
page
,
many
=
True
)
message
=
{
'code'
:
200
,
'status'
:
'success'
,
'message'
:
'Archived services found'
,
'results'
:
serializer
.
data
}
return
self
.
get_paginated_response
(
message
)
except
Exception
as
e
:
message
=
{
'code'
:
500
,
'status'
:
'failed'
,
'message'
:
'Request was not able to process'
+
str
(
e
),
}
return
Response
(
message
,
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
@
action
(
methods
=
[
"GET"
],
detail
=
True
)
def
endpoints
(
self
,
request
,
id
=
None
):
service
=
self
.
get_object
()
endpoints
=
APIEndpoint
.
objects
.
filter
(
service
=
service
)
serializer
=
APIEndpointSerializer
(
endpoints
,
many
=
True
)
return
Response
(
serializer
.
data
,
status
=
status
.
HTTP_200_OK
)
#
@action(methods=["GET"], detail=True)
#
def endpoints(self, request, id=None):
#
service = self.get_object()
#
endpoints = APIEndpoint.objects.filter(service=service)
#
serializer = APIEndpointSerializer(endpoints, many=True)
#
return Response(serializer.data, status=status.HTTP_200_OK)
class
APIEndpointViewSet
(
viewsets
.
ModelViewSet
):
...
...
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