-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
96 lines (83 loc) · 2.78 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import sqlQuery as bd
from flask import Flask, jsonify, request, render_template
app = Flask(__name__)
def load_cars(sort):
cars_list = bd.get_cars(sort)
return cars_list
@app.route('/islogged', methods=['GET'])
def is_logged():
login = bd.get_login()
return {'login': login}, 200
@app.route('/login', methods=['POST', 'GET'])
def login():
if request.method == 'GET':
return render_template("login.html")
if request.method == 'POST':
email = request.json['email']
senha = request.json['senha']
login = bd.login(email, senha)
return jsonify(login)
@app.route('/logout', methods=['GET'])
def logout():
logout = bd.logout()
return jsonify(logout)
@app.route('/meu-historico', methods=['GET'])
def historico():
return render_template("historico.html")
@app.route('/load-historico/<int:idUser>', methods=['GET'])
def load_historico(idUser):
historico = bd.load_historico(idUser)
return jsonify(historico)
@app.route('/add-car', methods=['GET'])
def addCar():
return render_template("addCar.html")
@app.route('/new-car', methods=['POST'])
def newCar():
data = request.get_json()
if not data:
return jsonify({'sucess': False, 'message': 'Bad request'})
model = request.json['model']
marca = request.json['marca']
obs = request.json['obs']
ano = request.json['ano']
valor = request.json['valor']
status = request.json['status']
dono = request.json['dono']
img = request.json['img']
result = bd.new_car(model, marca, ano, obs, valor, status, dono, img)
return jsonify(result)
@app.route('/new-rent', methods=['POST'])
def newRent():
data = request.get_json()
if not data:
return jsonify({'sucess': False, 'message': 'Bad request'})
idCarro = request.json['idCarro']
idUsuario = request.json['idUsuario']
local = request.json['local']
data = request.json['data']
hora = request.json['hora']
status = request.json['finalizado']
result = bd.new_rent(idCarro, idUsuario, data, local, hora, status)
return jsonify(result)
@app.route('/update/<int:id>', methods=['PUT'])
def update_car(id):
data = request.get_json()
if not data:
return jsonify({'sucess': False, 'message': 'Bad request'})
obs = request.json['newObs']
valor = request.json['newValor']
status = request.json['newStatus']
result = bd.updateCar(id, obs, valor, status)
return jsonify(result)
@app.route('/delete/<int:id>', methods=['DELETE'])
def delete_car(id):
result = bd.deleteCar(id)
return jsonify(result)
@app.route('/', methods=['GET'])
def entry_page():
sort = request.args.get("sort")
if sort == None:
sort = "status"
cars = load_cars(sort)
return render_template("index.html", the_cars = cars)
app.run(debug=True)