cake-erp-challenge/api/routes/routes.py

43 lines
1.5 KiB
Python
Raw Normal View History

2021-10-18 15:49:47 -04:00
from api.app import app
2021-10-19 00:06:08 -04:00
from api.views import trainer, pokemon_owned, errors
from api.util import authentication
2021-10-18 15:49:47 -04:00
import asyncio
2021-10-17 17:59:27 -04:00
2021-10-18 23:26:16 -04:00
@app.route("/trainer/<int:trainerId>", methods=["GET"])
def route_get_trainer(trainerId):
return trainer.get_trainer(trainerId)
2021-10-18 23:26:16 -04:00
@app.route("/trainer", methods=["GET"])
2021-10-17 17:59:27 -04:00
def route_get_trainers():
return trainer.get_trainers()
2021-10-18 23:26:16 -04:00
@app.route("/trainer", methods=["POST"])
2021-10-17 17:59:27 -04:00
def route_create_trainer():
return trainer.post_trainer()
2021-10-18 15:49:47 -04:00
@app.route("/trainer/authenticate", methods=["POST"])
def route_auth_trainer():
return trainer.auth_trainer()
2021-10-18 15:49:47 -04:00
@app.route("/trainer/<int:trainerId>/pokemon", methods=["GET"])
def route_get_pokemons_owned(trainerId):
return asyncio.run(pokemon_owned.get_pokemons_owned(trainerId))
@app.route("/trainer/<int:trainerId>/pokemon", methods=["POST"])
2021-10-18 23:43:26 -04:00
@authentication.token_required
2021-10-18 15:49:47 -04:00
def route_post_pokemons_owned(trainer, trainerId):
if trainer.id != trainerId:
return errors.ForbiddenError("Trainer id mismatch")
return pokemon_owned.post_pokemon_owned(trainerId)
@app.route("/trainer/<int:trainerId>/pokemon/<int:pokemonId>", methods=["GET"])
def route_get_pokemon_owned(trainerId, pokemonId):
return pokemon_owned.get_pokemon_owned(trainerId, pokemonId)
@app.route("/trainer/<int:trainerId>/pokemon/<int:pokemonId>", methods=["DELETE"])
2021-10-18 23:43:26 -04:00
@authentication.token_required
def route_delete_pokemon_owned(trainer, trainerId, pokemonId):
if trainer.id != trainerId:
return errors.ForbiddenError("Trainer id mismatch")
return pokemon_owned.delete_pokemon_owned(trainer, pokemonId)