Closed jsurrea closed 5 months ago
This PR implements the basic functionalities for the "Available Spaces" Service. Solves #1
Expected Request (API REST): GET http://34.133.121.100:3000/ With Body (JSON):
{ "dayOfWeek": 1 letter string either 'l' | 'm' | 'i' | 'j' | 'v' | 's' | 'd', "startTime": 4 digit string (hhmm), "endTime": 4 digit string (hhmm) }
Expected Response (JSON):
[ { building: string (example "W"), room: string (example "101"), availableFrom: 4 digit string (hhmm), availableUntil: 4 digit string (hhmm), minutesAvailable: integer number between 0 and 1440 }, ... (0 or more of these) ]
DEMO:
https://github.com/ISIS3510-202410-Team-13/Backend/assets/68788933/dcf7259e-4168-42d5-82c2-924b848f80e9
Troubleshooting: Here are some 4xx errors you might get while fetching this API and their causes (validations)
if (!req.body) { res.status(400).send({ message: 'Request body is missing' }); return; } const { dayOfWeek, startTime, endTime } = req.body; if (dayOfWeek === undefined || startTime === undefined || endTime === undefined) { res.status(400).send({ message: 'Missing required fields in request body' }); return; } if (typeof dayOfWeek !== "string" || typeof startTime !== "string" || typeof endTime !== "string") { res.status(400).send({ message: 'Invalid data types in request body' }); return; } if (dayOfWeek.length !== 1 || !["l", "m", "i", "j", "v", "s", "d"].includes(dayOfWeek)) { res.status(400).send({ message: 'Invalid day of week' }); return; } if (!/^\d{4}$/.test(startTime) || !/^\d{4}$/.test(endTime)) { res.status(400).send({ message: 'Invalid time format' }); return; } if (startTime >= endTime) { res.status(400).send({ message: 'Start time must be before end time' }); return; } if (startTime < "0000" || startTime >= "2400" || endTime < "0000" || endTime >= "2400") { res.status(400).send({ message: 'Invalid time range' }); return; } if (startTime.slice(-2) > "59" || endTime.slice(-2) > "59") { res.status(400).send({ message: 'Invalid minutes' }); return; }
Note: Currently filters available spaces only for these buildings: ["ML", "SD", "W", "R", "O", "C", "LL", "B", "RGD", "AU"];
This PR implements the basic functionalities for the "Available Spaces" Service. Solves #1
Expected Request (API REST): GET http://34.133.121.100:3000/ With Body (JSON):
Expected Response (JSON):
DEMO:
https://github.com/ISIS3510-202410-Team-13/Backend/assets/68788933/dcf7259e-4168-42d5-82c2-924b848f80e9
Troubleshooting: Here are some 4xx errors you might get while fetching this API and their causes (validations)
Note: Currently filters available spaces only for these buildings: ["ML", "SD", "W", "R", "O", "C", "LL", "B", "RGD", "AU"];