Exemple #1
0
def service_user_get_process(user_id):

    # user_id check
    if not is_valid_id(user_id):
        raise ServiceError(ErrorCode.SERVICE_INVALID_ID_OBJ)

    if len(query_user_get_by_id(user_id)) <= 0:
        raise ServiceError(ErrorCode.SERVICE_USER_NOT_FOUND)

    # perform db operations and get result
    search_mongo = query_video_op_get_by_user_id(user_id)
    if len(search_mongo) == 0:
        return []

    search_result = util_serializer_mongo_results_to_array(search_mongo)

    process_result = []
    for each in search_result:
        process_result.append({
            "video_id": each["video_id"],
            "user_id": each["user_id"],
            "process": str(each["process"]),
            "process_date": str(each["process_date"])
        })

    return process_result
Exemple #2
0
def service_video_comments(**kw):

    kw['service'] = 'video'
    kw = util_pattern_format_param(**kw)

    # keyword check and formatting
    if 'video_id' not in kw:
        raise ServiceError(ErrorCode.SERVICE_MISSING_PARAM)

    if not is_valid_id(kw["video_id"]):
        raise ServiceError(ErrorCode.SERVICE_INVALID_ID_OBJ)

    # perform db operations and get result
    search_mongo = query_video_op_get_by_video_id(kw["video_id"])
    if len(search_mongo) == 0:
        return []

    search_result = util_serializer_mongo_results_to_array(search_mongo)

    comments_result = []
    for each in search_result:
        if each["comment"] != "":
            user_obj = query_user_get_by_id(each["user_id"])[0].to_dict()
            comments_result.append({
                "video_id": each["video_id"],
                "user_id": each["user_id"],
                "user_name": user_obj["user_name"],
                "user_thumbnail": user_obj["user_thumbnail"],
                "comment": each["comment"],
                "comment_date": str(each["comment_date"])
            })

    return comments_result
Exemple #3
0
def service_video_delete(**kw):

    kw['service'] = 'video'
    kw = util_pattern_format_param(**kw)

    # keyword check and formatting
    if 'video_id' not in kw:
        raise ServiceError(ErrorCode.SERVICE_MISSING_PARAM)

    if not is_valid_id(kw['video_id']):
        raise ServiceError(ErrorCode.SERVICE_INVALID_ID_OBJ)

    # delete by setting status
    if 'method' in kw and kw['method'] == 'status':
        res = query_video_update(kw['video_id'], video_status='deleted')
    # delete by removing from database
    else:
        res = query_video_delete(kw['video_id'], silent=True)

    # delete all op in this video immediately
    ops = query_video_op_get_by_video_id(kw['video_id'])
    for op in ops:
        opid = op.to_dict()['video_op_id']
        query_video_op_delete(opid, silent=True)
    return res
Exemple #4
0
def service_video_upload(user_id: str):

    if not is_valid_id(user_id):
        raise ServiceError(ErrorCode.SERVICE_INVALID_ID_OBJ)

    # perform db operations and get result
    vid = query_video_create(user_id)
    return vid
Exemple #5
0
def service_user_get_user(user_id):

    # user_id check
    if not is_valid_id(user_id):
        raise ServiceError(ErrorCode.SERVICE_INVALID_ID_OBJ)

    users = query_user_get_by_id(user_id)
    if len(users) == 0:
        raise ServiceError(ErrorCode.SERVICE_USER_NOT_FOUND)

    user_array = util_serializer_mongo_results_to_array(users)
    return user_array[0]
Exemple #6
0
def service_video_get_by_user(**kw):

    kw['service'] = 'video'
    kw = util_pattern_format_param(**kw)
    # keyword check and formatting
    if 'user_id' not in kw:
        raise ServiceError(ErrorCode.SERVICE_MISSING_PARAM)
    if not is_valid_id(kw["user_id"]):
        raise ServiceError(ErrorCode.SERVICE_INVALID_ID_OBJ)
    videos = query_video_get_by_user_id(kw['user_id'])
    if len(videos) == 0:
        return []
    video_array = util_serializer_mongo_results_to_array(videos)
    return video_array
Exemple #7
0
def service_video_info(**kw):

    kw['service'] = 'video'
    kw = util_pattern_format_param(**kw)
    # keyword check and formatting
    if 'video_id' not in kw:
        raise ServiceError(ErrorCode.SERVICE_MISSING_PARAM)

    if not is_valid_id(kw["video_id"]):
        raise ServiceError(ErrorCode.SERVICE_INVALID_ID_OBJ)
    # perform db operations and get result
    video = query_video_get_by_video_id(kw["video_id"])
    if len(video) == 0:
        raise ServiceError(ErrorCode.SERVICE_VIDEO_NOT_FOUND)

    res = video[0].to_dict()
    user_id = res["user_id"]
    user_obj = query_user_get_by_id(user_id)[0].to_dict()
    res["user_name"] = user_obj["user_name"]
    res["user_thumbnail"] = user_obj["user_thumbnail"]
    return res
Exemple #8
0
def service_video_update(**kw):

    kw['service'] = 'video'
    kw = util_pattern_format_param(**kw)

    # keyword check and formatting
    if 'video_id' not in kw:
        raise ServiceError(ErrorCode.SERVICE_MISSING_PARAM)

    if not is_valid_id(kw["video_id"]):
        raise ServiceError(ErrorCode.SERVICE_INVALID_ID_OBJ)

    if 'video_status' in kw and kw['video_status'] not in VALID_VIDEO_STATUS:
        raise ServiceError(ErrorCode.SERVICE_VIDEO_INVALID_STATUS)

    if 'video_raw_status' in kw and \
       kw['video_raw_status'] not in VALID_VIDEO_RAW_STATUS:
        raise ServiceError(ErrorCode.SERVICE_VIDEO_INVALID_STATUS)

    query_video_update(**kw)

    return query_video_get_by_video_id(kw["video_id"])