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))
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')
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))
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)
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 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()
def get(self, request: HttpRequest, id: str): id = self.parse_int_pk(id) place = PlaceService.get(id) return ApiResponse.success(PlaceOutDto.from_place(place))
def post(self, request: HttpRequest, dto: ControllerInDto): controller = ControllerService.create(dto.name, dto.controller_id) return ApiResponse.success(ControllerOutDto.from_controller(controller))
def delete(self, request: HttpRequest, id: str): id = self.parse_int_pk(id) ControllerService.delete(id) return ApiResponse.success()
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 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))
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))
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 get(self, request: HttpRequest): keys = KeyService.get_all() key_dtos = list([KeyOutDto.from_key(k) for k in keys]) return ApiResponse.success(key_dtos)
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()
def put(self, request: HttpRequest, id: str, dto: PlaceInDto): id = self.parse_int_pk(id) place = PlaceService.update(id, dto.name) return ApiResponse.success(PlaceOutDto.from_place(place))
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()
def post(self, request: HttpRequest, dto: ParentDto): if not dto.is_valid(): return ApiResponse.bad_request(dto) return ApiResponse.success(dto)
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)
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 get(self, request: HttpRequest): controllers = ControllerService.get_all() controller_dtos = list([ControllerOutDto.from_controller(c) for c in controllers]) return ApiResponse.success(controller_dtos)
def get(self, request: HttpRequest): places = PlaceService.get_all() place_dtos = list([PlaceOutDto.from_place(p) for p in places]) return ApiResponse.success(place_dtos)
def get(self, request: HttpRequest, id: str): id = self.parse_int_pk(id) controller = ControllerService.get(id) return ApiResponse.success(ControllerOutDto.from_controller(controller))
def get(self, request: HttpRequest, id: str): id = self.parse_int_pk(id) person = PersonService.get(id) return ApiResponse.success(PersonOutDto.from_person(person))
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)
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))
def post(self, request: HttpRequest, dto: PersonInDto): person = PersonService.create(dto.name) return ApiResponse.success(PersonOutDto.from_person(person))
def post(self, request: HttpRequest, dto: PlaceInDto): place = PlaceService.create(dto.name) return ApiResponse.success(PlaceOutDto.from_place(place))