Beispiel #1
0
 def getRequestedResources(self):
     dao = ResourceRequestsDAO()
     request_list = dao.getRequestedResources()
     result_list = []
     for row in request_list:
         request = ResourceRequest().build_dict_from_row2(row)
         result_list.append(request)
     return jsonify(result_list)
Beispiel #2
0
 def getRequestById(self, req_id):
     dao = ResourceRequestsDAO()
     request = dao.getRequestByIdWithDetails(req_id)
     if not request:
         return jsonify(Error="Availability Announcement Not Found"), 404
     else:
         result = ResourceRequest().build_dict_from_table_details(request)
         return jsonify(result)
Beispiel #3
0
    def searchRequests(self, args):
        allowedKeys = {"rid", "rname", "catname", "catid"}
        for key in args.keys():
            if key not in allowedKeys:
                return jsonify(Error="Malformed query string"), 400

        dao = ResourceRequestsDAO()
        request_list = dao.getRequestsByParameters(args)
        result_list = ResourceRequest().build_dict_from_table(request_list)
        return jsonify(result_list)
Beispiel #4
0
    def insertRequest(self, form, nid):
        # New Resource
        if len(form) == 3:
            rname = form['rname']
            catid = form['catid']
            qty = form['qty']
            if rname and catid and qty:
                dao = ResourcesDAO()
                resource = dao.getResourcesByRname(rname)
                if not resource:
                    dao2 = CategoriesDAO()
                    if not dao2.getCategoryById(catid):
                        return jsonify(Error="Category Not Found"), 404
                    rid = dao.insert(rname, catid)
                else:
                    rid = (resource[0])[0]

                dao = ResourceRequestsDAO()
                req_id = dao.insertRequest(nid)

                dao3 = ResourceRequestDetailsDAO()
                dao3.insertRequestDetails(req_id, rid, qty)

                table = dao.getRequestByIdWithDetails(req_id)

                if not table:
                    return jsonify(Error="Request Not Found"), 404
                else:
                    print(table)
                    result = ResourceRequest().build_dict_from_table_details(
                        table)
                    return jsonify(result)
        elif len(form) != 2:
            return jsonify(Error="Malformed post request"), 400
        else:
            # Existing Resource
            rid = form['rid']
            qty = form['qty']

            if rid and qty:
                dao = ResourcesDAO()
                if not dao.getResourceById(rid):
                    return jsonify(Error="Resource Not Found"), 404

                dao2 = ResourceRequestsDAO()
                reqid = dao2.insertRequest(nid)
                dao3 = ResourceRequestDetailsDAO()
                dao3.insertRequestDetails(reqid, rid, qty)

                result = ResourceRequest().build_dict_from_row_resource(
                    dao2.getRequestByIdWithDetails2(reqid))
                return jsonify(result), 201
            else:
                return jsonify(
                    Error="Unexpected attributes in post request"), 400
Beispiel #5
0
 def getRequestsByNid(self, nid):
     dao = RequestersDAO()
     row = dao.getRequesterById(nid)
     if not row:
         return jsonify(Error="Requester Not Found"), 404
     else:
         dao2 = ResourceRequestsDAO()
         requests_list = dao2.getRequestsByNid(nid)
         if not requests_list:
             return jsonify([])
         result_list = ResourceRequest().build_dict_from_table_no_nid(
             requests_list)
         return jsonify(result_list)
Beispiel #6
0
 def getRequestByIds(self, nid, req_id):  #new by herbert
     dao = RequestersDAO()
     row = dao.getRequesterById(nid)
     if not row:
         return jsonify(Error="Requester Not Found"), 404
     else:
         dao2 = ResourceRequestsDAO()
         requests_list = dao2.getRequestsByNid(nid)
         if not requests_list[0]:
             return jsonify(Error="Request Not Found"), 404
         dao = ResourceRequestsDAO()
         newresult = ResourceRequest().build_dict_from_table_no_nid(
             dao.getRequestByIdWithDetailsNoReq(req_id))
         return jsonify(newresult)
