def get_selected( resources_ids: Optional[List[ResourceId]] = None, start: Optional[str] = None, end: Optional[str] = None ) -> Tuple[Union[List[Any], Content], HttpStatusCode]: # TODO This may need a decent refactor - give more freedom # All args are required at once, otherwise return 400 all_not_none = resources_ids and start and end if all_not_none: try: start_as_datetime = DateUtils.parse_string(start) ends_as_datetime = DateUtils.parse_string(end) matches = list( Reservation.filter_by_uuids_and_time_range( resources_ids, start_as_datetime, ends_as_datetime)) matches = [match.as_dict() for match in matches] except (ValueError, AssertionError) as reason: content = {'msg': '{}. {}'.format(GENERAL['bad_request'], reason)} status = 400 except Exception as e: content = {'msg': GENERAL['internal_error'] + str(e)} status = 500 else: content = matches # type: ignore status = 200 else: content = {'msg': GENERAL['bad_request']} status = 400 return content, status
def get_selected(resources_ids: List, start: str, end: str): # TODO This may need a decent refactor - give more freedom # All args are required at once, otherwise return 400 all_not_none = resources_ids and start and end if all_not_none: try: start_as_datetime = Reservation.parsed_input_datetime(start) ends_as_datetime = Reservation.parsed_input_datetime(end) matches = list(Reservation.filter_by_uuids_and_time_range( resources_ids, start_as_datetime, ends_as_datetime)) matches = [match.as_dict for match in matches] except (ValueError, AssertionError) as reason: content = {'msg': '{}. {}'.format(G['bad_request'], reason)} status = 400 except Exception: content = {'msg': G['internal_error']} status = 500 else: content = matches # type: ignore status = 200 else: content = {'msg': G['bad_request']} status = 400 return content, status