in src/backend/catalog/src/reserve-flight/reserve.py [0:0]
def reserve_seat_on_flight(flight_id):
try:
table.update_item(
Key={"id": flight_id},
ConditionExpression="id = :idVal AND seatCapacity > zero",
UpdateExpression="SET seatCapacity = seatCapacity - :dec",
ExpressionAttributeValues={
":idVal": flight_id,
":dec": 1,
":zero": 0
},
)
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'])