def detach_door(controller_id: int, door_id: int): controller = get(controller_id) door = DoorService.get(door_id) if controller.doors.filter(id=door_id) == 0: raise exceptions.DoorNotFound try: controller.doors.remove(door) except: raise exceptions.ControllerManageFailed
def detach_door(place_id: int, door_id: int): place = get(place_id) door = DoorService.get(door_id) if place.doors.filter(id=door_id).count() == 0: raise exceptions.PlaceManageFailed try: place.doors.remove(door) except: raise exceptions.PlaceManageFailed
def attach_door(controller_id: int, door_id: int): controller = get(controller_id) door = DoorService.get(door_id) if controller.doors.filter(id=door_id).count() > 0: raise exceptions.DoorNotFound try: controller.doors.add(door) except: raise exceptions.ControllerManageFailed
def get(self, request: HttpRequest, id: str): id = self.parse_int_pk(id) door = DoorService.get(id) return ApiResponse.success(DoorOutDto.from_door(door))