def post(): data = request.get_json() ###comm = CommModel.find_by_commodityname(data['commodityName']) ###if comm is not None: ###return {'message': 'Commodity {} already exists'.format(data['commodityName'])} new_comm = CommModel(commodityName=data['commodityName'], description=data['description'], uom=data['uom'], createdBy=data['createdBy']) try: new_comm.save() comm = CommModel.find_by_commodityname(data['commodityName']) new_comm_upd = CommModel(commodityId=comm['commodityId'], commodityName=comm['commodityName'], description=comm['description'], uom=comm['uom'], modifiedBy=comm['modifiedBy']) new_comm_upd.update_to_db() return { 'message': 'Commodity {} was created'.format(data), } except Exception as e: print(e) return {'message': 'Something went wrong' + e.__str__()}, 500
def put(): data = request.get_json() new_comm = CommModel(commodityId=data['commodityId'], commodityName=data['commodityName'], description=data['description'], uom=data['uom'], modifiedBy=data['modifiedBy']) try: new_comm.update_to_db() return { 'message': 'Commodity {} was updated'.format(data), } except Exception as e: print(e) return {'message': 'Something went wrong' + e.__str__()}, 500
def get(comm_id): try: print(comm_id, file=sys.stdout) commodity = CommModel().find_by_commid(comm_id) return commodity except Exception as e: print(e) return {'message': 'Something went wrong' + e.__str__()}, 500
def get(): return CommModel.return_all()
def delete(comm_id): try: return CommModel().delete_by_commid(comm_id) except: return {'message': 'Something went wrong'}, 500