Skip to content

Commit

Permalink
feat: created field productivity for Recipe, included default values
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasbpro committed May 8, 2021
1 parent a6881cb commit 3e74110
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
4 changes: 2 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
# creates Flask application
app = Flask(__name__)

# sets up production environment
# sets up LOCAL environment
app.config['DEBUG'] = True
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get('DATABASE_URL', 'sqlite:///data.db').replace("://", "ql://", 1)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///data.db' # local db file
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.secret_key = 'rebequinha'

Expand Down
Binary file modified data.db
Binary file not shown.
7 changes: 4 additions & 3 deletions models/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ class RecipeModel(db.Model):

def __init__(self, description, labor_cost, supply_cost, productivity):
self.description = description
self.labor_cost = labor_cost
self.supply_cost = supply_cost
self.labor_cost = labor_cost or 5
self.supply_cost = supply_cost or 0
self.productivity = productivity or 1
self.creation_date = datetime.now().strftime("%d/%m/%Y %H:%M")
self.last_update = self.creation_date
self.productivity = productivity


def json(self):
materialList = {}
Expand Down
8 changes: 6 additions & 2 deletions resources/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Recipe(Resource):
parser.add_argument('description',type=str,required=False)
parser.add_argument('labor_cost',type=float,required=False)
parser.add_argument('supply_cost',type=float,required=False)
parser.add_argument('productivity',type=int,required=False)
parser.add_argument('materials', type=dict, action="append",required=False)

# to handle HTTP GET /recipes/<int:id>
Expand Down Expand Up @@ -55,6 +56,8 @@ def put(self, id):
recipe.labor_cost = data['labor_cost']
if key=='supply_cost':
recipe.supply_cost = data['supply_cost']
if key=='productivity':
recipe.productivity = data['productivity']
if key=='sell_by_date':
recipe.sell_by_date = data['sell_by_date']
if key=='materials':
Expand Down Expand Up @@ -83,7 +86,7 @@ def put(self, id):

# in case not exist, creates a new item
else:
recipe = RecipeModel(data['description'],data['labor_cost'],data['supply_cost'])
recipe = RecipeModel(data['description'],data['labor_cost'],data['supply_cost'], data['productivity'])
materialsDict = data['materials'][0]
for key in materialsDict.keys():
materialId = int(key)
Expand Down Expand Up @@ -118,6 +121,7 @@ class Recipes(Resource):
parser.add_argument('description',type=str,required=True)
parser.add_argument('labor_cost',type=float,required=False)
parser.add_argument('supply_cost',type=float,required=False)
parser.add_argument('productivity',type=int,required=False)
parser.add_argument('materials',type=dict,action="append",required=True)

# handles HTTP request GET /recipes
Expand All @@ -138,7 +142,7 @@ def post(self):

# in case it does not exist, creates a new recipe using data passed
# along with the HTTP request
recipe = RecipeModel(data['description'],data['labor_cost'],data['supply_cost'])
recipe = RecipeModel(data['description'],data['labor_cost'],data['supply_cost'], data['productivity'])
materialsDict = data['materials'][0]
for key in materialsDict.keys():
materialId = int(key)
Expand Down

0 comments on commit 3e74110

Please sign in to comment.