|
@ -33,13 +33,16 @@ myCursor = mydb.cursor() |
|
|
# Define a function that gets the parking status |
|
|
# Define a function that gets the parking status |
|
|
# for all parking codes. |
|
|
# for all parking codes. |
|
|
def getParkings(): |
|
|
def getParkings(): |
|
|
parks = dict() |
|
|
parks = [] |
|
|
|
|
|
|
|
|
myCursor.execute("SELECT * FROM PARKING") |
|
|
myCursor.execute("SELECT * FROM PARKING") |
|
|
myRes = myCursor.fetchall() |
|
|
myRes = myCursor.fetchall() |
|
|
|
|
|
|
|
|
for res in myRes: |
|
|
for res in myRes: |
|
|
parks[res[0]] = res[1] |
|
|
if res[1] == 1: |
|
|
|
|
|
parks.append({"no": res[0], "status": True}) |
|
|
|
|
|
else: |
|
|
|
|
|
parks.append({"no": res[0], "status": False}) |
|
|
return parks |
|
|
return parks |
|
|
|
|
|
|
|
|
# ================================================================== |
|
|
# ================================================================== |
|
@ -65,18 +68,26 @@ class ParkingStatus(Resource): |
|
|
# SQL get all Parking places status. |
|
|
# SQL get all Parking places status. |
|
|
parks = getParkings() |
|
|
parks = getParkings() |
|
|
|
|
|
|
|
|
|
|
|
currentParking = {} |
|
|
|
|
|
for park in parks: |
|
|
|
|
|
if park['no'] == data['no']: |
|
|
|
|
|
currentParking = park |
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
thereIs = False |
|
|
thereIs = False |
|
|
toUpdate = False |
|
|
toUpdate = False |
|
|
try: |
|
|
try: |
|
|
if parks[int(data['no'])] != int(data['status']): |
|
|
if currentParking['status'] != data['status']: |
|
|
toUpdate = True |
|
|
toUpdate = True |
|
|
thereIs = True |
|
|
thereIs = True |
|
|
except IndexError: |
|
|
except IndexError: |
|
|
# handle Index Error |
|
|
# handle Index Error |
|
|
thereIs = False |
|
|
thereIs = False |
|
|
|
|
|
toUpdate = False |
|
|
except KeyError: |
|
|
except KeyError: |
|
|
# handle the KeyError |
|
|
# handle the KeyError |
|
|
thereIs = False |
|
|
thereIs = False |
|
|
|
|
|
toUpdate = False |
|
|
|
|
|
|
|
|
if not thereIs: |
|
|
if not thereIs: |
|
|
# Make a new insert entry for a new Parking Code. |
|
|
# Make a new insert entry for a new Parking Code. |
|
@ -91,7 +102,7 @@ class ParkingStatus(Resource): |
|
|
mydb.commit() |
|
|
mydb.commit() |
|
|
parks = getParkings() |
|
|
parks = getParkings() |
|
|
|
|
|
|
|
|
return parks[data['no']], 201 |
|
|
return currentParking, 201 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ================================================================== |
|
|
# ================================================================== |
|
|