def query_video_op_get_by_op_id(op_id: str): """ :param: op_id, video operation unique id :return: an array of such video_op (len == 0 or 1), len == 0 if no such video_op_id, len == 1 if found """ return VideoOp.objects(id=op_id)
def query_video_op_get_by_user_video(user_id: str, video_id: str): """ :param: user_id, user's unique id :param: video_id, video's unique id :return: an array of such video_op (len == 0 or 1), len == 0 if no such video_op, len == 1 if found """ return VideoOp.objects(user_id=user_id, video_id=video_id)
def query_video_op_search_comment_by_pattern(comment): """ Search video op by comment pattern :param comment: comment pattern :return: result array of VideoOp Model """ # Check input param if type(comment) != re.Pattern: raise MongoError(ErrorCode.MONGODB_RE_PATTERN_EXPECTED) return VideoOp.objects(comment=comment)
def query_video_op_delete(op_id: str, silent=False): """ :param op_id: op's unique id :param silent: delete video op regardless of existence :return: 1 if succeeded, -1 if no such video """ if len(query_video_op_get_by_op_id(op_id)) == 0 and silent is False: # No such video op raise MongoError(ErrorCode.MONGODB_VIDEO_OP_NOT_FOUND) return VideoOp.objects(id=op_id).delete()
def util_tests_clean_database(): data = util_tests_load_data() for user in data['temp_user']: User.objects(user_name=user['user_name']).delete() for video in data['temp_video']: Video.objects(video_title=video['video_title']).delete() Video.objects(user_id=video['user_id']).delete() for video in data['const_video']: VideoOp.objects(video_id=video['_id']['$oid']).delete() Video.objects(user_id=data['const_user'][1]['_id']['$oid']).delete() Video.objects(video_title="new title").delete() Video.objects(video_title="").delete() VideoOp.objects(user_id=data['const_user'][1]['_id']['$oid']).delete() vop = data['const_video_op'][0] VideoOp(**vop).save()
def query_video_op_update_comment(op_id: str, comment: str, comment_date=get_time_now_utc()): """ :param: op_id, video op unique id :param: comment, video comment :param: comment_date (optional, default utc now) :return: 1 if succeeded, -1 if no such video_op """ if len(query_video_op_get_by_op_id(op_id)) == 0: # No such video op raise MongoError(ErrorCode.MONGODB_VIDEO_OP_NOT_FOUND) return VideoOp.objects(id=op_id) \ .update(comment=comment, comment_date=comment_date)
def query_video_op_update_process(op_id: str, process: int, process_date=get_time_now_utc()): """ :param: op_id, video op unique id :param: process, video watching process :param: process_date (optional, default utc now) :return: 1 if succeeded, -1 if no such video_op """ if len(query_video_op_get_by_op_id(op_id)) == 0: # No such video op raise MongoError(ErrorCode.MONGODB_VIDEO_OP_NOT_FOUND) return VideoOp.objects(id=op_id) \ .update(process=process, process_date=process_date)
def query_video_op_update_star(op_id: str, star: bool, star_date=get_time_now_utc()): """ :param: op_id, video op unique id :param: star, video star (boolean) :param: star_date (optional, default utc now) :return: 1 if succeeded, -1 if no such video_op """ if len(query_video_op_get_by_op_id(op_id)) == 0: # No such video op raise MongoError(ErrorCode.MONGODB_VIDEO_OP_NOT_FOUND) return VideoOp.objects(id=op_id)\ .update(star=star, star_date=star_date)
def query_video_op_get_by_video_id(video_id: str): """ :param: video_id, video's unique id :return: an array of such video_op, len == 0 if no such video_op """ return VideoOp.objects(video_id=video_id)
def query_video_op_get_by_user_id(user_id: str): """ :param: user_id, user's unique id :return: an array of such video_op, len == 0 if no such video_op """ return VideoOp.objects(user_id=user_id)