Adicionar endpoint: DELETE /../pokemon/{pokemonId}
This commit is contained in:
parent
e02e05ea06
commit
d6f29b98a6
|
@ -23,4 +23,4 @@ Os endpoints que já estão funcionando marcados:
|
||||||
- [X] GET /trainer/{trainerId}/pokemon
|
- [X] GET /trainer/{trainerId}/pokemon
|
||||||
- [X] POST /trainer/{trainerId}/pokemon
|
- [X] POST /trainer/{trainerId}/pokemon
|
||||||
- [X] GET /trainer/{trainerId}/pokemon/{pokemonId}
|
- [X] GET /trainer/{trainerId}/pokemon/{pokemonId}
|
||||||
- [ ] DELETE /trainer/{trainerId}/pokemon/{pokemonId}
|
- [X] DELETE /trainer/{trainerId}/pokemon/{pokemonId}
|
||||||
|
|
|
@ -7,11 +7,11 @@ import asyncio
|
||||||
def route_get_trainer(trainerId):
|
def route_get_trainer(trainerId):
|
||||||
return trainer.get_trainer(trainerId)
|
return trainer.get_trainer(trainerId)
|
||||||
|
|
||||||
@app.route("/trainer", methods=["GET"])
|
@app.route("/trainer/", methods=["GET"])
|
||||||
def route_get_trainers():
|
def route_get_trainers():
|
||||||
return trainer.get_trainers()
|
return trainer.get_trainers()
|
||||||
|
|
||||||
@app.route("/trainer", methods=["POST"])
|
@app.route("/trainer/", methods=["POST"])
|
||||||
def route_create_trainer():
|
def route_create_trainer():
|
||||||
return trainer.post_trainer()
|
return trainer.post_trainer()
|
||||||
|
|
||||||
|
@ -33,3 +33,10 @@ def route_post_pokemons_owned(trainer, trainerId):
|
||||||
@app.route("/trainer/<int:trainerId>/pokemon/<int:pokemonId>", methods=["GET"])
|
@app.route("/trainer/<int:trainerId>/pokemon/<int:pokemonId>", methods=["GET"])
|
||||||
def route_get_pokemon_owned(trainerId, pokemonId):
|
def route_get_pokemon_owned(trainerId, pokemonId):
|
||||||
return pokemon_owned.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)
|
||||||
|
|
|
@ -73,3 +73,15 @@ def get_pokemon_owned(trainer_id, pokemon_id):
|
||||||
return "", 404
|
return "", 404
|
||||||
except HTTPError as e:
|
except HTTPError as e:
|
||||||
return FetchError(e.message)
|
return FetchError(e.message)
|
||||||
|
|
||||||
|
def delete_pokemon_owned(trainer, pokemon_id):
|
||||||
|
try:
|
||||||
|
pokemon = get_pokemon_fail(trainer, pokemon_id)
|
||||||
|
set_pokemon_data(pokemon)
|
||||||
|
db.session.delete(pokemon)
|
||||||
|
db.session.commit()
|
||||||
|
return pokemon_owned_schema.dump(pokemon)
|
||||||
|
except NotFound:
|
||||||
|
return "", 404
|
||||||
|
except HTTPError as e:
|
||||||
|
return FetchError(e.message)
|
||||||
|
|
Loading…
Reference in New Issue