db:
model parking:{
status: reserved | free | taken
reservationCreatedAt?:Date
reservedFrom?: Date
reservedUntil?: Date
paidAt?: Date
leftAt?:Date
carId:String
}
GET /parkings - shows all parkings details
POST /reserve/parking/{parkingId} body:{ reservedFrom: Date, reservedUntil: Date} - used for reserving a parking lot
POST /pay/parking/{parkingId} body:{ carId:string; cardDetails:JSON } - used for paying a parking lot
POST /park/parking/{parkingId}?is_parking={is_parking}&leaving_at={leaving_at} - used for parking a car and for leaving parking earlier or on time
POST /parking/{parkingId}/status/{status} - used by admins to reset the status of a parking in case of no show
reserving, parking, leaving parking, updating parking status flow:
payment flow:
parking service is handling reservations, leaving, parking and updating a parking lot status. it firstly checks the cache and if missing, it checks/updates the db.
payment service is call a 3rd party api called Payment API, it could be stripe. based on the response, it updates the parking paidAt date or in case of failure, it prompts the user to retry the payment
if 2 clients try to reserve the parking spot, parking service saves to db who reserved the parking and at what time (reservationCreatedAt) so before updating that parking lot as reserved, it checks if it wasnt already reserved. only if its status is "free" it will let the second customer reserve it.
the cache will be updated on each write/update so it wont be stale and wont lead to any inconsistencies