def create(rental): # Validate in persistence level validatorResponse = RentalValidator.validateCreate(rental) if FieldKey.ERROR in validatorResponse: return validatorResponse # Create and process Tasks processor = TaskProcessor() processor.add(SaveNewEntityTask(rental)) processor.process() # Return Result return {FieldKey.SUCCESS: rental}
def update(updatedImage): # Validate in persistence level validatorResponse = ImageValidator.validateUpdate(updatedImage) if FieldKey.ERROR in validatorResponse: return validatorResponse # Create and process Tasks processor = TaskProcessor() processor.add( UpdateEntityTask(Image, ImageService.mergeImages, updatedImage)) processor.process() # Return Result image = ReadOnlyAccess.getEntityCopy(Image, updatedImage.id) return {FieldKey.SUCCESS: image}
def update(updatedRental): # Validate in persistence level validatorResponse = RentalValidator.validateUpdate(updatedRental) if FieldKey.ERROR in validatorResponse: return validatorResponse # Create and process Tasks processor = TaskProcessor() processor.add( UpdateEntityTask(Rental, RentalService.mergeRentals, updatedRental)) processor.process() # Return Result rental = ReadOnlyAccess.getEntityCopy(Rental, updatedRental.id) return {FieldKey.SUCCESS: rental}
def delete(customerId, viewingId): # Validate in persistence level validatorResponse = ViewingValidator.validateDelete( customerId, viewingId) if FieldKey.ERROR in validatorResponse: return validatorResponse # Get return copy, before delete viewing = ReadOnlyAccess.getEntityCopy(Viewing, viewingId) # Create and process Tasks processor = TaskProcessor() processor.add(DeleteEntityTask(Viewing, viewingId)) processor.process() # Return Result return {FieldKey.SUCCESS: viewing}
def update(updatedViewing): # Validate in persistence level validatorResponse = ViewingValidator.validateUpdate(updatedViewing) if FieldKey.ERROR in validatorResponse: return validatorResponse # Create and process Tasks processor = TaskProcessor() processor.add( UpdateEntityTask(Viewing, ViewingService.mergeViewings, updatedViewing)) processor.process() # Return Result viewing = ReadOnlyAccess.getEntityCopy(Viewing, updatedViewing.id) return {FieldKey.SUCCESS: viewing}
def add(image): # Validate in persistence level validatorResponse = ImageValidator.validateCreate(image) if FieldKey.ERROR in validatorResponse: return validatorResponse # Get Property Info property = ReadOnlyAccess.getEntityCopy(Property, image.propertyId) # Create and process Tasks processor = TaskProcessor() processor.add( SaveToFileSystemTask("images", property.ownerId, image.id, image.file, "jpg")) processor.add(SaveNewEntityTask(image)) processor.process() # Return Result return {FieldKey.SUCCESS: image}
def setMain(propertyId, imageId): # Validate in persistence level validatorResponse = ImageValidator.validateSetMain(propertyId, imageId) if FieldKey.ERROR in validatorResponse: return validatorResponse # Create Updated Property updatedProperty = Property() updatedProperty.id = propertyId updatedProperty.mainImageId = imageId # Create and process Tasks processor = TaskProcessor() processor.add( UpdateEntityTask(Property, PropertyService.mergeProperties, updatedProperty)) processor.process() property = ReadOnlyAccess.getEntityCopy(Property, propertyId) return {FieldKey.SUCCESS: property}
def remove(propertyId, imageId): # Validate in persistence level validatorResponse = ImageValidator.validateDelete(propertyId, imageId) if FieldKey.ERROR in validatorResponse: return validatorResponse # Get return copy, before delete image = ReadOnlyAccess.getEntityCopy(Image, imageId) property = ReadOnlyAccess.getEntityCopy(Property, propertyId) # Create and process Tasks processor = TaskProcessor() processor.add( RemoveFromFileSystemTask("images", property.ownerId, imageId, "jpg")) processor.add(DetachForeignKeyTask(Property, "mainImageId", imageId)) processor.add(DeleteEntityTask(Image, imageId)) processor.add(FlushDirectoryTask("images", [])) processor.process() # Return Result return {FieldKey.SUCCESS: image}