Пример #1
0
def get_skill_by_id(skill_id):
    response = User.check_token(request)
    if response == 200:
        return jsonify(
            Skill.query.filter_by(
                id_skill=skill_id).first_or_404().to_dict('id'))
    return error_response(response)
Пример #2
0
def get_category_by_name(category_name):
    response = User.check_token(request)
    if response == 200:
        return jsonify(
            Category.query.filter_by(
                category_name=category_name).first_or_404().to_dict('name'))
    return error_response(response)
Пример #3
0
def get_skill_by_name(skill_name):
    response = User.check_token(request)
    if response == 200:
        return jsonify(
            Skill.query.filter_by(
                skill_name=skill_name).first_or_404().to_dict('name'))
    return error_response(response)
Пример #4
0
def get_category_by_id(category_id):
    response = User.check_token(request)
    if response == 200:
        return jsonify(
            Category.query.filter_by(
                id_skill_cat=category_id).first_or_404().to_dict('id'))
    return error_response(response)
Пример #5
0
def delete_category_by_name(category_name):
    response = User.check_token(request)
    if response == 200 \
            and User.query.filter_by(token=request.headers.get('Authorization')).first().email == Config.ADMIN_EMAIL:
        if Category.delete_category(category_name):
            response = jsonify(Config.API_DELETION_SUCCESS)
            response.status_code = 200
            return response
        else:
            return bad_request(ErrorMessages.API_DELETE_CATEGORY_FAILURE)
    return error_response(response if response != 200 else 401)
Пример #6
0
def delete_skill_by_id(skill_id):
    response = User.check_token(request)
    if response == 200 \
            and User.query.filter_by(token=request.headers.get('Authorization')).first().email == Config.ADMIN_EMAIL:
        skill_to_be_deleted = Skill.query.filter_by(id_skill=skill_id).first()
        if skill_to_be_deleted is None:
            return bad_request(ErrorMessages.API_DELETE_SKILL_FAILURE)
        if Skill.delete_skill(skill_to_be_deleted.skill_name):
            response = jsonify(Config.API_DELETION_SUCCESS)
            response.status_code = 200
            return response
        else:
            return bad_request(ErrorMessages.API_DELETE_SKILL_FAILURE)
    return error_response(response if response != 200 else 401)
Пример #7
0
def create_category():
    response = User.check_token(request)
    if response == 200 \
            and User.query.filter_by(token=request.headers.get('Authorization')).first().email == Config.ADMIN_EMAIL:
        data = request.get_json() or {}
        if not validate_category_json(data):
            return bad_request(ErrorMessages.API_FORMAT_NOT_ALLOWED)
        if not validate_new_category_name(data['category_name']):
            return bad_request(ErrorMessages.API_CATEGORY_NAME_ERROR)
        if Category.insert_new_category(data['category_name'],
                                        data.get('is_shown', 1)):
            response = jsonify(
                Category.query.filter_by(category_name=data['category_name']).
                first().to_dict('name'))
            response.status_code = 201
            response.headers['Location'] = url_for(
                'api.get_category_by_name',
                category_name=data['category_name'])
            return response
        else:
            return bad_request(ErrorMessages.API_CATEGORY_INSERT_ERROR)
    return error_response(response if response != 200 else 401)
Пример #8
0
def get_categories():
    response = User.check_token(request)
    if response == 200:
        return jsonify(to_collection_dict(Category))
    return error_response(response)
Пример #9
0
def get_skills():
    response = User.check_token(request)
    if response == 200:
        return jsonify(to_collection_dict(Skill))
    return error_response(response)
Пример #10
0
def internal_error(error):
    db.session.rollback()
    if wants_json_response():
        return error_response(500)
    return render_template('errors/500.html'), 500
Пример #11
0
def page_not_found(e):
    if wants_json_response():
        return error_response(404)
    return render_template('errors/404.html'), 404