Example #1
0
def points(uuid):
    # API Token exist?
    if 'X_API_Token' not in request.headers:
        return make_response(jsonify({'message': 'API token not found'}), 400)
    # API Token Correct?
    if not check_api_token(request.headers['X_API_Token']):
        return make_response(jsonify({'message': 'API token is not correct'}),
                             400)

    # check Content-Type header
    if 'application/json' not in request.headers['Content-Type'].split(';'):
        return make_response(jsonify({'message': 'error'}), 400)

    # check request json contains item 'point'?
    if 'point' not in request.json:
        return make_response(jsonify({'message': 'Require point'}), 400)

    user_records = get_user_by_uuid(uuid)
    if len(user_records) == 0:
        return make_response(
            jsonify({'message': 'No user found on specified uuid'}), 400)

    add_point(uuid, request.json['point'])
    create_point_history(user_records[0]['id'], request.json['point'])

    res = get_user_by_uuid(uuid)

    return make_response(jsonify(res[0]), 200)
Example #2
0
def create_post():
    # API Token exist?
    if 'X_API_Token' not in request.headers:
        return make_response(jsonify({'message': 'API token not found'}), 400)
    # API Token Correct?
    if not check_api_token(request.headers['X_API_Token']):
        return make_response(jsonify({'message': 'API token is not correct'}),
                             400)
    # When multipule Content-Type Specified, 'application/json' != request.headers['Content-Type'] is True.
    # So, split request.headers['Content-Type'] to list by ';'.
    if 'application/json' not in request.headers['Content-Type'].split(';'):
        return make_response(jsonify({'message': 'error'}), 400)

    json = request.json
    if not ('b64image' in json and 'place_uid' in json and 'uuid' in json):
        return make_response(
            jsonify({'message': 'Require b64, place_uid, uuid.'}), 400)

    # get user_id from uuid
    user_records = get_user_by_uuid(json['uuid'])
    if len(user_records) == 0:
        return make_response(jsonify({'message': 'uuid not found.'}), 400)

    user_id = user_records[0]['id']

    # upload
    ret = uploadPost(json['b64image'], user_id)

    # create record
    create(ret['cloud_storage_filename'], user_id, json['place_uid'])

    return make_response(jsonify({'message': 'Successfuly Uploaded.'}))
Example #3
0
def set_icon(uuid, icon_id):
    # API Token exist?
    if 'X_API_Token' not in request.headers:
        return make_response(jsonify({'message': 'API token not found'}), 400)
    # API Token Correct?
    if not check_api_token(request.headers['X_API_Token']):
        return make_response(jsonify({'message': 'API token is not correct'}),
                             400)

    user_records = get_user_by_uuid(uuid)
    if len(user_records) == 0:
        return make_response(
            jsonify({'message': 'No user found on specified uuid'}), 400)

    content, code = change_icon(user_records[0]['id'], icon_id)

    if code == 400:
        return make_response(jsonify(content), code)

    return make_response(jsonify(get_user_by_uuid(uuid)[0]), 200)
Example #4
0
def get_user(uuid):
    # API Token exist?
    if 'X_API_Token' not in request.headers:
        return make_response(jsonify({'message': 'API token not found'}), 400)
    # API Token Correct?
    if not check_api_token(request.headers['X_API_Token']):
        return make_response(jsonify({'message': 'API token is not correct'}),
                             400)

    res = get_user_by_uuid(uuid)

    if len(res) > 0:
        return make_response(jsonify(res[0]), 200)
    else:
        return '', 204
Example #5
0
def goods(uuid):
    # API Token exist?
    if 'X_API_Token' not in request.headers:
        return make_response(jsonify({'message': 'API token not found'}), 400)
    # API Token Correct?
    if not check_api_token(request.headers['X_API_Token']):
        return make_response(jsonify({'message': 'API token is not correct'}),
                             400)

    user_records = get_user_by_uuid(uuid)
    if len(user_records) == 0:
        return make_response(
            jsonify({'message': 'No user found on specified uuid'}), 400)

    ret = get_goods(user_records[0]['id'])
    return make_response(jsonify(ret), 200)
Example #6
0
def visit_place(uuid, place_uid):
    # API Token exist?
    if 'X_API_Token' not in request.headers:
        return make_response(jsonify({'message': 'API token not found'}), 400)
    # API Token Correct?
    if not check_api_token(request.headers['X_API_Token']):
        return make_response(jsonify({'message': 'API token is not correct'}),
                             400)

    user_records = get_user_by_uuid(uuid)
    if len(user_records) == 0:
        return make_response(
            jsonify({'message': 'No user found on specified uuid'}), 400)

    visit(user_records[0]['id'], place_uid)

    return make_response(
        jsonify({'message': '{} visited at {}'.format(uuid, place_uid)}), 200)