Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New update endpoint #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

urlpatterns = [
path('<str:name>/_search/', views.index, name='index'),
path('<str:name>/<str:id>/update', views.update, name='update'),
path('<str:name>/<str:id>', views.detail, name='detail'),
path('fire_api/trackhubregistry/<str:genome_id>/<str:folder>/<str:doc_id>',
views.trackhubregistry_with_dirs_fire_api,
Expand Down
51 changes: 51 additions & 0 deletions api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,57 @@ def index(request, name):

return JsonResponse(data)

@swagger_auto_schema(method='put', tags=['Update'],
operation_summary="Update records",
operation_description="Update records by queries",
manual_parameters=[
openapi.Parameter('name', openapi.IN_PATH,
description="type of records to query",
type=openapi.TYPE_STRING,
enum=ALLOWED_INDICES),
openapi.Parameter('id', openapi.IN_PATH,
description="id of record to update",
type=openapi.TYPE_STRING)
],
request_body=openapi.Schema(
type=openapi.TYPE_OBJECT,
example=index_search_request_example
),
responses={
200: openapi.Response('Updated',
examples={"application/json": index_search_response_example},
schema=openapi.Schema(type=openapi.TYPE_OBJECT)
),
404: openapi.Response('Not Found')
})
@api_view(['PUT'])
@permission_classes([AllowAny])
@csrf_exempt
def update(request, name, id):
if request.method != 'PUT':
context = {
'status': '405', 'reason': 'This method is not allowed!'
}
response = HttpResponse(
json.dumps(context), content_type='application/json')
response.status_code = 405
return response
if name not in ALLOWED_INDICES:
context = {
'status': '404', 'reason': 'This index doesn\'t exist!'
}
response = HttpResponse(
json.dumps(context), content_type='application/json')
response.status_code = 404
return response

es = Elasticsearch([settings.NODE1, settings.NODE2])
if request.body:
print(request.body.decode("utf-8"))
data = es.update(index=name, id=id, doc_type="_doc",
body=json.loads(request.body.decode("utf-8")))
return JsonResponse(data)


@swagger_auto_schema(method='get', tags=['Details'],
operation_summary="Get details of the Organism, Specimen, File or Dataset etc, by their ID",
Expand Down
8 changes: 8 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Django==3.2.4
python-decouple==3.1
djangorestframework==3.12.2
django-cors-headers==3.5.0
drf-yasg==1.20.0
djangorestframework-jwt==1.11.0
elasticsearch==7.10.0
pandas==1.1.4