def add_equipment():
    json_data = flask.request.json

    # name
    name = json_data.get('name')
    if not name:
        return flask.jsonify({'msg': 'Must provide non-empty name'}), 400

    equipment = Equipment(name=name)
    if not equipment.save():
        return flask.jsonify({'msg': 'Error in saving data'}), 400
    return flask.jsonify({'msg': 'Success'}), 200
def edit_equipment(equipmentId: str):
    json_data = flask.request.json
    equipment = Equipment.get_by_id(equipmentId)

    # name
    name = json_data.get('name')
    if name:
        equipment.name = name

    if not equipment.save():
        return flask.jsonify({'msg': 'Error in saving data'}), 400
    return flask.jsonify({'msg': 'Success'}), 200
示例#3
0
 def equipment(self):
     from models.model_equipment import Equipment
     from models.relation_step_equipment import StepEquipmentRelation
     return Equipment.select().join(
         StepEquipmentRelation,
         pw.JOIN.LEFT_OUTER).where(StepEquipmentRelation.step == self)
示例#4
0
 def equipment(self):
     from models.model_equipment import Equipment
     from models.relation_recipe_equipment import RecipeEquipmentRelation
     return Equipment.select().join(
         RecipeEquipmentRelation,
         pw.JOIN.LEFT_OUTER).where(RecipeEquipmentRelation.recipe == self)
def delete_equipment(equipmentId: str):
    equipment = Equipment.get_by_id(equipmentId)
    if not equipment.delete_instance():
        return flask.jsonify({'msg': 'Error in deleting data'}), 400
    return flask.jsonify({'msg': 'Success'}), 200
def get_equipment(equipmentId: str):
    equipment = Equipment.get_by_id(equipmentId)
    return flask.jsonify({'msg': 'Success', 'data': equipment.as_dict()}), 200
def get_equipments():
    query = Equipment.select()

    equipments = [c for c in query]
    equipment_dicts = [c.as_dict() for c in equipments]
    return flask.jsonify({'msg': 'Success', 'data': equipment_dicts}), 200
 def wrapper(equipmentId, *args, **kwargs):
     equipment = Equipment.get_or_none(Equipment.id == equipmentId)
     if equipment:
         return func(equipmentId, *args, **kwargs)
     else:
         return flask.jsonify({'msg': 'Equipment does not exists'}), 400