def setUp(self):
        self.r1 = [
            1, 'Toilet Paper', 'this is NOT a description', 'home',
            'Requesting', 1
        ]
        self.r2 = [
            2, 'Hand Sanitizer', 'this MAY be a decription', 'Maya',
            'Provided', 3
        ]
        self.r3 = [
            3, 'Food', 'this is POSSIBLY a description', 'laCalle', 'Provided',
            1
        ]
        self.r4 = [
            4, 'send help pls', 'this is ME DOING a description', 'home',
            'Requesting', 3
        ]
        self.r5 = [
            5, 'beer', 'this is JUST a description', 'bar', 'Requesting', 4
        ]

        self.keys = [
            'rid', 'rtitle', 'rdescription', 'rlocation', 'rstatus', 'ruser'
        ]
        self.rh = RequestHandler()
        self.dao = RequestDAO()
        self.app = Flask(__name__)
Ejemplo n.º 2
0
 def setUp(self):
     self.r1 = [
         1, 'Toilet Paper', 'this is NOT a description', 'home',
         'Requesting', 1
     ]
     self.r2 = [
         2, 'Hand Sanitizer', 'this MAY be a decription', 'Maya',
         'Provided', 3
     ]
     self.r3 = [
         3, 'Food', 'this is POSSIBLY a description', 'laCalle', 'Provided',
         1
     ]
     self.r4 = [
         4, 'send help pls', 'this is ME DOING a description', 'home',
         'Requesting', 3
     ]
     self.r5 = [
         5, 'beer', 'this is JUST a description', 'bar', 'Requesting', 4
     ]
     self.requests: list = [self.r1, self.r2, self.r3, self.r4, self.r5]
     self.user1 = [1, 'Morsa', 'faces4444', '*****@*****.**', '7878598899']
     self.keys = [
         'rid', 'rtitle', 'rdescription', 'rlocation', 'rstatus', 'ruser'
     ]
     self.rh = RequestHandler()
     self.dao = RequestDAO()
     self.daoUSER = UserDAO()
     self.app = Flask(__name__)
Ejemplo n.º 3
0
 def insert_request(self, json_input):
     if len(json_input
            ) != 5:  # check if there are sufficient elements in input
         return jsonify(Error="Malformed insert request"), 400
     try:  # check parameters are valid
         rtitle: str = json_input['rtitle']
         rdescription: str = json_input['rdescription']
         rlocation: str = json_input['rlocation']
         rstatus: str = json_input['rstatus']
         ruser: int = json_input['ruser']  # must be an int
     except Exception as e:
         print(e)
         return jsonify(
             Error="Unexpected attributes in insert request"), 400
     try:
         if rtitle and rdescription and rlocation and rstatus and ruser:
             rid: int = RequestDAO().insert_request(rtitle, rdescription,
                                                    rlocation, rstatus,
                                                    ruser)
         else:
             return jsonify(Error="One or more attribute is empty"), 400
     except Exception as e:
         print(e)
         return jsonify(Error="Request insertion failed horribly."), 400
     # Finally returns an request dict of the inserted request.
     return jsonify(Request=self.create_request_dict(
         [rid, rtitle, rdescription, rlocation, rstatus, ruser])), 201
 def insert_provider(self, json_input):
     if len(json_input
            ) != 2:  # check if there are sufficient elements in input
         return jsonify(Error="Malformed insert provider request"), 400
     try:  # check parameters are valid
         puser = json_input['puser']
         prequest = json_input['prequest']
     except:
         return jsonify(
             Error="Unexpected attributes in insert provider request"), 400
     try:
         if puser and prequest:
             # Validate that puser != ruser:
             if puser == RequestHandler.create_request_dict(
                     RequestDAO().get_request_by_id(prequest))['ruser']:
                 return jsonify(
                     Error="User cannot provide his own request"), 400
             # Insert provider
             dao = ProviderDAO()
             pid = dao.insert_provider(puser, prequest)
             # Update status of request
             form = {}
             form['prequest'] = prequest
             form[
                 'rstatus'] = 'InProgress'  #  YELLOW, its updated to delivery on it's way.
             self.update_request_status_by_provider(form)
         else:
             return jsonify(Error="One or more attribute is empty"), 400
     except:
         return jsonify(Error="Provider insertion failed horribly."), 400
     # Finally returns an user dict of the inserted provider.
     return jsonify(
         Provider=self.createProviderDict([pid, puser, prequest])), 201
Ejemplo n.º 5
0
 def get_request_by_status(self, status: str):
     try:
         requests = RequestDAO().get_request_by_status(status)
         results = list()
         for row in requests:
             results.append(self.create_request_dict(row))
         return jsonify(Requests=results), 200
     except Exception as e:
         print(e)
         return jsonify(ERROR=e), 500
Ejemplo n.º 6
0
 def get_request_by_uid(self, uid: int):
     try:
         requests = RequestDAO().get_requests_by_user_id(uid)
         results = list()
         for row in requests:
             results.append(self.create_request_dict(row))
         return jsonify(Requests=results), 200
     except Exception as e:
         print(e)
         return jsonify(ERROR=e), 500
Ejemplo n.º 7
0
 def get_requests_by_user_status(self, rid: int, status: str):
     try:
         requests = RequestDAO().get_requests_by_user_status(rid, status)
         results = list()
         for row in requests:
             results.append(self.create_request_dict(row))
         return jsonify(Requests=results), 200
     except Exception as e:
         print(e)
         return jsonify(ERROR="Unexpected error"), 500
Ejemplo n.º 8
0
 def get_request_by_location(self, location: str):
     try:
         requests = RequestDAO().get_request_by_location(location)
         results = list()
         for row in requests:
             results.append(self.create_request_dict(row))
         return jsonify(Requests=results)
     except Exception as e:
         print(e)
         return jsonify(ERROR=e), 500
Ejemplo n.º 9
0
 def delete_request_by_id(self, rid: int):
     try:
         dao = RequestDAO()
         row = dao.get_request_by_id(rid)
         if not row:
             return jsonify(Error="Request" + str(rid) + " not found."), 404
         else:
             if dao.delete_request_by_id(rid) > 0:
                 return jsonify(DeletedRequest=self.create_request_dict(row)), 200
             else:
                 return jsonify(Error="Delete failed"), 404
     except Exception as e:
         print(e)
         return jsonify(ERROR=e), 500