def get(self, user_id: str) -> Iterable[Union[Mapping, int, None]]: """ Return a list of resources that user has followed :param user_id: :return: """ try: resources = self.client.get_table_by_user_relation(user_email=user_id, relation_type=UserResourceRel.follow) table_key = ResourceType.Table.name.lower() dashboard_key = ResourceType.Dashboard.name.lower() result = { table_key: [], dashboard_key: [] } # type: Dict[str, List[Any]] if resources and table_key in resources and len(resources[table_key]) > 0: result[table_key] = PopularTableSchema().dump(resources[table_key], many=True) resources = self.client.get_dashboard_by_user_relation(user_email=user_id, relation_type=UserResourceRel.follow) if resources and dashboard_key in resources and len(resources[dashboard_key]) > 0: result[dashboard_key] = DashboardSummarySchema().dump(resources[dashboard_key], many=True) return result, HTTPStatus.OK except NotFoundException: return {'message': 'user_id {} does not exist'.format(user_id)}, HTTPStatus.NOT_FOUND except Exception: LOGGER.exception('UserFollowAPI GET Failed') return {'message': 'Internal server error!'}, HTTPStatus.INTERNAL_SERVER_ERROR
def get(self) -> Iterable[Union[Mapping, int, None]]: limit = request.args.get('limit', 10, type=int) popular_tables: List[PopularTable] = self.client.get_popular_tables( num_entries=limit) popular_tables_json: str = PopularTableSchema( many=True).dump(popular_tables).data return {'popular_tables': popular_tables_json}, HTTPStatus.OK
def get(self, user_id: str) -> Iterable[Union[Mapping, int, None]]: """ Return a list of resources that user has read :param user_id: :return: """ try: resources = self.client.get_frequently_used_tables( user_email=user_id) if len(resources['table']) > 0: return { 'table': PopularTableSchema(many=True).dump(resources['table']).data }, HTTPStatus.OK return {'table': []}, HTTPStatus.OK except NotFoundException: return { 'message': 'user_id {} does not exist'.format(user_id) }, HTTPStatus.NOT_FOUND except Exception: LOGGER.exception('UserReadsAPI GET Failed') return { 'message': 'Internal server error!' }, HTTPStatus.INTERNAL_SERVER_ERROR
def get(self, user_id: Optional[str] = None ) -> Iterable[Union[Mapping, int, None]]: limit = request.args.get('limit', 10, type=int) popular_tables: List[PopularTable] = self.client.get_popular_tables( num_entries=limit, user_id=user_id) popular_tables_json: str = PopularTableSchema().dump(popular_tables, many=True) return {'popular_tables': popular_tables_json}, HTTPStatus.OK
def marshall_table_partial(table_dict: Dict) -> Dict: """ Forms a short version of a table Dict, with selected fields and an added 'key' :param table_dict: Dict of partial table object :return: partial table Dict TODO - Unify data format returned by search and metadata. """ schema = PopularTableSchema() table: PopularTable = schema.load(table_dict, unknown=EXCLUDE) results = schema.dump(table) # TODO: fix popular tables to provide these? remove if we're not using them? # TODO: Add the 'key' or 'id' to the base PopularTableSchema results[ 'key'] = f'{table.database}://{table.cluster}.{table.schema}/{table.name}' results['last_updated_timestamp'] = None results['type'] = 'table' return results