def update(propertyId, imageId, imageResource): # Authenticate authenticator = Authenticator(request.headers.get( HeaderKey.TOKEN)).allowAgent().allowOwnerOf( Property, "ownerId", propertyId) authentification = authenticator.authenticate() if FieldKey.ERROR in authentification: return ResponseFormatter.getFormattedValidatorResponse( authentification) # Validate Resource imageResourceValidation = ImageValidator.validateUpdate(imageResource) if FieldKey.ERROR in imageResourceValidation: return ResponseFormatter.getFormattedValidatorResponse( imageResourceValidation) # Create Domain Instance image = ImageConverter.toDomain(imageResource) image.id = imageId image.propertyId = propertyId # Call Service Layer response = ImageService.update(image) return ResponseFormatter.getFormmattedServiceResponse( ImageConverter.toResource, response)
def create(rentalResource): # Authenticate authenticator = Authenticator(request.headers.get( HeaderKey.TOKEN)).allowAgent().allowCustomer( rentalResource[RentalField.CUSTOMER]) authentification = authenticator.authenticate() if FieldKey.ERROR in authentification: return ResponseFormatter.getFormattedValidatorResponse( authentification) # Validate Resource rentalResourceValidation = RentalValidator.validateCreate( rentalResource) if FieldKey.ERROR in rentalResourceValidation: return ResponseFormatter.getFormattedValidatorResponse( rentalResourceValidation) # Create Domain Instance rental = RentalConverter.toDomain(rentalResource) rental.id = IdGenerator.generate() rental.status = RentalStatus.PROPOSED # Call Service Layer response = RentalService.create(rental) return ResponseFormatter.getFormmattedServiceResponse( RentalConverter.toResource, response)
def update(rentalId, rentalResource): # Authenticate authenticator = Authenticator(request.headers.get( HeaderKey.TOKEN)).allowAgent().allowOwnerOf( Rental, "customer", rentalId) authentification = authenticator.authenticate() if FieldKey.ERROR in authentification: return ResponseFormatter.getFormattedValidatorResponse( authentification) # Validate Resource rentalResourceValidation = RentalValidator.validateUpdate( rentalResource) if FieldKey.ERROR in rentalResourceValidation: return ResponseFormatter.getFormattedValidatorResponse( rentalResourceValidation) # Create Domain Instance rental = RentalConverter.toDomain(rentalResource) rental.id = rentalId rental.status = RentalStatus.PROPOSED # Call Service Layer response = RentalService.update(rental) return ResponseFormatter.getFormmattedServiceResponse( RentalConverter.toReso0urce, response)
def update(accountId, accountResource): # Authenticate authenticator = Authenticator(request.headers.get( HeaderKey.TOKEN)).allowAgent().allowCustomer(accountId).allowOwner( accountId) authentification = authenticator.authenticate() if FieldKey.ERROR in authentification: return ResponseFormatter.getFormattedValidatorResponse( authentification) # Validate Resource accountResourceValidation = AccountValidator.validateUpdate( accountResource) if FieldKey.ERROR in accountResourceValidation: return ResponseFormatter.getFormattedValidatorResponse( accountResourceValidation) # Create Domain Instance account = AccountConverter.toDomain(accountResource) account.id = accountId credential = CredentialFactory.createDomain( account.id, accountResource[AccountField.PASSWORD]) # Call Service Layer response = AccountService.update(account, credential) return ResponseFormatter.getFormmattedServiceResponse( AccountConverter.toResource, response)
def cancel(rentalId): # Authenticate authenticator = Authenticator(request.headers.get( HeaderKey.TOKEN)).allowAgent() authentification = authenticator.authenticate() if FieldKey.ERROR in authentification: return ResponseFormatter.getFormattedValidatorResponse( authentification) # Create Domain Instance rental = Rental() rental.id = rentalId rental.status = RentalStatus.CANCELLED # Call Service Layer response = RentalService.update(rental) return ResponseFormatter.getFormmattedServiceResponse( RentalConverter.toResource, response)
def add(propertyId): # Authentication authenticator = Authenticator(request.headers.get( HeaderKey.TOKEN)).allowAgent().allowOwnerOf( Property, "ownerId", propertyId) authentification = authenticator.authenticate() if FieldKey.ERROR in authentification: return ResponseFormatter.getFormattedValidatorResponse( authentification) # Create Domain Instance image = ImageFactory.createDomain() image.id = IdGenerator.generate() image.propertyId = propertyId image.file = request.files.get("image") # Call Service Layer response = ImageService.add(image) return ResponseFormatter.getFormmattedServiceResponse( ImageConverter.toResource, response)