def item_list(): user_id = int(request.args['user_id']) type = int(request.args.get('type', 1)) offset = int(request.args.get('offset', 0)) count = int(request.args.get('count', 10)) # 获取短视频信息 items = item_service.get_item_list(type=type, offset=offset, count=count) # 获取用户身份信息 ids = [item.user_id for item in items] user_info_dict = get_user_info_dict_for_ids(ids) item_ids = [item.item_id for item in items] # 获取点赞关系(非核心) try: status = relation_service.get_love_status(user_id, item_ids) except: status = [False for item in items] # 获取点赞数(非核心) try: counts = relation_service.get_love_count(item_ids) except: counts = [0 for item in items] item_list = [] for i, item in enumerate(items): item_list.append({ 'item_id': item.item_id, 'user_id': item.user_id, 'nickname': user_info_dict[item.user_id].nickname, 'head_img_url': user_info_dict[item.user_id].head_img_url, 'img': oss.get_img_url(item.video), 'video': oss.get_video_url(item.video), 'text': item.text, 'click': item.click, 'create_time': item.create_time, 'love_status': status[i], 'love_count': counts[i], }) return success_response(item_list)
def item_one(): user_id = int(request.args['user_id']) item_id = int(request.args['item_id']) item = item_service.get_item_by_id(item_id) user_info = user_service.get_user_info(item.user_id) # 获取关注关系(非核心) try: follow_status = relation_service.get_follow_status( user_id, [item.user_id])[0] except: follow_status = False # 获取点赞关系(非核心) try: status = relation_service.get_love_status(user_id, [item.item_id])[0] except: status = False # 获取点赞数(非核心) try: love_count = relation_service.get_love_count([item.item_id])[0] except: love_count = 0 item_info = { 'item_id': item.item_id, 'user_id': item.user_id, 'nickname': user_info.nickname, 'head_img_url': user_info.head_img_url, 'img': oss.get_img_url(item.video), 'video': oss.get_video_url(item.video), 'text': item.text, 'click': item.click, 'create_time': item.create_time, 'love_status': status, 'love_count': love_count, 'follow_status': follow_status, } return success_response(item_info)
def item_list_for_user(): user_id = int(request.args['user_id']) offset = request.args.get('offset', 0) count = request.args.get('count', 10) items = item_service.get_item_list(offset=offset, count=count, user_id=user_id) item_list = [] for i, item in enumerate(items): item_list.append({ 'item_id': item.item_id, 'user_id': item.user_id, 'img': oss.get_img_url(item.video), 'video': oss.get_video_url(item.video), 'text': item.text, 'click': item.click, 'create_time': item.create_time }) return success_response(item_list)