Overview
ThereleaseParkingSpot endpoint cancels an active reservation on a parking spot, returning it to available status. It uses Firestore transactions to ensure safe concurrent operations.
Endpoint
Authentication
CORS-enabled endpoint. Should be protected with user authentication in production to verify the user owns the reservation.Request Body
The unique identifier of the reserved parking spot to release (e.g., “A-01”, “I-16”)
Response
Indicates whether the release was successful
Error message (only present on failure)
Success Response
- 200 OK - Reservation cancelled successfully
Error Responses
- 400 Bad Request - Missing required parameter
spot_id - 405 Method Not Allowed - Request method is not POST
- 409 Conflict - Spot cannot be released due to:
- Spot does not exist
- Spot does not have an active reservation (status is not
2)
Transaction Logic
The function uses Firestore transactions to ensure atomic operations:- Read: Fetch current spot data within transaction
- Validate: Check spot exists and status is
2(Reserved) - Write: Update spot to status
1(Available) and delete reservation metadata - Commit: Transaction commits only if no conflicts occurred
Code Example
Success Response Example
Error Response Examples
Missing Parameter
No Active Reservation
Spot Does Not Exist
Firestore Data Structure
After successful release, the spot document is updated:Use Cases
User Cancellation
User decides to cancel their reservation before arriving:Administrative Release
Admin manually releases a stuck reservation:Automatic Expiration
Note: Expired reservations are automatically cleared by the Get Parking Status endpoint, so manual release is not needed for expired reservations.Status Transition Flow
Security Considerations
In a production environment, you should:- Verify Ownership: Check that the requesting user owns the reservation
- Rate Limiting: Prevent abuse of reservation/release cycles
- Audit Logging: Log all release operations for accountability
- Authorization: Use Firebase Auth or similar to validate user identity
Related Endpoints
- Reserve Parking Spot - Create a new reservation
- Get Parking Status - Check spot status and automatic expiration
- Ingest Parking Data - Handle sensor updates for reserved spots