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
from api.views import trainer, pokemon_owned, helper, errors
2021-10-17 17:59:27 -04:00
from flask import request
2021-10-18 15:49:47 -04:00
import asyncio
2021-10-17 17:59:27 -04:00
2021-10-18 15:49:47 -04:00
@app.route("/trainer/<int:trainerId>/", methods=["GET"])
def route_get_trainer(trainerId):
return trainer.get_trainer(trainerId)
@app.route("/trainer/", methods=["GET"])
2021-10-17 17:59:27 -04:00
def route_get_trainers():
return trainer.get_trainers()
@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"])
@helper.token_required
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"])
@helper.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)