Skip to content
Snippets Groups Projects
Commit efda2d1d authored by Sahu, Pratyush K (PG/T - Comp Sci & Elec Eng)'s avatar Sahu, Pratyush K (PG/T - Comp Sci & Elec Eng)
Browse files

Fixed some issues in rental api

parent 1bd3a5e2
No related branches found
No related tags found
No related merge requests found
......@@ -82,24 +82,27 @@ async def create_rental(rental: Rental):
@app.get("/rentals/", response_model=List[Rental])
async def read_rentals():
cursor.execute('SELECT * FROM Rentals')
rentals = cursor.fetchall()
with db_connection.cursor(dictionary=True) as cursor:
cursor.execute('SELECT * FROM Rentals')
rentals = cursor.fetchall()
# Convert each rental record to Rental model
rental_objects = [
Rental(
booking_id=rental[0],
user_id=rental[1],
bike_id=rental[2],
year=rental[3],
hour=rental[4],
season=rental[5],
holiday=bool(rental[6]),
workingday=bool(rental[7]),
weather=rental[8],
temp=float(rental[9]),
atemp=float(rental[10]),
humidity=float(rental[11]),
windspeed=float(rental[12]),
count=rental[13]
booking_id=int(rental['booking_id']),
user_id=int(rental['user_id']),
bike_id=int(rental['bike_id']),
year=int(rental['year']),
hour=int(rental['hour']),
season=int(rental['season']),
holiday=bool(rental['holiday']),
workingday=bool(rental['workingday']),
weather=int(rental['weather']),
temp=float(rental['temp']),
atemp=float(rental['atemp']),
humidity=float(rental['humidity']),
windspeed=float(rental['windspeed']),
count=int(rental['count']) # Ensure count is treated as integer
) for rental in rentals
]
return rental_objects
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment