in src/backend/catalog/src/release-flight/release.py [0:0]
def reserve_seat_on_flight(flight_id):
try:
# TODO: This needs to find the max. In theory, we should never have a situation
# where we're trying to increment the seat when one hasn't been
# decremented, but just to be sure.
table.update_item(
Key={"id": flight_id},
ConditionExpression="id = :idVal AND seatCapacity < maximumSeating",
UpdateExpression="SET seatCapacity = seatCapacity + :dec",
ExpressionAttributeValues={
":idVal": flight_id,
":dec": 1
},
)
return {
'status': 'SUCCESS'
}
except dynamodb.meta.client.exceptions.ConditionalCheckFailedException as e:
# Due to no specificity from the DDB error, this could also mean the flight
# doesn't exist, but we should've caught that earlier in the flow.
# TODO: Fix that. Could either use TransactGetItems, or Get then Update.
raise FlightFullyBookedException(f"Flight with ID: {flight_id} is fully booked.")
except ClientError as e:
raise FlightReservationException(e.response['Error']['Message'])