From 34b9a29f0bdd3e56fa9a17e8e343a2bdbcdd9a5a Mon Sep 17 00:00:00 2001 From: Israel Date: Fri, 22 May 2026 20:18:42 -0300 Subject: [PATCH] =?UTF-8?q?Mudan=C3=A7a?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apirest/__pycache__/db.cpython-311.pyc | Bin 907 -> 911 bytes apirest/app.py | 20 ++++++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/apirest/__pycache__/db.cpython-311.pyc b/apirest/__pycache__/db.cpython-311.pyc index 9242bbfdad98181c26a48c6be385d6879eb18fef..a2ce442ae3d7d70f5338740c08e40d4093c72544 100644 GIT binary patch delta 36 qcmeBX?`P*;&dbZi00jGP3vA>TXJWLOtjwgzVq{=sw%Lcto)G|&QwOR5 delta 31 lcmeBY?`G#-&dbZi00jDb**9{FGcj6BR%X)N9KdAH2moW01||Ri diff --git a/apirest/app.py b/apirest/app.py index 1c19b56..6f3752c 100644 --- a/apirest/app.py +++ b/apirest/app.py @@ -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/", 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) \ No newline at end of file + app.run(port=PORT, debug=True)