From da8e3ae8207c2d4e3719b561577cb453b83b18b6 Mon Sep 17 00:00:00 2001 From: PleahMaCaka Date: Thu, 2 Nov 2023 14:33:09 +0900 Subject: [PATCH] feat(translate): hard coded `/toEn` endpoint --- routers/translate.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/routers/translate.py b/routers/translate.py index a91366d..e464f64 100644 --- a/routers/translate.py +++ b/routers/translate.py @@ -2,6 +2,7 @@ import deepl from fastapi import APIRouter +from pydantic import BaseModel router = APIRouter() @@ -9,6 +10,15 @@ translator = deepl.Translator(API_KEY) +class TranslatedModel(BaseModel): + text: str + + @router.post("/toKr") -async def translate(text: str): - return translator.translate_text(text, source_lang="EN", target_lang="KO") +async def translate(data: TranslatedModel): + return translator.translate_text(data.text, source_lang="EN", target_lang="KO") + + +@router.post("/toEn") +async def translate(data: TranslatedModel): + return translator.translate_text(data.text, source_lang="KO", target_lang="EN")