A simple implementation of a taxi booking system in a 2D world. Cars start at (0, 0), can be booked by a customer via the /api/book endpoint (the closest car to the customer must be chosen), and remain unavailable for the whole duration of the trip.
Prerequisite: you will need Node.js to run this service. Install it here: https://nodejs.org/en/
- Clone the repo
cd taxi-booking
npm install
npm run start
Available endpoints ? see below
npm run test
Libraries used:
- Jest for unit tests
- Jest & Supertest for integration tests
/config/default.js
timeServiceUp
(integer): time the service has been upinitPosition
(array [x, y]): initial car positionscars
(integer): number of carscarData
(array): contains the cars current details/status
id
(integer)x
(integer): x position on the gridy
(integer): y position on the gridavailable
(boolean): false if bookedtimeRemaining
(integer): positive if currently booked, measures the time until the car is available again (decreases on each tick)
body
{
source: { x: x1, y: y1 },
destination: { x: x2, y: y2 }
}
- find the nearest available car
- if equality, return smallest id
- compute the total_time = (distance car-customer) + (distance source-destination)
success (car available)
status: 200
body: {
car_id: id,
total_time: t
}
failed to find a car available
status: 200
body: {}
empty body
- timestamp += 1 Time Unit
- decrease all booked cars' timeRemaining time
status: 200
body: {
timeServiceUp: value
}
empty body
- put all the cars back to their initial position
- make them all available
status: 200