-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
177 lines (155 loc) · 8.26 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import requests
from flask import Flask, render_template, redirect, url_for, request
from datetime import datetime
app = Flask(__name__)
@app.route("/")
def return_index():
return redirect(url_for('dashboard'))
@app.route("/parking-management")
def index():
return redirect(url_for('dashboard'))
# ------------------ DASHBOARD ---------------------
@app.route("/parking-management/dashboard")
def dashboard():
totalCars = requests.get("http://localhost:8080/dashboard/total-cars").json()
totalActiveParkings = requests.get("http://localhost:8080/dashboard/total-active-parkings").json()
totalLots = requests.get("http://localhost:8080/dashboard/total-parking-lots").json()
totalUnoccupiedLots = requests.get("http://localhost:8080/dashboard/total-unoccupied-parking-lots").json()
totalPaidPaymentsToday = requests.get("http://localhost:8080/dashboard/total-paid-payments-value-today").json()
totalPendingPayments = requests.get("http://localhost:8080/dashboard/total-pending-payments").json()
totalParkingsToday = requests.get("http://localhost:8080/dashboard/total-parkings-today").json()
return render_template("dashboard.html", totalCars=totalCars, totalActiveParkings=totalActiveParkings,
totalLots=totalLots, totalUnoccupiedLots=totalUnoccupiedLots,
totalPaidPaymentsToday=totalPaidPaymentsToday, totalPendingPayments=totalPendingPayments,
totalParkingsToday=totalParkingsToday)
# ------------------ PARKING LOTS ---------------------
@app.route("/parking-management/parking-lots/filter/<int:filter>", methods=["GET", "POST"])
def parkingLots(filter):
match filter:
case 1:
req = requests.get("http://localhost:8080/parkingLots").json()
case 2:
req = requests.get("http://localhost:8080/parkingLots/unoccupied").json()
case 3:
req = requests.get("http://localhost:8080/parkingLots/occupied").json()
return render_template("parkingLots.html", parkingLots=req)
@app.route("/parking-management/parking-lots/create", methods=["GET", "POST"])
def createParkingLot():
if request.method == "GET":
return render_template("createParkingLot.html")
if request.method == "POST":
tag = request.form.get("tag")
data = {"tag": tag}
req = requests.post("http://localhost:8080/parkingLots", json=data)
return redirect(url_for("parkingLots", filter=1))
@app.route("/parking-management/parking-lots/delete/<int:id>", methods=["GET", "POST"])
def deleteParkingLot(id):
req = requests.delete(f"http://localhost:8080/parkingLots/{id}")
return redirect(url_for("parkingLots", filter=1))
@app.route("/parking-management/parking-lots/edit/<int:id>", methods=["GET", "POST"])
def editParkingLot(id):
if request.method == "GET":
parkingLot = requests.get(f"http://localhost:8080/parkingLots/{id}").json()
return render_template("editParkingLot.html", parkingLot=parkingLot)
if request.method == "POST":
data = {"tag": request.form.get("tag")}
req = requests.put(f"http://localhost:8080/parkingLots/{id}", json=data)
return redirect(url_for("parkingLots", filter=1))
# ------------------ CARS ---------------------
@app.route("/parking-management/cars")
def cars():
req = requests.get("http://localhost:8080/cars").json()
return render_template("cars.html", cars=req)
@app.route("/parking-management/cars/create", methods=["GET", "POST"])
def createCar():
if request.method == "GET":
return render_template("createCar.html")
if request.method == "POST":
data = {"licensePlate": request.form.get("licensePlate"), "brand": request.form.get("brand"), "model": request.form.get("model"), "color": request.form.get("color")}
req = requests.post("http://localhost:8080/cars", json=data)
return redirect(url_for("cars"))
@app.route("/parking-management/cars/delete/<int:id>", methods=["GET", "POST"])
def deleteCar(id):
req = requests.delete(f"http://localhost:8080/cars/{id}")
return redirect(url_for("cars"))
@app.route("/parking-management/cars/edit/<int:id>", methods=["GET", "POST"])
def editCar(id):
if request.method == "GET":
car = requests.get(f"http://localhost:8080/cars/{id}").json()
return render_template("editCar.html", car=car)
if request.method == "POST":
data = {"licensePlate": request.form.get("licensePlate"), "brand": request.form.get("brand"), "model": request.form.get("model"), "color": request.form.get("color")}
req = requests.put(f"http://localhost:8080/cars/{id}", json=data)
return redirect(url_for("cars"))
@app.route("/parking-management/cars/parkings/<int:id>/filter/<int:filter>", methods=["GET"])
def carParkings(id, filter):
if request.method == "GET":
match filter:
case 1:
parkings = requests.get(f"http://localhost:8080/parkings/search?carId={id}").json()
case 2:
parkings = requests.get(f"http://localhost:8080/parkings/going?carId={id}").json()
case 3:
parkings = requests.get(f"http://localhost:8080/parkings/ended?carId={id}").json()
car = requests.get(f"http://localhost:8080/cars/{id}").json()
return render_template("carParkings.html", parkings=parkings, car=car)
# ------------------ PARKINGS ---------------------
@app.route("/parking-management/parkings/filter/<int:filter>")
def parkings(filter):
match filter:
case 1:
req = requests.get("http://localhost:8080/parkings").json()
case 2:
req = requests.get("http://localhost:8080/parkings/going").json()
case 3:
req = requests.get("http://localhost:8080/parkings/ended").json()
return render_template("parkings.html", parkings=req)
@app.route("/parking-management/parkings/create", methods=["GET", "POST"])
def createParking():
if request.method == "GET":
cars = requests.get("http://localhost:8080/cars/inParkingFalse").json()
parkingLots = requests.get("http://localhost:8080/parkingLots/unoccupied").json()
return render_template("createParking.html", cars=cars, parkingLots=parkingLots)
if request.method == "POST":
url = "http://localhost:8080/parkings/insert?carId={carId}&parkingLotId={parkingLotId}"
data = {"startTime": request.form.get("startTime"), "rate": request.form.get("rate")}
carId = request.form["carId"]
parkingLotId = request.form["parkingLotId"]
url = url.format(carId=carId, parkingLotId=parkingLotId)
req = requests.post(url, json=data)
return redirect(url_for("parkings", filter=1))
@app.route("/parking-management/parkings/delete/<int:id>", methods=["GET", "POST"])
def deleteParking(id):
req = requests.delete(f"http://localhost:8080/parkings/{id}")
return redirect(url_for("parkings", filter=1))
@app.route("/parking-management/parkings/end/<int:id>")
def endParking(id):
time = datetime.now().strftime('%H:%M')
req = requests.get(f"http://localhost:8080/parkings/end/{id}?endTime={time}")
return redirect(url_for("parkings", filter=1))
@app.route("/parking-management/parkings/generate-payment/<int:id>")
def generatePayment(id):
data = {}
req = requests.post(f"http://localhost:8080/payments/insert?parkingId={id}", json=data)
return redirect(url_for("payments", filter=1))
# ------------------ PAYMENTS ---------------------
@app.route("/parking-management/payments/filter/<int:filter>")
def payments(filter):
match filter:
case 1:
req = requests.get("http://localhost:8080/payments").json()
case 2:
req = requests.get("http://localhost:8080/payments/paid").json()
case 3:
req = requests.get("http://localhost:8080/payments/pending").json()
return render_template("payments.html", payments=req)
@app.route("/parking-management/payments/end/<int:id>")
def endPayment(id):
req = requests.get(f"http://localhost:8080/payments/end/{id}")
return redirect(url_for("payments", filter=1))
@app.route("/parking-management/payments/delete/<int:id>")
def deletePayment(id):
req = requests.delete(f"http://localhost:8080/payments/{id}")
return redirect(url_for("payments", filter=1))
if __name__ == "__main__":
app.run(debug=True)