From eeca45778634c7493187248a677494d23ae71033 Mon Sep 17 00:00:00 2001 From: kartikvirendrar Date: Wed, 9 Oct 2024 14:09:17 +0530 Subject: [PATCH 1/2] created a proxy endpoint for xlit api --- backend/tasks/urls.py | 6 ++++++ backend/tasks/views.py | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/backend/tasks/urls.py b/backend/tasks/urls.py index ceabbf4c7..4b265b707 100644 --- a/backend/tasks/urls.py +++ b/backend/tasks/urls.py @@ -9,6 +9,7 @@ stopping_celery_tasks, resume_celery_task, delete_celery_task, + TransliterationAPIView ) router = routers.DefaultRouter() @@ -21,4 +22,9 @@ path("stopping_celery_tasks/", stopping_celery_tasks), path("resume_celery_task/", resume_celery_task), path("delete_celery_task/", delete_celery_task), + path( + "xlit-api/generic/transliteration//", + TransliterationAPIView.as_view(), + name="transliteration-api", + ), ] + router.urls diff --git a/backend/tasks/views.py b/backend/tasks/views.py index 991c4f141..d5a02e5c7 100644 --- a/backend/tasks/views.py +++ b/backend/tasks/views.py @@ -59,6 +59,7 @@ from utils.date_time_conversions import utc_to_ist from django.db import IntegrityError +from rest_framework.views import APIView # Create your views here. @@ -2774,3 +2775,15 @@ def delete_celery_task(req): task.forget() return JsonResponse({"message": "Task deleted successfully"}, status=200) + +class TransliterationAPIView(APIView): + permission_classes = [IsAuthenticated] + + def get(self, request, target_language, data, *args, **kwargs): + response_transliteration = requests.get( + os.getenv("TRANSLITERATION_URL")+target_language+"/"+data, + headers={"Authorization": "Bearer "+os.getenv("TRANSLITERATION_KEY")}, + ) + + transliteration_output = response_transliteration.json() + return Response(transliteration_output, status=status.HTTP_200_OK) From 7cfb8c781003b5e6d854da544e153431f1335da8 Mon Sep 17 00:00:00 2001 From: kartikvirendrar Date: Wed, 9 Oct 2024 14:13:53 +0530 Subject: [PATCH 2/2] created a proxy endpoint for xlit api --- backend/tasks/urls.py | 2 +- backend/tasks/views.py | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/backend/tasks/urls.py b/backend/tasks/urls.py index 4b265b707..1e6cc3999 100644 --- a/backend/tasks/urls.py +++ b/backend/tasks/urls.py @@ -9,7 +9,7 @@ stopping_celery_tasks, resume_celery_task, delete_celery_task, - TransliterationAPIView + TransliterationAPIView, ) router = routers.DefaultRouter() diff --git a/backend/tasks/views.py b/backend/tasks/views.py index d5a02e5c7..c780c0536 100644 --- a/backend/tasks/views.py +++ b/backend/tasks/views.py @@ -2776,13 +2776,14 @@ def delete_celery_task(req): return JsonResponse({"message": "Task deleted successfully"}, status=200) + class TransliterationAPIView(APIView): permission_classes = [IsAuthenticated] - + def get(self, request, target_language, data, *args, **kwargs): response_transliteration = requests.get( - os.getenv("TRANSLITERATION_URL")+target_language+"/"+data, - headers={"Authorization": "Bearer "+os.getenv("TRANSLITERATION_KEY")}, + os.getenv("TRANSLITERATION_URL") + target_language + "/" + data, + headers={"Authorization": "Bearer " + os.getenv("TRANSLITERATION_KEY")}, ) transliteration_output = response_transliteration.json()