-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
30 lines (23 loc) · 893 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from fastapi import FastAPI
from fastapi.responses import JSONResponse
from pokedex import get_pokemon
import translator
import json
import pytest
app = FastAPI()
@app.get("/")
async def root():
return {"message": "Hello, and welcome to the Pokedex :-)"}
@app.get("/pokemon/{pokemon_name}")
async def pokemon(pokemon_name):
pokemon = get_pokemon(pokemon_name)
if not pokemon:
return JSONResponse(content={"message":f"Unable to find a pokemon with the name {pokemon_name}"},status_code=404)
return pokemon
@app.get("/pokemon/translated/{pokemon_name}")
async def pokemon_transalted(pokemon_name):
pokemon = get_pokemon(pokemon_name)
if not pokemon:
return JSONResponse(content={"message":f"Unable to find a pokemon with the name {pokemon_name}"},status_code=404)
translated_pokemon = translator.translate(pokemon)
return translated_pokemon