def SellOrNotSellProduct(self,Command:SellOrNotSellProductCommand): UpdatedProduct = Product() Saga = SagaParticipant() Events, SnapshotData = ProductRepository().Find(Command.SagaId,Command.SagaType) Saga.Revise(SnapshotData,Events) Events, SnapshotData = ProductRepository().Find(Saga.Data['ProductId'],'Product') UpdatedProduct.Revise(SnapshotData,Events) Events = UpdatedProduct.proccess_SellOrNotSellProductCommand(Command) UpdatedProduct.apply_ProductSoldOrNotSoldEvent(Events[0]) ProductRepository().Update((UpdatedProduct,),Events,MessageId=Command.MessageId)
def ValidateOrderProduct(self,Command): try: SnapshotData = ProductRepository().ConnectProductToOrder(Command.ProductName) except NotAvailableProduct: SnapshotData = ProductRepository().ConnectProductToOrder(Command.ProductName) UpdatedProduct = Product() UpdatedProduct.Revise(SnapshotData,[]) Events = UpdatedProduct.proccessOrderProductValidationCommand(Command) UpdatedProduct.applyProductValidatedEvent(Events[0]) Saga = SagaParticipant() Saga.Create(Command.OrderId,Command.SagaType,Events[1].EventJsonData()) ProductRepository().Update((UpdatedProduct,Saga),Events,MessageId=Command.MessageId)