Beispiel #1
0
def jb_exception_handler(exc, context):
    if isinstance(exc, exceptions.EntityNotFound):
        return ApiResponse.not_found(exc.error_code)
    if isinstance(exc, exceptions.BadDataException):
        return ApiResponse.bad_request(exc.error_code.dto_or_error_message, exc.error_code.error_code)
    if isinstance(exc, exceptions.JbAccessException):
        return ApiResponse.bad_request(exc.error_code.dto_or_error_message, exc.error_code.error_code)
    return exception_handler(exc, context)
def error_handler(exc, context):
    if isinstance(exc, MethodNotAllowed):
        return ApiResponse.bad_request('Request method error')
    if isinstance(exc, ControlledError):
        if isinstance(exc, NotFoundError):
            return ApiResponse.not_found(exc.error_code)
        if isinstance(exc, NotUniqueError):
            return ApiResponse.bad_request(exc.error_code)
    return exception_handler(exc, context)
Beispiel #3
0
    def post(self, request: HttpRequest):
        try:
            decoded_body = request.body.decode("utf-8")

            if request.content_type in self.URL_ENCODED_CONTENT_TYPES:
                decoded_body = urllib.parse.unquote_plus(
                    decoded_body)  #self._query_dict_to_str(request.POST)

            message = _helloService.echo(decoded_body)
            return ApiResponse.success(HelloResponseDto(message))

        except UnicodeDecodeError:
            return ApiResponse.bad_request(
                'Cannot convert POST data to string')
Beispiel #4
0
 def post(self, request: HttpRequest):
     dto = CalculationRequestDto.from_dict(request.data)
     if not dto.is_valid():
         return ApiResponse.bad_request(dto)
     task = CalculationService.CalculationTask(arg1=dto.arg1,
                                               arg2=dto.arg2,
                                               operator=dto.operator)
     try:
         result = CalculationService.calculate(task)
         return ApiResponse.success(
             CalculationResultDto.from_calculation_result(result))
     except Exception as e:  # Should be more concrete
         return ApiResponse.bad_request(
             "Unable to calculate your expression: " + str(e))
Beispiel #5
0
 def wrapped(*args, **kwargs):
     request = args[1]
     dto_object = dto_class.from_dict(request.data)
     if not dto_object.is_valid():
         return ApiResponse.bad_request(dto_object)
     kwargs.setdefault(dto_object_name, dto_object)
     return func(*args, **kwargs)
 def put(self, request: HttpRequest, id: str, dto: ControllerInDto):
     id = self.parse_int_pk(id)
     controller = ControllerService.update(id,
                                           name=dto.name,
                                           controller_id=dto.controller_id)
     return ApiResponse.success(
         ControllerOutDto.from_controller(controller))
 def get(self, request: HttpRequest, controller_id: str):
     controller_id = self.parse_int_pk(controller_id)
     resolved_acls = AclService.resolve_acls_by_controller(controller_id)
     acl_dtos = list([
         ResolvedAclOutDto.from_values(a[0], a[1], a[2], a[3])
         for a in resolved_acls
     ])
     return ApiResponse.success(acl_dtos)
 def post(self, request: HttpRequest, id: str, dto: SimplePatternInDto):
     id = self.parse_int_pk(id)
     pattern = AclService.create_pattern(id,
                                         dto.validated_data['from_time'],
                                         dto.validated_data['until_time'],
                                         dto.days_of_week,
                                         dto.days_of_month, dto.months)
     return ApiResponse.success(
         SimplePatternOutDto.from_simple_pattern(pattern))
Beispiel #9
0
 def put(self, request: HttpRequest, person_id: str, place_id: str):
     person_id = self.parse_int_pk(person_id)
     place_id = self.parse_int_pk(place_id)
     acl = AclService.person_allow_place(person_id, place_id)
     return ApiResponse.success(PersonAclOutDto.from_person_acl(acl))
Beispiel #10
0
 def get(self, request: HttpRequest, id: str):
     id = self.parse_int_pk(id)
     acls = AclService.get_person_acls(id)
     acl_dtos = list([PersonAclOutDto.from_person_acl(a) for a in acls])
     return ApiResponse.success(acl_dtos)
Beispiel #11
0
 def delete(self, request: HttpRequest, person_id: str, role_id: str):
     person_id = self.parse_int_pk(person_id)
     role_id = self.parse_int_pk(role_id)
     PersonService.detach_role(person_id, role_id)
     return ApiResponse.success()
