示例#1
0
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
示例#2
0
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
示例#3
0
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
示例#4
0
def get():
    return CommModel.return_all()
示例#5
0
def delete(comm_id):
    try:
        return CommModel().delete_by_commid(comm_id)
    except:
        return {'message': 'Something went wrong'}, 500