Mudança
This commit is contained in:
parent
226c0aac47
commit
677af4118f
|
|
@ -0,0 +1,2 @@
|
||||||
|
.venv/
|
||||||
|
.env
|
||||||
Binary file not shown.
|
|
@ -0,0 +1,32 @@
|
||||||
|
from flask import Flask, jsonify, request
|
||||||
|
from flask_cors import CORS
|
||||||
|
import os
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
from db import get_connection
|
||||||
|
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
|
PORT = os.getenv("PORT")
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
CORS(app)
|
||||||
|
|
||||||
|
@app.route("/health")
|
||||||
|
def health():
|
||||||
|
return jsonify({"message" : "API Flask version 1.0!!!"})
|
||||||
|
|
||||||
|
@app.route("/produtos",methods=["GET"])
|
||||||
|
def listar_produtos():
|
||||||
|
conexao = get_connection()
|
||||||
|
cursor = conexao.cursor(dictionary=True)
|
||||||
|
|
||||||
|
cursor.execute("select * from produto")
|
||||||
|
produtos = cursor.fetchall()
|
||||||
|
|
||||||
|
cursor.close()
|
||||||
|
conexao.close()
|
||||||
|
|
||||||
|
return jsonify(produtos)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
app.run(port=PORT, debug=True)
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
import os
|
||||||
|
import mysql.connector
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
|
def get_connection():
|
||||||
|
return mysql.connector.connect(
|
||||||
|
host=os.getenv("DB_HOST"),
|
||||||
|
user=os.getenv("DB_USER"),
|
||||||
|
password=os.getenv("DB_PASSWORD"),
|
||||||
|
database=os.getenv("DB_NAME"),
|
||||||
|
port=os.getenv("DB_PORT")
|
||||||
|
)
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
blinker==1.9.0
|
||||||
|
click==8.3.3
|
||||||
|
colorama==0.4.6
|
||||||
|
Flask==3.1.3
|
||||||
|
flask-cors==6.0.2
|
||||||
|
itsdangerous==2.2.0
|
||||||
|
Jinja2==3.1.6
|
||||||
|
MarkupSafe==3.0.3
|
||||||
|
mysql-connector-python==9.7.0
|
||||||
|
python-dotenv==1.2.2
|
||||||
|
Werkzeug==3.1.8
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
create table produto (
|
||||||
|
id int auto_increment primary key,
|
||||||
|
nome varchar(100) not null,
|
||||||
|
preco decimal(10,2) not null,
|
||||||
|
estoque int not null
|
||||||
|
);
|
||||||
|
|
||||||
|
#Carga inicial do banco
|
||||||
|
insert into produto (nome,preco,estoque)
|
||||||
|
values ('Bola',12.50,10);
|
||||||
|
|
||||||
|
#Exemplo de consulta
|
||||||
|
insert into produto (nome,preco,estoque)
|
||||||
|
values ('PS5',3950.50,5);
|
||||||
|
|
||||||
|
#select * from produto;
|
||||||
|
|
||||||
|
#delete from produto where id
|
||||||
Loading…
Reference in New Issue