Exemplo n.º 1
0
 def deleteResource(self, rid):
     dao = ResourcesDAO()
     if not dao.getResourceById(rid):
         return jsonify(Error="Resource not found."), 404
     else:
         dao.delete(rid)
         return jsonify(DeleteStatus="OK"), 200
Exemplo n.º 2
0
 def getResourceById(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)
Exemplo n.º 3
0
 def getAllResources(self):
     dao = ResourcesDAO()
     resources_list = dao.getAllResources()
     result_list = []
     for row in resources_list:
         result = self.build_resource_dict(row)
         result_list.append(result)
     return jsonify(Resources=result_list)
Exemplo n.º 4
0
 def getSuppliersByResourceId(self, rid):
     dao = ResourcesDAO()
     if not dao.getResourceById(rid):
         return jsonify(Error="Resource Not Found"), 404
     suppliers_list = dao.getSuppliersByResourceId(rid)
     result_list = []
     for row in suppliers_list:
         result = self.build_supplier_dict(row)
         result_list.append(result)
     return jsonify(Suppliers=result_list)
Exemplo n.º 5
0
 def insertResourceBySupplierIdJson(self, rid, json):
     sid = json['sid']
     resv_amount = json['resv_amount']
     cost = json['cost']
     rname = json['rname']
     if rname and resv_amount and cost and sid:
         dao = ResourcesDAO()
         r = dao.insert(rid, sid, rname, cost, resv_amount)
         if r:
             result = self.build_resource_attributes(
                 rid, sid, rname, cost, resv_amount)
             return jsonify(Resource=result), 201
         else:
             return jsonify(
                 Error="Resource not found or invalid supplier id."), 404
     else:
         return jsonify(Error="Unexpected attributes in post request"), 400
Exemplo n.º 6
0
 def insertResourcesJson(self, form):
     print("form: ", form)
     if len(form) != 4:
         return jsonify(Error="Malformed post request"), 400
     else:
         sid = form['sid']
         resv_amount = form['resv_amount']
         cost = form['cost']
         rname = form['rname']
         if rname and resv_amount and cost and sid:
             dao = ResourcesDAO()
             rid = dao.insert(sid, rname, cost, resv_amount)
             result = self.build_resource_attributes(
                 rid, sid, rname, cost, resv_amount)
             return jsonify(Resource=result), 201
         else:
             return jsonify(
                 Error="Unexpected attributes in post request"), 400
Exemplo n.º 7
0
 def searchResources(self, args):  #Fixed
     name = args.get("name")
     cost = args.get("cost")
     dao = ResourcesDAO()
     resources_list = []
     if (len(args) == 2) and name and cost:
         resources_list = dao.getResourcesByNameAndCost(name, cost)
     elif (len(args) == 1) and name:
         resources_list = dao.getResourcesByName(name)
     elif (len(args) == 1) and cost:
         resources_list = dao.getResourcesByCost(cost)
     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)
Exemplo n.º 8
0
 def updateResource(self, rid, form):
     dao = ResourcesDAO()
     if not dao.getResourceById(rid):
         return jsonify(Error="Resource not found."), 404
     else:
         if len(form) != 4:
             return jsonify(Error="Malformed update request"), 400
         else:
             sid = form['sid']
             resv_amount = form['resv_amount']
             cost = form['cost']
             rname = form['rname']
             if rname and resv_amount and cost and sid:
                 dao.update(rid, sid, rname, cost, resv_amount)
                 result = self.build_resource_attributes(
                     rid, sid, rname, cost, resv_amount)
                 return jsonify(Resource=result), 200
             else:
                 return jsonify(
                     Error="Unexpected attributes in update request"), 400
Exemplo n.º 9
0
 def getCountByResourceId(self):
     dao = ResourcesDAO()
     result = dao.getCountByResourceId()
     # print(self.build_resource_counts(result))
     return jsonify(ResourceCounts=self.build_resource_counts(result)), 200