Example #1
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
Example #2
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
Example #3
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