Ejemplo n.º 1
0
 def getAll(customerId):
     # Authenticate
     authenticator = Authenticator(request.headers.get(HeaderKey.TOKEN)).allowAgent().allowCustomer(customerId)
     authentification = authenticator.authenticate()
     if FieldKey.ERROR in authentification:
         return ResponseFormatter.getFormattedValidatorResponse(authentification)
     # Call Service Layer
     response = ViewingService.readAll(customerId)
     return ResponseFormatter.getFormmattedServiceListResponse(ViewingConverter.toResource, response)
Ejemplo n.º 2
0
 def readAll(ownerId):
     # Authenticate
     authenticator = Authenticator(request.headers.get(HeaderKey.TOKEN)).allowAgent().allowOwner(ownerId)
     authentification = authenticator.authenticate()
     if FieldKey.ERROR in authentification:
         return ResponseFormatter.getFormattedValidatorResponse(authentification)
     # Call Service Layer
     response = PropertyService.readAll(ownerId)
     return ResponseFormatter.getFormmattedServiceListResponse(PropertyConverter.toResource, response)
Ejemplo n.º 3
0
 def history(ownerId):
     # Authenticate
     authenticator = Authenticator(request.headers.get(HeaderKey.TOKEN)).allowAgent().allowOwner(ownerId)
     authentification = authenticator.authenticate()
     if FieldKey.ERROR in authentification:
         return ResponseFormatter.getFormattedValidatorResponse(authentification)
     # Create Domain Instance
     start = request.args.get('start', default=None, type=str)
     end = request.args.get('end', default=None, type=str)
     # Call Service Layer
     response = PropertyService.history(ownerId, start, end)
     return ResponseFormatter.getFormmattedServiceListResponse(PropertyConverter.toResource, response)
Ejemplo n.º 4
0
 def read(rentalId):
     # 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)
     # Call Service Layer
     response = RentalService.read(rentalId)
     return ResponseFormatter.getFormmattedServiceResponse(
         RentalConverter.toResource, response)
Ejemplo n.º 5
0
 def delete(accountId):
     # 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)
     # Call Service Layer
     response = AccountService.delete(accountId)
     return ResponseFormatter.getFormmattedServiceResponse(
         AccountConverter.toResource, response)
Ejemplo n.º 6
0
 def remove(propertyId, imageId):
     # 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)
     # Call Service Layer
     response = ImageService.remove(propertyId, imageId)
     return ResponseFormatter.getFormmattedServiceResponse(
         ImageConverter.toResource, response)
Ejemplo n.º 7
0
 def update(customerId, viewingId, viewingResource):
     # Authenticate
     authenticator = Authenticator(request.headers.get(HeaderKey.TOKEN)).allowAgent().allowCustomer(customerId)
     authentification = authenticator.authenticate()
     if FieldKey.ERROR in authentification:
         return ResponseFormatter.getFormattedValidatorResponse(authentification)
     # Validate Resource
     viewingResourceValidation = ViewingValidator.validateUpdate(viewingResource)
     if FieldKey.ERROR in viewingResourceValidation:
         return ResponseFormatter.getFormattedValidatorResponse(viewingResourceValidation)
     # Create Domain Instance
     viewing = ViewingConverter.toDomain(viewingResource)
     viewing.id = viewingId
     # Call Service Layer
     response = ViewingService.update(viewing)
     return ResponseFormatter.getFormmattedServiceResponse(ViewingConverter.toResource, response)
Ejemplo n.º 8
0
 def update(ownerId, propertyId, propertyResource):
     # Authenticate
     authenticator = Authenticator(request.headers.get(HeaderKey.TOKEN)).allowAgent().allowOwner(ownerId)
     authentification = authenticator.authenticate()
     if FieldKey.ERROR in authentification:
         return ResponseFormatter.getFormattedValidatorResponse(authentification)
     # Validate Resource
     propertyResourceValidation = PropertyValidator.validateUpdate(propertyResource)
     if FieldKey.ERROR in propertyResourceValidation:
         return ResponseFormatter.getFormattedValidatorResponse(propertyResourceValidation)
     # Create Domain Instance
     property = PropertyConverter.toDomain(propertyResource)
     property.id = propertyId
     # Call Service Layer
     response = PropertyService.update(ownerId, property)
     return ResponseFormatter.getFormmattedServiceResponse(PropertyConverter.toResource, response)
Ejemplo n.º 9
0
 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)
Ejemplo n.º 10
0
 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)
Ejemplo n.º 11
0
 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)
Ejemplo n.º 12
0
 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)
Ejemplo n.º 13
0
 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)
Ejemplo n.º 14
0
 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)