Skip to content
CCPEDIAby Unity Nodes
Discussions/App Development/Choice in Airline ModelForum ↗

Choice in Airline Model

App Development2 posts143 viewsLast activity Apr 2022
ZE
ZerumOP
Apr 2022

Hi Team,

Can you please explain the following choices specifically the code in “do” Block

choice AssignSeat : ContractId Flight
with
passenger : Party
ticketRef : Text
seat : Text
controller [passenger, airline]
do
None === TM.lookup seat allocation

    create this with
      allocation = insert seat ticketRef allocation

choice AddPassenger : ContractId Flight
  with
    passenger : Party
  controller [airline, passenger]
  do
    assert (passenger `elem` invitedPassengers)
    create this with passengers = passenger :: passengers

Thank you

Erum

CO
cocreature
Apr 2022

The AssignSeat choice checks if the seat has already been assigned using an assertion

None === TM.lookup seat allocation

If that assertion fails, the choice throws an exception and the transaction is aborted. If not, the current contract is archived and a new one is created wtih that seat allocated to the given ticket reference.

AddPassenger follows the same pattern. It first checks an assertion, in this case that the passenger is among the invited passengers. If that assertion holds the passenger is added to the list of passengers by archiving the old contract & creating a new one with that passenger.

← Back to Discussions