Esempio n. 1
0
 def deleteWater(self, waterid):
     dao = WaterDAO()
     if not dao.getWaterById(waterid):
         return jsonify(Error="Resource not found"), 404
     else:
         dao.delete(waterid)
         return jsonify(DeleteStatus="OK"), 200
Esempio n. 2
0
    def updateWater(self, water_id, json):
        water_dao = WaterDAO()
        if not water_dao.getWaterById(water_id):
            return jsonify(Error="Water not found."), 404
        else:
            supplier_id = json["supplier_id"]
            category_id = json["category_id"]
            water_name = json["water_name"]
            water_brand = json["water_brand"]
            water_quantity = json["water_quantity"]
            water_price = json["water_price"]
            water_size = json["water_size"]
            water_container = json["water_container"]
            water_type = json["water_type"]
            water_exp_date = json["water_exp_date"]

            if supplier_id and category_id and water_name and water_brand and water_quantity and (
                    water_price >= 0
            ) and water_size and water_container and water_type and water_exp_date:
                resource_id = water_dao.update(water_id, water_size,
                                               water_container, water_type,
                                               water_exp_date)
                resource_dao = ResourceDAO()
                resource_dao.update(resource_id, supplier_id, category_id,
                                    water_name, water_brand, water_quantity,
                                    water_price)
                result = self.build_water_attributes(
                    water_id, resource_id, supplier_id, category_id,
                    water_name, water_brand, water_quantity, water_price,
                    water_size, water_container, water_type, water_exp_date)
                return jsonify(Water=result), 200
            else:
                return jsonify(
                    Error="Unexpected attributes in update request"), 400
Esempio n. 3
0
 def getWaterByID(self, waterid):
     dao = WaterDAO()
     row = dao.getWaterById(waterid)
     if not row:
         return jsonify(Error="Water Not Found "), 404
     else:
         water = self.build_water_dict(row)
         return jsonify(Water=water)
Esempio n. 4
0
 def deleteWater(self, water_id):
     water_dao = WaterDAO()
     if not water_dao.getWaterById(water_id):
         return jsonify(Error="Water not found."), 404
     else:
         resource_id = water_dao.delete(water_id)
         resource_dao = ResourceDAO()
         resource_dao.delete(resource_id)
         return jsonify(DeleteStatus="OK"), 200
Esempio n. 5
0
 def getWaterAddress(self, water_id):
     water_dao = WaterDAO()
     try:
         supplier_id = water_dao.getWaterById(water_id)[6]
     except Exception:
         return jsonify(Error="Water not found."), 404
     supplier_dao = SupplierDAO()
     if not supplier_dao.getSupplierById(supplier_id):
         return jsonify(Error="Supplier not found."), 404
     else:
         row = water_dao.getWaterAddress(supplier_id)
         if not row:
             return jsonify(Error="Address Not Found"), 404
         else:
             address = self.build_address_dict(row)
             return jsonify(Address=address)
Esempio n. 6
0
 def updateResourceJson(self, waterid, json):
     dao = WaterDAO()
     if not dao.getWaterById(waterid):
         return jsonify(Error="Resource not found"), 404
     else:
         watersize = json['watersize']
         waterdescription = json['waterdescription']
         if watersize and waterdescription:
             dao.update(waterid, watersize, waterdescription)
             resourceid = dao.getResourceIDByWaterID(waterid)
             result = self.build_water_attributes(waterid, resourceid,
                                                  watersize,
                                                  waterdescription)
             return jsonify(Water=result), 200
         else:
             return jsonify(
                 Error="Unexpected attributes in post request"), 400
Esempio n. 7
0
 def updateResource(self, waterid, form):
     dao = WaterDAO()
     if not dao.getWaterById(waterid):
         return jsonify(Error="Resource not found"), 404
     else:
         if (len(form) != 2):
             return jsonify(Error="Malformed update request")
         else:
             watersize = form['watersize']
             waterdescription = form['waterdescription']
             if watersize and waterdescription:
                 dao.update(waterid, watersize, waterdescription)
                 resourceid = dao.getResourceIDByWaterID(waterid)
                 result = self.build_water_attributes(
                     waterid, resourceid, watersize, waterdescription)
                 return jsonify(Water=result), 400
             else:
                 return jsonify(
                     Error="Unexpected attributes in update request"), 404