Mudança
This commit is contained in:
parent
677af4118f
commit
34b9a29f0b
Binary file not shown.
|
|
@ -20,7 +20,7 @@ def listar_produtos():
|
|||
conexao = get_connection()
|
||||
cursor = conexao.cursor(dictionary=True)
|
||||
|
||||
cursor.execute("select * from produto")
|
||||
cursor.execute("Select * from produto")
|
||||
produtos = cursor.fetchall()
|
||||
|
||||
cursor.close()
|
||||
|
|
@ -28,5 +28,21 @@ def listar_produtos():
|
|||
|
||||
return jsonify(produtos)
|
||||
|
||||
@app.route("/produtos/<int:id>", methods=["GET"])
|
||||
def listar_produto_id(id):
|
||||
conexao = get_connection()
|
||||
cursor = conexao.cursor(dictionary=True)
|
||||
|
||||
cursor.execute("Select * from produto where id = %s", (id))
|
||||
produto = cursor.fetchone()
|
||||
|
||||
cursor.close()
|
||||
conexao.close()
|
||||
|
||||
if produto is None:
|
||||
return jsonify({"erro" : "Produto nao encontrado"}), 404
|
||||
|
||||
return jsonify(produto)
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(port=PORT, debug=True)
|
||||
app.run(port=PORT, debug=True)
|
||||
|
|
|
|||
Loading…
Reference in New Issue