<commit_before>from flask import jsonify, request, Blueprint
from app.model.user import User
from app.model.response import ResponseBodyCreator


bp = Blueprint('user', __name__, url_prefix='/api/users')


@bp.route('/', methods=['GET'])
def index():
    body_createor = ResponseBodyCreator()
    body = body_createor.ok(User.find_by(''))
    res = jsonify(body)
    res.status_code = body['status_code']
    return res


@bp.route('/', methods=['POST'])
def add():
    body_createor = ResponseBodyCreator()

    if request.json is None:
        body = body_createor.bad_request()
        res = jsonify(body)
        res.status_code = body['status_code']
        return res

    user = User(
        None,
        request.json['name'],
        request.json['nickname'],
        request.json['email'],
        request.json['password'])
    saved = user.save()

    if saved:
        body = body_createor.created(request.json)
    elif not saved and user.errors:
        body = body_createor.bad_request(user.errors)

    res = jsonify(body)
    res.status_code = body['status_code']
    return res


@bp.route('/<int:id>', methods=['PUT'])
def edit(id):
    body_createor = ResponseBodyCreator()
    user = User(
        id,
        request.json['name'],
        request.json['nickname'],
        request.json['email'],
        request.json['password'])
    saved = user.save()

    if saved:
        body = body_createor.ok(request.json)
    elif not saved and user.errors:
        body = body_createor.conflict(user.errors)

    res = jsonify(body)
    res.status_code = body['status_code']
    return res


@bp.route('/<int:id>', methods=['DELETE'])
def delete(id):
    user = User(id)
    deleted = user.delete()
    body_createor = ResponseBodyCreator()

    if deleted:
        body = body_createor.no_content('delete successfuly')
    else:
        body = body_createor.not_found('resource not found')

    res = jsonify(body)
    res.status_code = body['status_code']<commit_msg>#36 I/F変更反映<commit_after>from flask import jsonify, request, Blueprint
from app.model.user import User
from app.model.response import ResponseBodyCreator


bp = Blueprint('user', __name__, url_prefix='/api/users')


@bp.route('/', methods=['GET'])
def index():
    body_createor = ResponseBodyCreator()
    body = body_createor.ok(User.find_by(''))
    res = jsonify(body)
    res.status_code = body['status_code']
    return res


@bp.route('/', methods=['POST'])
def add():
    body_createor = ResponseBodyCreator()

    if request.json is None:
        body = body_createor.bad_request()
        res = jsonify(body)
        res.status_code = body['status_code']
        return res

    user = User(
        None,
        request.json['name'],
        request.json['nickname'],
        request.json['email'],
        request.json['password'])
    saved = user.save()

    if saved:
        body = body_createor.created(request.json)
    elif not user.is_valid():
        body = body_createor.bad_request(user.validation_errors)

    res = jsonify(body)
    res.status_code = body['status_code']
    return res


@bp.route('/<int:id>', methods=['PUT'])
def edit(id):
    body_createor = ResponseBodyCreator()
    user = User(
        id,
        request.json['name'],
        request.json['nickname'],
        request.json['email'],
        request.json['password'])
    saved = user.save()

    if saved:
        body = body_createor.ok(request.json)
    elif not user.is_valid():
        body = body_createor.conflict(user.validation_errors)

    res = jsonify(body)
    res.status_code = body['status_code']
    return res


@bp.route('/<int:id>', methods=['DELETE'])
def delete(id):
    user = User(id)
    deleted = user.delete()
    body_createor = ResponseBodyCreator()

    if deleted:
        body = body_createor.no_content('delete successfuly')
    else:
        body = body_createor.not_found('resource not found')

    res = jsonify(body)
    res.status_code = body['status_code']
{'fraction_non_alphanumeric': 0.13819095477386933, 'fraction_numerical': 0.0005025125628140704, 'mean_word_length': 2.984984984984985, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7210827', 'n_tokens_mistral': 1270, 'n_tokens_neox': 1248, 'n_words': 260}