예제 #1
0
    def patch_user(client_request, username):
        token = get_request_token(client_request)
        if token is None:
            return get_response(status=HTTPStatus.UNAUTHORIZED)

        json_fields = [("username", str), ("password", str), ("mail", str)]
        user_data = extract_request_form_data_dict(client_request)
        if user_data is None:
            return get_response(status=HTTPStatus.UNSUPPORTED_MEDIA_TYPE)

        user_json = object_to_dict(user_data, json_fields)
        patch_json, patch_avatar = check_json_dict(user_json, json_fields,
                                                   False), None

        if client_request.files.get('avatar', None) is not None:
            patch_avatar, response = check_form_data_image(
                client_request, 'avatar')
            if response is not None:
                return get_response(status=response)

        if patch_json is False and patch_avatar is None:
            return get_response(status=HTTPStatus.BAD_REQUEST)
        return UsersService.patch_user(token, username,
                                       user_json if patch_json else None,
                                       patch_avatar)
예제 #2
0
    def patch_user_post(client_request, username, post_id):
        post_id = get_valid_number(post_id)
        if post_id is None:
            return get_response(status=HTTPStatus.NOT_FOUND)

        token = get_request_token(client_request)
        if token is None:
            return get_response(status=HTTPStatus.UNAUTHORIZED)

        json_fields = [("title", str), ("description", str)]
        user_post_data = extract_request_form_data_dict(client_request)
        if user_post_data is None:
            return get_response(status=HTTPStatus.UNSUPPORTED_MEDIA_TYPE)

        user_post_json = object_to_dict(user_post_data, json_fields)
        patch_json, patch_image = check_json_dict(user_post_json, json_fields,
                                                  False), None

        if client_request.files.get('image', None) is not None:
            patch_image, response = check_form_data_image(
                client_request, 'image')
            if response is not None:
                return get_response(status=response)

        if patch_json is False and patch_image is None:
            return get_response(status=HTTPStatus.BAD_REQUEST)
        return UsersService.patch_user_post(token, username, post_id,
                                            user_post_json, patch_image)
예제 #3
0
    def analyze_post(client_request, username, post_id):
        token = get_request_token(client_request)
        if token is None:
            return get_response(status=HTTPStatus.UNAUTHORIZED)

        post_id = get_valid_number(post_id)
        if post_id is None:
            return get_response(status=HTTPStatus.NOT_FOUND)

        return UsersService.analyze_post(token, username, post_id)
예제 #4
0
    def translate_post(client_request, username, post_id):
        language = client_request.args.get("lang", None)
        post_id = get_valid_number(post_id)

        if post_id is None:
            return get_response(status=HTTPStatus.NOT_FOUND)

        if check_language_format(language) is False:
            return get_response(status=HTTPStatus.BAD_REQUEST)

        token = get_request_token(client_request)
        if token is None:
            return get_response(status=HTTPStatus.UNAUTHORIZED)

        return UsersService.translate_post(token, username, post_id, language)
예제 #5
0
    def add_user_post(client_request, username):
        token = get_request_token(client_request)
        if token is None:
            return get_response(status=HTTPStatus.UNAUTHORIZED)

        json_fields = [("title", str), ("description", str)]
        data = extract_request_form_data_dict(client_request)
        if data is None:
            return get_response(status=HTTPStatus.UNSUPPORTED_MEDIA_TYPE)

        post = {
            "title": data.get("title", None),
            "description": data.get("description", None)
        }
        if check_json_dict(post, json_fields) is False:
            return get_response(status=HTTPStatus.BAD_REQUEST)

        image, response = check_form_data_image(client_request, 'image')
        if response is not None:
            return get_response(status=response)
        return UsersService.add_user_post(token, username, post, image)
예제 #6
0
    def locate_post(client_request, username, post_id):
        token = get_request_token(client_request)
        if token is None:
            return get_response(status=HTTPStatus.UNAUTHORIZED)

        post_id = get_valid_number(post_id)
        if post_id is None:
            return get_response(status=HTTPStatus.NOT_FOUND)

        zoom = get_valid_number(client_request.args.get("zoom", None))
        width = get_valid_number(client_request.args.get("width", None))
        height = get_valid_number(client_request.args.get("height", None))

        if zoom is None or width is None or height is None:
            return get_response(status=HTTPStatus.BAD_REQUEST)

        return UsersService.locate_post(token, username, post_id, {
            "zoom": zoom,
            "width": width,
            "height": height
        })
예제 #7
0
    def delete_user(client_request, username):
        token = get_request_token(client_request)
        if token is None:
            return get_response(status=HTTPStatus.UNAUTHORIZED)

        return UsersService.delete_user(token, username)