예제 #1
0
 def deleteIce(self, iceid):
     dao = IceDAO()
     if not dao.getIceById(iceid):
         return jsonify("Error ice not found")
     else:
         dao.delete(iceid)
         return jsonify(DeleteStatus="OK")
예제 #2
0
 def getAllIce(self):
     dao = IceDAO()
     ice_list = dao.getAllIce()
     result_list = []
     for row in ice_list:
         result = self.build_ice_dict(row)
         result_list.append(result)
     return jsonify(Ice=result_list)
예제 #3
0
 def getIceByLocation(self, location):
     dao = IceDAO()
     ice_list = dao.getIceByLocation(location)
     result_list = []
     for row in ice_list:
         result = self.build_Ice_dict(row)
         result_list.append(result)
     return jsonify(Ice=result_list)
예제 #4
0
 def getAllResourceByKeyword(self, keyword):
     dao = IceDAO()
     Resources_list = dao.getResourceByKeyWord(keyword)
     result_list = []
     for row in Resources_list:
         result = self.build_Ice_dict(row)
         result_list.append(result)
     return jsonify(Resources=result_list)
예제 #5
0
 def getIceById(self, id):
     dao = IceDAO()
     ice_list = dao.getIceById(id)
     result_list = []
     for row in ice_list:
         result = self.build_Ice_dict(row)
         result_list.append(result)
     return jsonify(Ice=result_list)
예제 #6
0
 def getIceByResourceID(self, resourceid):
     dao = IceDAO()
     row = dao.getIceByResourceID(resourceid)
     if not row:
         return jsonify(Error="Ice Not Found "), 404
     else:
         Ice = self.build_icedetails_dict(row)
         return jsonify(Ice=Ice)
예제 #7
0
 def getResourceIDByIceID(self, Iceid):
     dao = IceDAO()
     row = dao.getResourceIDByIceID(Iceid)
     if not row:
         return jsonify(Error="Ice Not Found "), 404
     else:
         Ice = self.build_ice_dict(row)
         return jsonify(Ice=Ice)
예제 #8
0
 def getIceByID(self, iceid):
     dao = IceDAO()
     row = dao.getIceById(iceid)
     if not row:
         return jsonify(Error="Ice not found"), 404
     else:
         ice = self.build_ice_dict(row)
         return ice
예제 #9
0
 def update(self, iceid, form):
     dao = IceDAO()
     if not dao.getIceById(iceid):
         return jsonify(Error="Ice not found"), 404
     else:
         icesize = form['icesize']
         icedescription = form['icedescription']
         if icesize and icedescription:
             dao.update(iceid, icesize, icedescription)
예제 #10
0
 def deleteIce(self, ice_id):
     ice_dao = IceDAO()
     res_dao = ResourceDAO()
     if not ice_dao.getIceById(ice_id):
         return jsonify(Error = "Ice not found."), 404
     else:
         resource_id = ice_dao.delete(ice_id)
         res_dao.delete(resource_id)
         return jsonify(DeleteStatus = "OK"), 200
예제 #11
0
 def insertIceJson(self, json):
     icesize = json['IceSize']
     icedescription = json['IceDescription']
     resourceid = json['ResourceID']
     if resourceid and icesize and icedescription:
         dao = IceDAO()
         iceid = dao.insert(icesize, icedescription, resourceid)
         result = self.build_ice_attributes(iceid, icesize, icedescription,
                                            resourceid)
         return jsonify(Ice=result), 201
     else:
         return jsonify(Error="Unexpected attributes in post request")
예제 #12
0
 def getIceBySupplierId(self, supplier_id):
     supplier_dao = SupplierDAO()
     if not supplier_dao.getSupplierById(supplier_id):
         return jsonify(Error = "Supplier Not Found"), 404
     else:
         ice_dao = IceDAO()
         result_list = []
         ice_list = ice_dao.getIceBySupplierId(supplier_id)
         for row in ice_list:
             result = self.build_ice_dict(row)
             result_list.append(result)
         return jsonify(Ice = result_list)
예제 #13
0
 def searchIce(self, args):
     brand =  args.get('ice_brand')
     weight = args.get('ice_weight')
     dao = IceDAO()
     ice_list = []
     if (len(args) == 1) and brand:
         ice_list = dao.getIceByBrand(brand)
     elif (len(args) == 1) and weight:
         ice_list = dao.getIceByWeight(weight)
     else:
         return jsonify(Error = "Malformed query string"), 400
     result_list = []
     for row in ice_list:
         result = self.build_ice_dict(row)
         result_list.append(result)
     return jsonify(Ice = result_list)
예제 #14
0
 def getIceAddress(self,ice_id):
     ice_dao = IceDAO()
     try:
         supplier_id = ice_dao.getIceById(ice_id)[3]
     except Exception:
         return jsonify(Error = "Ice not found."), 404
     supplier_dao = SupplierDAO()
     if not supplier_dao.getSupplierById(supplier_id):
         return jsonify(Error = "Supplier not found."), 404
     else:
         row = ice_dao.getIceAddress(supplier_id)
         if not row:
             return jsonify(Error = "Address not found."), 404
         else:
             address = self.build_address_dic(row)
             return jsonify(Address = address)
