def AddProduct(self,Commands:list): for Command in Commands: NewProduct = Product() Events = NewProduct.processForProductCreationCommand(Command) NewProduct.applyForProductCreationEvent(Events[0]) ProductRepository().Create((NewProduct,),Events) return f'Products inserted successfully'
def ConnectProductToOrder(self, ProductName): # prepei try catch for Entity in self.session.execute( "SELECT MIN(EventTime), EntityId, EntityType FROM Snapshots WHERE SnapshotType = %s and SemantickLock = %s LIMIT 1 ALLOW FILTERING ", [ProductName, 'Unlock']): try: for product in self.session.execute( "SELECT EntityId, EntityType, SnapshotData FROM Snapshots WHERE EventTime = %s ALLOW FILTERING", [Entity.system_min_eventtime]): UpdatedRow = self.session.execute( "UPDATE Snapshots SET SemantickLock = %s WHERE EntityId = %s and EntityType = %s IF SemantickLock = %s", [ 'Locked', product.entityid, product.entitytype, 'Unlock' ]) if UpdatedRow[0].applied: return product.snapshotdata else: NewProduct = Product() Event = ProductInsertedEvent(str(randint(0, 1000)), ProductName, 'Free') NewProduct.applyForProductCreationEvent(Event) self.Create((NewProduct, ), (Event, )) raise NotAvailableProduct() except Exception: NewProduct = Product() Event = ProductInsertedEvent(str(randint(0, 1000)), ProductName, 'Free') NewProduct.applyForProductCreationEvent(Event) self.Create((NewProduct, ), (Event, )) raise NotAvailableProduct()