Example #1
0
def create_category():
    """ Create new category. """
    if request.is_json:
        data = request.get_json()
        categ = Category(data["name"])
        saved_category = categ.create()
        response = {"category": saved_category.to_dict()}
        return make_response(jsonify(response), 201)
    abort(404)
Example #2
0
def seed():
    """ Populate tables with data. """
    category = Category("Category 1").create()
    print(f"Create: {category}")

    question1 = Question("Question 1", 1, "Hard", False).create()
    print(f"Create: {question1}")
    question2 = Question("Question 2", 1, "Easy", True).create()
    print(f"Create: {question2}")
    question3 = Question("Question 3", 1, "Medium", True).create()
    print(f"Create: {question3}")

    answer1 = Answer("Answer 1", 1, False).create()
    print(f"Create: {answer1}")
    answer2 = Answer("Answer 2", 1, True).create()
    print(f"Create: {answer2}")
    answer3 = Answer("Answer 3", 1, False).create()
    print(f"Create: {answer3}")
    answer4 = Answer("Answer 4", 2, True).create()
    print(f"Create: {answer4}")
    answer5 = Answer("Answer 5", 2, False).create()
    print(f"Create: {answer5}")
    answer6 = Answer("Answer 6", 2, False).create()
    print(f"Create: {answer6}")
    answer7 = Answer("Answer 7", 3, False).create()
    print(f"Create: {answer7}")
    answer8 = Answer("Answer 8", 3, True).create()
    print(f"Create: {answer8}")
    answer9 = Answer("Answer 9", 3, False).create()
    print(f"Create: {answer9}")
Example #3
0
 def questions_data(self):
     """ Setup question data. """
     category = Category("Test Category").create()
     question1 = Question("Test Question 1", category.id, "Hard",
                          False).create()
     question2 = Question("Test Question 2", category.id, "Hard",
                          False).create()
Example #4
0
    def patch_single_preprocessor(instance_id=None, data=None, **kw):

        dish = Dish.query.get(instance_id)

        if dish is None or dish.cook_id is not current_user.id:
            raise ProcessingException(description='Dish does not exist',
                                      code=400)

        if 'allergies' in data:
            data['allergies'] = Allergy.get_allergies_by_list(
                data['allergies'])

        if 'categories' in data:
            data['categories'] = Category.get_categories_by_list(
                data['categories'])

        return instance_id
Example #5
0
File: dish.py Project: Ma-ve/voerr
    def patch_single_preprocessor(instance_id=None, data=None, **kw):

        dish = Dish.query.get(instance_id)

        if dish is None or dish.cook_id is not current_user.id:
            raise ProcessingException(
                description='Dish does not exist',
                code=400
            )

        if 'allergies' in data:
            data['allergies'] = Allergy.get_allergies_by_list(data['allergies'])

        if 'categories' in data:
            data['categories'] = Category.get_categories_by_list(data['categories'])

        return instance_id
Example #6
0
File: dish.py Project: Ma-ve/voerr
    def post_single_preprocessor(data=None, **kw):
        data['cook_id'] = current_user.id
        from app.api.models.user import User
        getUser = User.query.get(current_user.id)

        if not getUser.is_cook():
            raise ProcessingException(
                description='User (%r) must be a cook' % getUser.email,
                code=400
            )

        if 'allergies' in data:
            data['allergies'] = Allergy.get_allergies_by_list(data['allergies'])
        else:
            data['allergies'] = []

        if 'categories' in data:
            data['categories'] = Category.get_categories_by_list(data['categories'])
        else:
            data['categories'] = []

        return data
Example #7
0
    def post_single_preprocessor(data=None, **kw):
        data['cook_id'] = current_user.id
        from app.api.models.user import User
        getUser = User.query.get(current_user.id)

        if not getUser.is_cook():
            raise ProcessingException(description='User (%r) must be a cook' %
                                      getUser.email,
                                      code=400)

        if 'allergies' in data:
            data['allergies'] = Allergy.get_allergies_by_list(
                data['allergies'])
        else:
            data['allergies'] = []

        if 'categories' in data:
            data['categories'] = Category.get_categories_by_list(
                data['categories'])
        else:
            data['categories'] = []

        return data
Example #8
0
 def create_new_category(self, name):
     """ Helo method to create new category. """
     category = Category(name)
     category.create()
     return category
Example #9
0
api_manager.create_api(
    Allergy,
    url_prefix="/api/v1",
    collection_name="allergies",
    methods=["GET"],
    exclude_columns=Allergy.getExclude(),
    validation_exceptions=[Error, ProcessingException],
)

api_manager.create_api(
    Category,
    url_prefix="/api/v1",
    collection_name="categories",
    methods=["GET"],
    exclude_columns=Category.getExclude(),
    validation_exceptions=[Error, ProcessingException],
)

api_manager.create_api(
    Cook,
    url_prefix="/api/v1",
    collection_name="cooks",
    methods=["GET"],
    exclude_columns=Cook.getExclude(),
    validation_exceptions=[Error, ProcessingException],
)

api_manager.create_api(
    Dish,
    url_prefix="/api/v1",
Example #10
0
 def answer_data(self):
     """ Setup answer data. """
     category = Category("Test Category").create()
     question = Question("Test Question", category.id, "Easy", False).create()
     answer1 = Answer("Test Answer 1", question.id, False).create()
     answer2 = Answer("Test Answer 2", question.id, True).create()
Example #11
0
from app.api.models.review import Review
from app.api.models.transaction_log import TransactionLog
from app.api.models.user import User

api_manager.create_api(Allergy,
                       url_prefix='/api/v1',
                       collection_name='allergies',
                       methods=['GET'],
                       exclude_columns=Allergy.getExclude(),
                       validation_exceptions=[Error, ProcessingException])

api_manager.create_api(Category,
                       url_prefix='/api/v1',
                       collection_name='categories',
                       methods=['GET'],
                       exclude_columns=Category.getExclude(),
                       validation_exceptions=[Error, ProcessingException])

api_manager.create_api(Cook,
                       url_prefix='/api/v1',
                       collection_name='cooks',
                       methods=['GET'],
                       exclude_columns=Cook.getExclude(),
                       validation_exceptions=[Error, ProcessingException])

api_manager.create_api(Dish,
                       url_prefix='/api/v1',
                       collection_name='dishes',
                       methods=['GET', 'POST', 'PATCH', 'PUT', 'DELETE'],
                       exclude_columns=Dish.getExclude(),
                       validation_exceptions=[Error, ProcessingException],