package Ġcom . d restaurant . web Ċ Ċ import Ġcom . d restaurant . common . domain . api . model . Audit Entry Ċ import Ġcom . d restaurant . common . domain . api . model . Person Name Ċ import Ġcom . d restaurant . cour ier . domain . api . Assign Courier Order To Courier Command Ċ import Ġcom . d restaurant . cour ier . domain . api . Create Courier Command Ċ import Ġcom . d restaurant . cour ier . domain . api . Mark Courier Order As Deliver ed Command Ċ import Ġcom . d restaurant . cour ier . domain . api . model . Courier Id Ċ import Ġcom . d restaurant . cour ier . domain . api . model . Courier OrderId Ċ import Ġcom . d restaurant . cour ier . domain . api . model . Courier Order State Ċ import Ġcom . d restaurant . cour ier . query . api . Find Courier Order Query Ċ import Ġcom . d restaurant . cour ier . query . api . Find Courier Query Ċ import Ġcom . d restaurant . cour ier . query . api . model . Courier Model Ċ import Ġcom . d restaurant . cour ier . query . api . model . Courier Order Model Ċ import Ġorg . ax on framework . command handling . gateway . Command Gateway Ċ import Ġorg . ax on framework . messaging . respon set ypes . Response Types Ċ import Ġorg . ax on framework . query handling . Query Gateway Ċ import Ġorg . springframework . http . MediaType Ċ import Ġorg . springframework . http . Response Entity Ċ import Ġorg . springframework . security . core . context . SecurityContext Holder Ċ import Ġorg . springframework . web . bind . annotation .* Ċ import Ġjava . util .* Ċ import Ġjavax . servlet . http . HttpServletResponse ĊĊ Ċ /** Ċ Ġ* ĠRepository ĠREST ĠController Ġfor Ġhandling Ġ' commands ' Ġonly Ċ Ġ* Ċ Ġ*/ Ċ @ RestController Ċ class ĠCommand Controller ( private Ġval Ġcommand Gateway : ĠCommand Gateway , Ġprivate Ġval Ġquery Gateway : ĠQuery Gateway ) Ġ{ ĊĊĠĠĠ Ġprivate Ġval ĠcurrentUser : ĠString ĊĠĠĠĠĠĠĠ Ġget () Ġ= Ġif Ġ( SecurityContext Holder . getContext (). authentication Ġ!= Ġnull ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠSecurity Context Holder . getContext (). authentication . name ĊĠĠĠĠĠĠĠ Ġ} Ġelse Ġ" TEST " ĊĊĠĠĠ Ġprivate Ġval Ġaudit Entry : ĠAudit Entry ĊĠĠĠĠĠĠĠ Ġget () Ġ= ĠAudit Entry ( currentUser , ĠCalendar . getInstance (). time ) ĊĊĊĠĠĠ Ġ@ RequestMapping ( value Ġ= Ġ["/ co uri ers "], Ġmethod Ġ= Ġ[ Request Method . POST ], Ġconsume s Ġ= Ġ[ MediaType . APPLICATION _ JSON _ VALUE ]) ĊĠĠĠ Ġfun Ġcreate Courier (@ RequestBody Ġrequest : ĠCreate Courier Request , Ġresponse : ĠHttpServletResponse ): ĠResponseEntity < Any > Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcommand Ġ= ĠCreate Courier Command ( Person Name ( request . firstName , Ġrequest . lastName ), Ġrequest . max NumberOf Active Orders , Ġaudit Entry ) ĊĠĠĠĠĠĠĠ Ġquery Gateway . subscription Query ( Find Courier Query ( command . target Aggregate Identifier ), ĠResponse Types . instance Of < Courier Model >( Courier Model :: class . java ), ĠResponse Types . instance Of < Courier Model >( Courier Model :: class . java )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. use Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġcommand Result : ĠCour ier Id ? Ġ= Ġcommand Gateway . send And Wait ( command ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġcour ier Model Ġ= Ġit . updates (). block First () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġreturn ĠResponseEntity . ok (). build () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ RequestMapping ( value Ġ= Ġ["/ co uri ers /{ cid }/ orders /{ co id }/ assign "], Ġmethod Ġ= Ġ[ Request Method . PUT ], Ġconsume s Ġ= Ġ[ MediaType . APPLICATION _ JSON _ VALUE ]) ĊĠĠĠ Ġfun Ġassign Order To Courier (@ PathVariable Ġcid : ĠString , Ġ@ PathVariable Ġc oid : ĠString , Ġresponse : ĠHttpServletResponse ): ĠResponseEntity < Courier Order Model > Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcommand Ġ= ĠAssign Courier Order To Courier Command ( Courier OrderId ( co id ), ĠCour ier Id ( cid ), Ġaudit Entry ) ĊĠĠĠĠĠĠĠ Ġquery Gateway . subscription Query ( Find Courier Order Query ( command . target Aggregate Identifier ), ĠResponse Types . instance Of < Courier Order Model >( Courier Order Model :: class . java ), ĠResponse Types . instance Of < Courier Order Model >( Courier Order Model :: class . java )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. use Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġcommand Result : ĠCour ier OrderId ? Ġ= Ġcommand Gateway . send And Wait ( command ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġcour ier Order Model Ġ= Ġit . updates (). block First () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġreturn Ġif Ġ( Courier Order State . ASS IGNED Ġ== Ġcour ier Order Model ?. state ) ĠResponseEntity . ok (). build () Ġelse ĠResponseEntity . bad Request (). build () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ RequestMapping ( value Ġ= Ġ["/ co uri ers /{ cid }/ orders /{ co id }/ mark deliver ed "], Ġmethod Ġ= Ġ[ Request Method . PUT ], Ġconsume s Ġ= Ġ[ MediaType . APPLICATION _ JSON _ VALUE ]) ĊĠĠĠ Ġfun Ġmark Courier Order As Deliver ed (@ PathVariable Ġcid : ĠString , Ġ@ PathVariable Ġc oid : ĠString , Ġresponse : ĠHttpServletResponse ): ĠResponseEntity < Courier Order Model > Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcommand Ġ= ĠMark Courier Order As Deliver ed Command ( Courier OrderId ( co id ), Ġaudit Entry ) ĊĠĠĠĠĠĠĠ Ġquery Gateway . subscription Query ( Find Courier Order Query ( command . target Aggregate Identifier ), ĠResponse Types . instance Of < Courier Order Model >( Courier Order Model :: class . java ), ĠResponse Types . instance Of < Courier Order Model >( Courier Order Model :: class . java )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. use Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġcommand Result : ĠCour ier OrderId ? Ġ= Ġcommand Gateway . send And Wait ( command ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġcour ier Order Entity Ġ= Ġit . updates (). block First () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġreturn Ġif Ġ( Courier Order State . DE LI VER ED Ġ== Ġcour ier Order Entity ?. state ) ĠResponseEntity . ok (). build () Ġelse ĠResponseEntity . bad Request (). build () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ } Ċ Ċ /** Ċ Ġ* ĠA Ġrequest Ġfor Ġcreating Ġa ĠCour ier Ċ Ġ*/ Ċ data Ġclass ĠCreate Courier Request ( val ĠfirstName : ĠString , Ġval ĠlastName : ĠString , Ġval Ġmax NumberOf Active Orders : ĠInt ) Ċ