这是indexloc提供的服务,不要输入任何密码
Skip to content

SatYu26/Meeting-Room-Booking-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Meeting Room Booking API

Overview

This is a Node.js + Express based Meeting Room Booking API that allows users to:

  • View available meeting rooms
  • Retrieve bookings for a specific room
  • Create new bookings with conflict validation
  • Update existing bookings
  • Delete bookings
  • Handle concurrent booking attempts

Installation & Setup

Prerequisites

Ensure you have Node.js and npm installed on your system.

Unzip the file and CD into folder

cd meeting-room-booking-api

Install Dependencies

npm install

Run the Application

node index.js

The server will start at http://localhost:3000

API Endpoints

1. Get Available Rooms

Endpoint: GET /rooms

Description: Returns a list of all available meeting rooms.

Response:

[
    { "id": "room-1", "name": "Conference Room A" },
    { "id": "room-2", "name": "Conference Room B" }
]

2. Get Bookings for a Specific Room

Endpoint: GET /rooms/:roomId/bookings

Description: Retrieves all bookings for a specified room.

Response:

[
    { "id": "booking-1", "userId": "user-123", "startTime": "2025-03-01T10:00:00Z", "endTime": "2025-03-01T11:00:00Z" }
]

3. Create a New Booking

Endpoint: POST /rooms/:roomId/bookings

Request Body:

{
  "userId": "user-123",
  "startTime": "2025-03-01T10:00:00Z",
  "endTime": "2025-03-01T11:00:00Z"
}

Validation Checks:

  • Start time and end time must be valid ISO 8601 strings.
  • Start time must be before end time.
  • The booking must not conflict with existing bookings.
  • A locking mechanism prevents concurrent booking conflicts.

Response:

{
  "id": "generated-uuid",
  "userId": "user-123",
  "startTime": "2025-03-01T10:00:00Z",
  "endTime": "2025-03-01T11:00:00Z"
}

4. Update a Booking

Endpoint: PUT /rooms/:roomId/bookings/:bookingId

Request Body:

{
  "startTime": "2025-03-01T12:00:00Z",
  "endTime": "2025-03-01T13:00:00Z"
}

Response:

{
  "id": "booking-1",
  "userId": "user-123",
  "startTime": "2025-03-01T12:00:00Z",
  "endTime": "2025-03-01T13:00:00Z"
}

5. Delete a Booking

Endpoint: DELETE /rooms/:roomId/bookings/:bookingId

Response:

{
  "message": "Booking deleted successfully."
}

Approach & Considerations

  1. In-memory Data Storage:

    • Instead of a database, we use JavaScript objects to store rooms and bookings.
  2. Conflict Prevention:

    • Before confirming a booking, we check for overlapping time slots.
  3. Concurrent Booking Handling:

    • A locking mechanism prevents simultaneous bookings from conflicting.
  4. Error Handling:

    • Proper validation and HTTP status codes (400, 404, 409) are implemented.

Testing Guide for Meeting Room Booking API

Below is the explaination on how to test each API endpoint in detail using Postman.

Prerequisites

  • Ensure the API is running by executing:
    node index.js
    The server should start at http://localhost:3000.

1. Get Available Rooms

Endpoint: GET /rooms

Using Postman:

  1. Open Postman.
  2. Select GET request.
  3. Enter the URL: http://localhost:3000/rooms
  4. Click Send.

Expected Response:

[
  { "id": "room-1", "name": "Conference Room A" },
  { "id": "room-2", "name": "Conference Room B" }
]

2. Get Bookings for a Specific Room

Endpoint: GET /rooms/:roomId/bookings

Using Postman:

  1. Select GET request.
  2. Enter URL: http://localhost:3000/rooms/room-1/bookings
  3. Click Send.

Expected Response (If bookings exist):

[
  { "id": "booking-1", "userId": "user-123", "startTime": "2025-03-01T10:00:00Z", "endTime": "2025-03-01T11:00:00Z" }
]

3. Create a New Booking

Endpoint: POST /rooms/:roomId/bookings

Using Postman:

  1. Select POST request.
  2. Enter URL: http://localhost:3000/rooms/room-1/bookings
  3. Go to Body > raw > JSON and enter:
{
  "userId": "user-123",
  "startTime": "2025-03-01T10:00:00Z",
  "endTime": "2025-03-01T11:00:00Z"
}
  1. Click Send.

Expected Response:

{
  "id": "generated-uuid",
  "userId": "user-123",
  "startTime": "2025-03-01T10:00:00Z",
  "endTime": "2025-03-01T11:00:00Z"
}

4. Update an Existing Booking

Endpoint: PUT /rooms/:roomId/bookings/:bookingId

Using Postman:

  1. Select PUT request.
  2. Enter URL: http://localhost:3000/rooms/room-1/bookings/booking-1
  3. Go to Body > raw > JSON and enter:
{
  "startTime": "2025-03-01T12:00:00Z",
  "endTime": "2025-03-01T13:00:00Z"
}
  1. Click Send.

Expected Response:

{
  "id": "booking-1",
  "userId": "user-123",
  "startTime": "2025-03-01T12:00:00Z",
  "endTime": "2025-03-01T13:00:00Z"
}

5. Delete a Booking

Endpoint: DELETE /rooms/:roomId/bookings/:bookingId

Using Postman:

  1. Select DELETE request.
  2. Enter URL: http://localhost:3000/rooms/room-1/bookings/booking-1
  3. Click Send.

Expected Response:

{
  "message": "Booking deleted successfully."
}

Edge Cases to Test

  1. Invalid Room ID

    • Try accessing a non-existent room's bookings: GET /rooms/non-existent-room/bookings
    • Expected: { "error": "Room not found." }
  2. Booking with overlapping times

    • Try creating two bookings with the same time slot and check for 409 Conflict error.
  3. Concurrent Booking Handling

    • Simulate multiple users booking the same time slot using Postman runner.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published