Adicionar 2 rotas

This commit is contained in:
Augusto Gunsch
2021-10-18 16:49:47 -03:00
parent b905a812b9
commit 5fc179d389
11 changed files with 230 additions and 36 deletions

View File

@@ -1,20 +1,31 @@
from api.app import app
from api.views import trainer, pokemon_owned, helper, errors
from flask import request
from sqlite3 import ProgrammingError, IntegrityError
from api.app import app, db
from api.views import trainer
import asyncio
@app.route('/trainer/<int:trainerId>', methods=['GET'])
@app.route("/trainer/<int:trainerId>/", methods=["GET"])
def route_get_trainer(trainerId):
return trainer.get_trainer(trainerId)
@app.route('/trainer', methods=['GET'])
@app.route("/trainer", methods=["GET"])
def route_get_trainers():
return trainer.get_trainers()
@app.route('/trainer', methods=['POST'])
@app.route("/trainer", methods=["POST"])
def route_create_trainer():
return trainer.post_trainer()
@app.route("/trainer/authenticate", methods=['POST'])
@app.route("/trainer/authenticate", methods=["POST"])
def route_auth_trainer():
return trainer.auth_trainer()
@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)