Beispiel #12
0
 def get(self, request: HttpRequest, id: str):
     id = self.parse_int_pk(id)
     roles = PersonService.get_roles(id)
     key_dtos = list([RoleOutDto.from_role(r) for r in roles])
     return ApiResponse.success(key_dtos)
 def get(self, request: HttpRequest):
     keys = KeyService.get_all()
     key_dtos = list([KeyOutDto.from_key(k) for k in keys])
     return ApiResponse.success(key_dtos)
Beispiel #14
0
 def post(self, request: HttpRequest, dto: PersonInDto):
     person = PersonService.create(dto.name)
     return ApiResponse.success(PersonOutDto.from_person(person))
Beispiel #15
0
 def get(self, request: HttpRequest, id: str):
     id = self.parse_int_pk(id)
     controller = ControllerService.get(id)
     return ApiResponse.success(ControllerOutDto.from_controller(controller))
Beispiel #16
0
 def post(self, request: HttpRequest, dto: ParentDto):
     if not dto.is_valid():
         return ApiResponse.bad_request(dto)
     return ApiResponse.success(dto)
Beispiel #17
0
 def get(self, request: HttpRequest):
     personnel = PersonService.get_all()
     person_dtos = list([PersonOutDto.from_person(p) for p in personnel])
     return ApiResponse.success(person_dtos)
 def put(self, request: HttpRequest, id: str, dto: KeyInDto):
     id = self.parse_int_pk(id)
     key = KeyService.update(id, dto.name, dto.access_key, dto.person_id)
     return ApiResponse.success(KeyOutDto.from_key(key))
 def get(self, request: HttpRequest, id: str):
     id = self.parse_int_pk(id)
     key = KeyService.get(id)
     return ApiResponse.success(KeyOutDto.from_key(key))
 def post(self, request: HttpRequest, dto: KeyInDto):
     key = KeyService.create(dto.name, dto.access_key, dto.person_id)
     return ApiResponse.success(KeyOutDto.from_key(key))
Beispiel #21
0
 def get(self, request: HttpRequest):
     controllers = ControllerService.get_all()
     controller_dtos = list([ControllerOutDto.from_controller(c) for c in controllers])
     return ApiResponse.success(controller_dtos)
Beispiel #22
0
 def get(self, request: HttpRequest, id: str):
     id = self.parse_int_pk(id)
     doors = ControllerService.get_doors(id)
     door_dtos = list([DoorOutDto.from_door(d) for d in doors])
     return ApiResponse.success(door_dtos)
Beispiel #23
0
 def post(self, request: HttpRequest, dto: ControllerInDto):
     controller = ControllerService.create(dto.name, dto.controller_id)
     return ApiResponse.success(ControllerOutDto.from_controller(controller))
Beispiel #24
0
 def get(self, request: HttpRequest):
     return ApiResponse.not_found(errors.NOT_SUPPORTED)
Beispiel #25
0
 def delete(self, request: HttpRequest, id: str):
     id = self.parse_int_pk(id)
     ControllerService.delete(id)
     return ApiResponse.success()
Beispiel #26
0
 def delete(self, request: HttpRequest, place_id: str, door_id: str):
     place_id = self.parse_int_pk(place_id)
     door_id = self.parse_int_pk(door_id)
     PlaceService.detach_door(place_id, door_id)
     return ApiResponse.success()
Beispiel #27
0
 def delete(self, request: HttpRequest, controller_id: str, door_id: str):
     controller_id = self.parse_int_pk(controller_id)
     door_id = self.parse_int_pk(door_id)
     ControllerService.detach_door(controller_id, door_id)
     return ApiResponse.success()
Beispiel #28
0
 def put(self, request: HttpRequest, id: str, dto: PersonInDto):
     id = self.parse_int_pk(id)
     person = PersonService.update(id, dto.name)
     return ApiResponse.success(PersonOutDto.from_person(person))
Beispiel #29
0
 def get(self, request: HttpRequest, id: str):
     id = self.parse_int_pk(id)
     person = PersonService.get(id)
     return ApiResponse.success(PersonOutDto.from_person(person))
Beispiel #30
0
 def get(self, request: HttpRequest, id: str):
     id = self.parse_int_pk(id)
     keys = PersonService.get_keys(id)
     key_dtos = list([KeyOutDto.from_key(k) for k in keys])
     return ApiResponse.success(key_dtos)