예제 #15
0
 def insert(self, item, supplier_id):
     size = item['ice_size']
     rname = item['resource_name']
     rprice = item['resource_price']
     resource_location = item['resource_location']
     resource_quantity = item['resource_quantity']
     resource_date = item['resource_date']
     resource_description = item['resource_description']
     if size and rname and rprice and resource_location and resource_quantity and resource_date and resource_description:
         dao = IceDAO()
         rid = dao.insert(size, rname, rprice, resource_location,
                          resource_quantity, resource_description,
                          resource_date, supplier_id)
         return jsonify(Ice=self.build_ice_attributes(size)), 201
     else:
         return jsonify(Error="Unexpected attributes in post request"), 400
예제 #16
0
 def insertIce(self, form):
     if (len(form) != 3):
         return jsonify(Error="Malformed post request"), 404
     else:
         resourceid = form['resourceid']
         icesize = form['icesize']
         icedescription = form['icedescription']
         if resourceid and icesize and icedescription:
             dao = IceDAO()
             iceid = dao.insert(resourceid, icesize, icedescription)
             result = self.build_ice_attributes(iceid, resourceid, icesize,
                                                icedescription)
             return jsonify(Ice=result)
         else:
             return jsonify(
                 Error="Unexpected attributes in post request"), 404
예제 #17
0
 def getDAO(self, type):
     if (type == 'babyfood'):
         return babyFoodDAO()
     elif (type == 'dryfood'):
         return dryFoodDAO()
     elif (type == 'cannedfood'):
         return cannedFoodDAO()
     elif (type == 'medication'):
         return MedicationDAO()
     elif (type == 'batteries'):
         return BatteryDAO()
     elif (type == 'clothing'):
         return ClothingDAO()
     elif (type == 'heavyequipment'):
         return HeavyEquipmentDAO()
     elif (type == 'ice'):
         return IceDAO()
     elif (type == 'powertools'):
         return PowerToolsDAO()
     elif (type == 'fuel'):
         return FuelDAO()
     elif (type == 'medicaldevices'):
         return MedicalDevicesDAO()
     elif (type == 'powergenerator'):
         return PowerGeneratorDAO()
     elif (type == 'hygiene'):
         return HygieneDAO()
     elif (type == 'water'):
         return WaterDAO()
예제 #18
0
 def searchIce(self, args):
     icesize = args.get('icesize')
     icedescription = args.get('icedescription')
     dao = IceDAO()
     ice_list = []
     if icesize:
         ice_list = dao.getIceBySize(icesize)
     elif icedescription:
         ice_list = dao.getIceByDescription(icedescription)
     else:
         return jsonify(Error="Malformed query string"), 400
     result_list = []
     for row in ice_list:
         result = self.build_ice_dict(row)
         result_list.append(result)
     return jsonify(Ice=result_list)
예제 #19
0
    def insertIce(self, json):
        supplier_id = json['supplier_id']
        category_id = json['category_id']
        ice_name = json['ice_name']
        ice_brand = json['ice_brand']
        ice_quantity = json['ice_quantity'] 
        ice_price = json['ice_price']
        ice_weight = json['ice_weight']

        if supplier_id and category_id and ice_name and ice_brand and ice_quantity and (ice_price>=0) and ice_weight:
            resource_dao = ResourceDAO()
            resource_id = resource_dao.insert(supplier_id, category_id, ice_name, ice_brand, ice_quantity, ice_price)
            ice_dao = IceDAO()
            ice_id = ice_dao.insert(resource_id, ice_weight)
            result = self.build_ice_attributes(ice_id, supplier_id, resource_id, category_id, ice_name, ice_brand, ice_quantity, ice_price, ice_weight)
            return jsonify(Ice = result), 201
        else:
            return jsonify(Error = "Unexpected attributes in post request"), 400
예제 #20
0
    def updateIce(self, ice_id, json):
        ice_dao = IceDAO()
        if not ice_dao.getIceById(ice_id):
            return jsonify(Error = "Ice not found."), 404
        else:
            supplier_id = json['supplier_id']
            category_id = json['category_id']
            ice_name = json['ice_name']
            ice_brand = json['ice_brand']
            ice_quantity = json['ice_quantity'] 
            ice_price = json['ice_price']
            ice_weight = json['ice_weight']

            if supplier_id and category_id and ice_name and ice_brand and ice_quantity and (ice_price>=0) and ice_weight:
                resource_id = ice_dao.update(ice_id, ice_weight)
                res_dao = ResourceDAO()
                res_dao.update(resource_id, supplier_id, category_id, ice_name, ice_brand, ice_quantity, ice_price)
                result = self.build_ice_attributes(ice_id, supplier_id, resource_id, category_id, ice_name, ice_brand, ice_quantity, ice_price , ice_weight)
                return jsonify(Ice = result), 200
            else:
                return jsonify(Error = "Unexpected attributes in update request"), 400