Beispiel #1
0
 def deleteBFood(self, bfoodid):
     dao = BabyFoodDAO()
     if not dao.getBabyFoodById(bfoodid):
         return jsonify(Error="Resource not found."), 404
     else:
         dao.delete(bfoodid)
         return jsonify(DeleteStatus="OK"), 200
Beispiel #2
0
 def getResourceIDByBabyFoodID(self, bfoodid):
     dao = BabyFoodDAO()
     row = dao.getResourceIDByBFoodID(bfoodid)
     if not row:
         return jsonify(Error="BabyFood Not Found "), 404
     else:
         bfood = self.build_babyfood_dict(row)
         return jsonify(BFood=bfood)
Beispiel #3
0
 def getBabyFoodByResourceID(self, resourceid):
     dao = BabyFoodDAO()
     row = dao.getBFoodByResourceID(resourceid)
     if not row:
         return jsonify(Error="BabyFood Not Found "), 404
     else:
         bfood = self.build_bfooddetails_dict(row)
         return jsonify(BFood=bfood)
Beispiel #4
0
 def getAllBabyFood(self):
     dao = BabyFoodDAO()
     babyfood_list = dao.getAllBabyFood()
     result_list = []
     for row in babyfood_list:
         result = self.build_babyfood_dict(row)
         result_list.append(result)
     return jsonify(babyfood=babyfood_list)
Beispiel #5
0
 def searchBabyFood(self, args):
     supplierid = args.get("supplierid")
     dao = BabyFoodDAO()
     babyfood_list = []
     if (len(args) == 1) and supplierid:
         babyfood_list = dao.getBabyFoodBySupplier(supplierid)
     else:
         return jsonify(Error="Malformed query string"), 400
     result_list = []
     for row in babyfood_list:
         result = self.build_babyfood_dict(row)
         result_list.append(result)
     return jsonify(babyfood=result_list)
Beispiel #6
0
 def insertbfoodJson(self, json):
     bfoodflavor = json['BFoodFlavor']
     bfooddescription = json['BFoodDescription']
     resourceid = json['ResourceID']
     if bfoodflavor and bfooddescription and resourceid:
         dao = BabyFoodDAO()
         bfoodid = dao.insert(
             bfoodflavor,
             bfooddescription,
             resourceid,
         )
         result = self.build_babyfood_attributes(
             bfoodid,
             bfoodflavor,
             bfooddescription,
             resourceid,
         )
         return jsonify(bfood=result), 201
     else:
         return jsonify(Error="Unexpected attributes in post request")
Beispiel #7
0
 def insertBFood(self, form):
     print("form: ", form)
     if len(form) != 4:
         return jsonify(Error="Malformed post request")
     bfoodflavor = form['BFoodFlavor']
     bfooddescription = form['BFoodDescription']
     resourceid = form['ResourceID']
     if bfoodflavor and bfooddescription and resourceid:
         dao = BabyFoodDAO()
         bfoodid = dao.insert(
             bfoodflavor,
             bfooddescription,
             resourceid,
         )
         result = self.build_babyfood_attributes(
             bfoodid,
             bfoodflavor,
             bfooddescription,
             resourceid,
         )
         return jsonify(bfood=result), 201
     else:
         return jsonify(Error="Unexpected attributes in post request")
Beispiel #8
0
 def updateResourceJson(self, bfoodid, json):
     dao = BabyFoodDAO()
     if not dao.getBabyFoodById(bfoodid):
         return jsonify(Error="Baby Food not found."), 404
     else:
         bfoodflavor = json['BFoodFlavor']
         bfooddescription = json['BFoodDescription']
         if bfoodflavor and bfooddescription:
             dao.update(bfoodid, bfoodflavor, bfooddescription)
             resourceid = dao.getResourceIDByBFoodID(bfoodid)
             result = self.build_babyfood_attributes(
                 bfoodid, bfoodflavor, bfooddescription, resourceid)
             return jsonify(bfood=result), 400
         else:
             return jsonify(
                 Error="Unexpected attributes in update request"), 400