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 toDomain(rentalResource): rental = Rental() rental.id = rentalResource[ RentalField.ID] if RentalField.ID in rentalResource else None rental.customer = rentalResource[ RentalField. CUSTOMER] if RentalField.CUSTOMER in rentalResource else None rental.property = rentalResource[ RentalField. PROPERTY] if RentalField.PROPERTY in rentalResource else None rental.agent = rentalResource[ RentalField.AGENT] if RentalField.AGENT in rentalResource else None rental.rent = rentalResource[ RentalField.RENT] if RentalField.RENT in rentalResource else None rental.start = Date.formatDate( rentalResource[RentalField.START] ) if RentalField.START in rentalResource else None rental.end = Date.formatDate(rentalResource[ RentalField.END]) if RentalField.END in rentalResource else None rental.status = rentalResource[ RentalField. STATUS] if RentalField.STATUS in rentalResource else None return rental