Note: Please ensure you have installed nodejs
To preview and run the project on your device:
- Open project folder in Visual Studio Code
- In the terminal, run
npm install - Run
npm startto view project in browser
API Endpoint: GET /api/schedule/{date}
Example: GET /api/schedule/2024-12-21
Expected response:
// Expected API Response Format
{
"6 am - 8 am": {
"washer1": {
"reserved": false,
"name": null
},
"washer2": {
"reserved": false,
"name": null
}
},
"8 am - 10 am": {
"washer1": {
"reserved": false,
"name": null
},
"washer2": {
"reserved": true,
"name": "Lesther"
}
},
"10 am - 12 pm": {
"washer1": {
"reserved": true,
"name": null // null name means "RESERVED" will be displayed
},
"washer2": {
"reserved": true,
"name": null
}
}
// ... and so on for each time slot
}
// Response Status Codes:
// 200 - Success
// 404 - Schedule not found for date
// 500 - Server errorDjango API samples
@require_http_methods(["GET"])
def get_schedule(request, date):
"""
Returns the schedule for a specific date.
URL: /api/schedule/{date}
Example: /api/schedule/2024-11-21
"""
try:
# For demonstration, return the same schedule for all dates
return JsonResponse(SAMPLE_SCHEDULE)
except Exception as e:
return JsonResponse({"error": str(e)}, status=500)
@require_http_methods(["POST"])
def update_booking(request):
"""
Updates a booking slot.
URL: /api/bookings/
"""
try:
data = json.loads(request.body)
date = data.get('date')
time = data.get('time')
name = data.get('name')
# In a real application, you would update a database here
# For now, just return success
return JsonResponse({
"success": True,
"message": f"Booking updated for {date} at {time} for {name}"
})
except Exception as e:
return JsonResponse({"error": str(e)}, status=500)Should be able to use same endpoint as full schedule page to fetch
Making a booking: POST /api/bookings/
Data sent:
{
"name":"hi",
"date":"12/12/2024",
"time":"12:00 pm - 2:00 pm"
}