Beispiel #7
0
    def updateRequestDetailsByReqId(self, form, req_id):
        if len(form) == 2:
            rid = form['rid']
            qty = form['qty']

            if rid and qty:

                rdao = ResourcesDAO()
                if not rdao.getResourceById(rid):
                    return jsonify(Error="Resource Not Found"), 404

                rrdao = ResourceRequestsDAO()
                if not rrdao.getRequestByIdWithDetails(req_id):
                    return jsonify(Error="Request Not Found"), 404

                rrddao = ResourceRequestDetailsDAO()
                if not rrddao.getRequestDetailsById(req_id, rid):
                    return jsonify(Error="Request Detail Not Found"), 404

                if rrddao.getRequestDetailsById(req_id, rid)[3]:
                    return jsonify(Error="Request Detail was Fulfilled"), 400

                rrddao.update(req_id, rid, qty, None)
                #FIX HEREEEE
                result = ResourceRequest().build_dict_from_table_no_nid(
                    rrdao.getRequestByIdWithDetailsNoReq(req_id))
                return jsonify(result), 201
            else:
                return jsonify(
                    Error="Unexpected Attributes in Put Request"), 400
        elif len(form) != 3:
            return jsonify("Malformed Put Request"), 400
        else:
            rid = form['rid']
            qty = form['qty']
            date = form['f_date']

            if rid and qty and date:
                rdao = ResourcesDAO()
                if not rdao.getResourceById(rid):
                    return jsonify(Error="Resource Not Found"), 404

                rrdao = ResourceRequestsDAO()
                if not rrdao.getRequestByIdWithDetails2(req_id):
                    return jsonify(Error="Request Not Found"), 404

                rrddao = ResourceRequestDetailsDAO()
                if not rrddao.getRequestDetailsById(req_id, rid):
                    return jsonify(Error="Request Detail Not Found"), 404

                if rrddao.getRequestDetailsById(req_id, rid)[3]:
                    return jsonify(Error="Request Detail was Fulfilled"), 400

                rrddao.update(req_id, rid, qty, date)
                result_list = rrdao.getRequestByIdWithDetails2(req_id)
                table = []

                #FIX HEREEEEE
                result = ResourceRequest().build_dict_from_table_no_nid(
                    rrdao.getRequestByIdWithDetails(req_id))
                return jsonify(result), 201

            else:
                return jsonify(
                    Error="Unexpected Attributes in Put Request"), 400
Beispiel #8
0
    def insertRequestDetailsByReqId(self, form, req_id):

        # Existing Resource
        if 2 == len(form):
            rid = form['rid']
            qty = form['qty']

            if rid and qty:
                dao = ResourcesDAO()
                if not dao.getResourceById(rid):
                    return jsonify(Error="Resource Not Found"), 404

                dao2 = ResourceRequestsDAO()
                request = dao2.getRequestByIdWithDetails(req_id)
                if not request:
                    return jsonify(Error="Request Not Found"), 404
                else:
                    nid = request[0]

                dao3 = ResourceRequestDetailsDAO()
                if not dao3.getRequestDetailsById(req_id, rid):
                    dao3.insertRequestDetails(req_id, rid, qty)
                else:
                    return jsonify(Error="Duplicate Primary Key"), 400

                table = dao2.getRequestByIdWithDetails2(req_id)
                if not table:
                    return jsonify(Error="Resource Request Not Found"), 404
                else:
                    result = ResourceRequest().build_dict_from_row_resource(
                        table)
                    return jsonify(result)
        elif len(form) != 3:
            return jsonify(Error="Malformed Post Request"), 400

        # New Resource
        else:
            rname = form['rname']
            catid = form['catid']
            qty = form['qty']
            if rname and catid and qty:
                dao = ResourcesDAO()
                dao2 = CategoriesDAO()

                # Check if resource exists
                resource = dao.getResourcesByRname(rname)
                if not resource:
                    # Create new resource
                    if not dao2.getCategoryById(catid):
                        return jsonify(Error="Category Not Found"), 404
                    rid = dao.insert(rname, catid)
                else:
                    rid = (resource[0])[0]

                dao3 = ResourceRequestsDAO()
                request = dao3.getRequestByIdWithDetails(req_id)
                if not request or not request[0]:
                    return jsonify(Error="Request Not Found"), 404
                else:
                    nid = request[0][2]
                dao4 = ResourceRequestDetailsDAO()
                if not dao4.getRequestDetailsById(req_id, rid):
                    dao4.insertRequestDetails(req_id, rid, qty)
                else:
                    return jsonify(Error="Duplicate Primary Key"), 400

                table = dao3.getRequestByIdWithDetails(req_id)
                if not table:
                    return jsonify(Error="Request Not Found"), 404
                else:
                    result = ResourceRequest().build_dict_from_table_details(
                        table)
                    return jsonify(result)
            else:
                return jsonify(Error="Malformed Post Request"), 400
Beispiel #9
0
 def getAllRequests(self):
     dao = ResourceRequestsDAO()
     request_list = dao.getAllRequests()
     result_list = ResourceRequest().build_dict_from_table(request_list)
     return jsonify(result_list)