Skip to content

Commit

Permalink
merged with main: update date field, modified max length of strings
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasbpro committed Feb 16, 2021
2 parents a1385dc + 2924dbf commit e292571
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
6 changes: 3 additions & 3 deletions constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
constants = {

# ---- INT values
'SHORT_LENGTH' : 10,
'MEDIUM_LENGTH' : 30,
'LONG__LENGTH' : 50,
'SHORT_LENGTH' : 20,
'MEDIUM_LENGTH' : 50,
'LONG_LENGTH' : 100,
'LONG_TEXT_DESCRIPTION' : 140,
'UNIT_LENGTH' : 2,
'PRICE_PRECISION' : 2,
Expand Down
9 changes: 8 additions & 1 deletion models/raw_material.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

from db import db #, materials_by_recipe # import SQLAlchemy object
from constants import constants # constants dictionary
from datetime import datetime

materials_by_recipe = db.Table('materials_by_recipe',
db.Column('recipe_id', db.Integer, db.ForeignKey('recipes.id'), primary_key=True),
Expand All @@ -15,12 +16,14 @@ class RawMaterialModel(db.Model):

# define columns in table
id = db.Column(db.Integer, primary_key=True)
description = db.Column(db.String(constants['MEDIUM_LENGTH']))
description = db.Column(db.String(constants['LONG_LENGTH']))
package_price = db.Column(db.Float(constants['PRICE_PRECISION']))
package_amt = db.Column(db.Integer)
unit_material = db.Column(db.String(constants['UNIT_LENGTH'])) # m, ml, L, g (unidades de medicao)
stock_amt = db.Column(db.Integer)
sell_by_date = db.Column(db.String(constants['SHORT_LENGTH']))
creation_date = db.Column(db.String(constants['MEDIUM_LENGTH']))
last_update = db.Column(db.String(constants['MEDIUM_LENGTH']))

# define relationships with other tables
recipes = db.relationship('RecipeModel',
Expand All @@ -36,10 +39,14 @@ def __init__(self, description, package_price, package_amt,
self.unit_material = unit_material
self.stock_amt = stock_amt
self.sell_by_date = sell_by_date
self.creation_date = datetime.now().strftime("%d/%m/%Y %H:%M")
self.last_update = self.creation_date

def json(self):
return {'id' : self.id,
'description' : self.description,
'creation_date': self.creation_date,
'last_update' : self.last_update,
'package_price': self.package_price,
'package_amt' : self.package_amt,
'unit_material': self.unit_material,
Expand Down
2 changes: 1 addition & 1 deletion models/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class RecipeModel(db.Model):

# define columns in table
id = db.Column(db.Integer, primary_key=True)
description = db.Column(db.String(constants['MEDIUM_LENGTH']))
description = db.Column(db.String(constants['LONG_LENGTH']))
labor_cost = db.Column(db.Float(constants['PRICE_PRECISION']))
supply_cost = db.Column(db.Float(constants['PRICE_PRECISION']))
creation_date = db.Column(db.String(constants['MEDIUM_LENGTH']))
Expand Down
2 changes: 1 addition & 1 deletion resources/orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Order(Resource):
# adds a parser to handle PUT an POST HTTP requests
parser = reqparse.RequestParser()
parser.add_argument('status_fabrication',type=str,required=False)
parser.add_argument('status_payment',type=float,required=False)
parser.add_argument('status_payment',type=str,required=False)

# to handle HTTP GET /orders/<int:id>
def get(self, id):
Expand Down
5 changes: 4 additions & 1 deletion resources/raw_material.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# import flask libs
from flask_restful import Resource, reqparse
from constants import constants
from datetime import datetime
#from flask_jwt import jwt_required

# import model
Expand Down Expand Up @@ -59,6 +60,8 @@ def put(self, id):
if key=='sell_by_date':
raw_material.sell_by_date = data['sell_by_date']

raw_material.last_update = datetime.now().strftime("%d/%m/%Y %H:%M")

# in case it does not exist, creates a new material using data passed
# along with the HTTP request
else:
Expand Down Expand Up @@ -100,7 +103,7 @@ def post(self):

# in case it exists, returns a message and HTTP 400 code (BAD REQUEST)
if raw_material:
return {'message': "A raw material with descripton '{}' already exists.".format(description)}, 400
return {'message': "A raw material with descripton '{}' already exists.".format(data['description'])}, 400

# in case it does not exist, creates a new material using data passed
# along with the HTTP request
Expand Down

0 comments on commit e292571

Please sign in to comment.