This commit is contained in:
Israel Alves de Oliveira Arruda 2026-05-22 20:18:42 -03:00
parent 677af4118f
commit 34b9a29f0b
2 changed files with 18 additions and 2 deletions

View File

@ -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)