from flask import abort

import factory as factory
import validator as validator
import ingredient.model as ingredient

server = factory.Server()
validator = validator.Validator()
ingredient = ingredient.Ingredient()


class Validator(object):

    def is_body_valid(self, data):
        self.is_name_valid(data)

    @staticmethod
    def is_name_valid(data):
        validator.is_mandatory("name", data)
        validator.is_string("name", data["name"])
        validator.is_string_non_empty("name", data["name"])
        return True

    @staticmethod
    def is_name_already_exist(data):
        """ check name already exist """
        name = data["name"]
        result_mongo = ingredient.select_one_by_name(name=name)
        if result_mongo.count() == 0:
            return False
        else:
import ingredient.model as ingredient_model

list_param_ingredient = ingredient_model.Ingredient().list_param


class Factory(object):
    @staticmethod
    def clean_body(data):
        clean_body = {}
        for i, j in data.items():
            if i in list_param_ingredient:
                clean_body[i] = j
        return clean_body
Exemple #3
0
from flask import Blueprint, request

import factory as factory
import ingredient.model as ingredient_model
import ingredient.validator.GetIngredient as validator_GetIngredient
import ingredient.validator.PostIngredient as validator_PostIngredient
import ingredient.validator.PutIngredient as validator_PutIngredient
import ingredient.validator.DeleteIngredient as validator_DeleteIngredient
import ingredient.factory.PostIngredient as factory_PostIngredient
import ingredient.factory.PutIngredient as factory_PutIngredient

ingredient_api = Blueprint('ingredient_api', __name__)

ingredient = ingredient_model.Ingredient()
get_ingredient_validator = validator_GetIngredient.Validator()
post_ingredient_validator = validator_PostIngredient.Validator()
put_ingredient_validator = validator_PutIngredient.Validator()
delete_ingredient_validator = validator_DeleteIngredient.Validator()
post_ingredient_factory = factory_PostIngredient.Factory()
put_ingredient_factory = factory_PutIngredient.Factory()
""" 
ingredient route 

- GET /ingredient
- GET /ingredient/<_id>
- POST /ingredient
- PUT /ingredient
- DELETE /ingredient/<_id>

"""