コード例 #1
0
    def searchResources(self, args):
        if len(args) > 2:
            return jsonify(Error="Malformed search string."), 400
        else:
            rid = args.get("rid")
            sid = args.get("sid")
            qty = args.get("qty")

            dao = ResourcesDAO()
            resources_list = []

            if (len(args) == 1) and rid:
                resources_list = dao.getResourcesById(rid)
            elif (len(args) == 1) and sid:
                resources_list = dao.getResourcesBySupplierId(sid)
            elif (len(args) == 1) and qty:
                resources_list = dao.getResourcesByQuantity(qty)
            else:
                return jsonify(Error="Malformed query string"), 400

        result_list = []
        for row in resources_list:
            result = self.build_resource_dict(row)
            result_list.append(result)
        return jsonify(Resources=result_list)
コード例 #2
0
    def getResourcesById(self, rid):
        dao = ResourcesDAO()
        row = dao.getResourcesById(rid)

        if not row:
            return jsonify(Error="Resource Not Found"), 404
        else:
            resource = self.build_resource_dict(row)
            return jsonify(Resource=resource)