Exemple #1
0
 def acquireResource(self, pid, form):
     dao = PersonDAO()
     rid = form['r_id']
     requestquantity = form['resource_total']
     result = dao.acquireResource(pid, rid, requestquantity)
     if result == 'No request':
         return jsonify(Error="No request exist for that resource"), 404
     elif result == 'No payment':
         return jsonify(Error="No payment exists for that order"), 404
     elif result == 'Reservation done':
         return jsonify(
             Error="Resource is already reserved for that person"), 400
     elif result == 'Purchase done':
         return jsonify(
             Error="Resource is already purchased for that person"), 400
     elif result == 'Not available':
         return jsonify(
             "Error: Resource Unavailable or requested quantity is too high"
         ), 400
     elif result == 'Not enough':
         return jsonify("Error: Payment amount is not enough"), 400
     elif result == 'Succeed':
         if rid and requestquantity:
             result = {}
             result['p_id'] = pid
             result['r_id'] = rid
             result['resource_total'] = requestquantity
             return jsonify(Request=result), 200
Exemple #2
0
 def insertPerson(self, form):
     if form and len(form) == 7:
         pfirstname = form['first_name']
         pmiddleinitial = form['middle_initial']
         plastname = form['last_name']
         email = form['email']
         plocation = form['location_of_p']
         pphone = form['phone']
         loginID = form['login_id']
         if pfirstname and plastname and pmiddleinitial and pphone and loginID and plocation and email:
             dao = PersonDAO()
             pid = dao.insert(pfirstname, pmiddleinitial, plastname, email,
                              plocation, pphone, loginID)
             result = {}
             result['p_id'] = pid
             result['first_name'] = pfirstname
             result['middle_initial'] = pmiddleinitial
             result['last_name'] = plastname
             result['email'] = email
             result['location_of_p'] = plocation
             result['phone'] = pphone
             result['login_id'] = loginID
             return jsonify(Person=result), 201
         else:
             return jsonify('Unexpected attributes in post request'), 401
     else:
         return jsonify(Error="Malformed post request"), 400
Exemple #3
0
 def updatePerson(self, pid, form):
     dao = PersonDAO()
     if not dao.getPersonById(pid):
         return jsonify(Error="Person not found."), 404
     else:
         if len(form) != 7:
             return jsonify(Error="Malformed update request"), 400
         else:
             pfirstname = form['first_name']
             pmiddleinitial = form['middle_initial']
             plastname = form['last_name']
             email = form['email']
             plocation = form['location_of_p']
             pphone = form['phone']
             loginID = form['login_id']
             if pfirstname and plastname and pmiddleinitial and pphone and loginID and plocation and email:
                 dao.update(pid, pfirstname, pmiddleinitial, plastname,
                            email, plocation, pphone, loginID)
                 result = {}
                 result['p_id'] = pid
                 result['first_name'] = pfirstname
                 result['middle_initial'] = pmiddleinitial
                 result['last_name'] = plastname
                 result['email'] = email
                 result['location_of_p'] = plocation
                 result['phone'] = pphone
                 result['login_id'] = loginID
                 return jsonify(Person=result), 200
             else:
                 return jsonify(
                     Error="Unexpected attributes in update request"), 400
Exemple #4
0
 def deletePerson(self, pid):
     dao = PersonDAO()
     if not dao.getPersonById(pid):
         return jsonify(Error="Person not found."), 404
     else:
         dao.delete(pid)
         return jsonify(DeleteStatus="OK"), 200
Exemple #5
0
 def getPersonById(self, pid):
     dao = PersonDAO()
     person1 = dao.getPersonById(pid)
     if not person1:
         return jsonify(Error="Person Not Found"), 404
     else:
         person = self.build_person_dict(person1)
     return jsonify(Person=person)
Exemple #6
0
 def getAllPerson(self):
     dao = PersonDAO()
     person_list = dao.getAllPerson()
     result_list = []
     for row in person_list:
         result = self.build_person_dict(row)
         result_list.append(result)
     return jsonify(PersonList=result_list)
Exemple #7
0
    def getPersonByEmail(self, email):
        dao = PersonDAO()
        persons = []
        items = dao.getPersonByEmail(email)

        for i in items:
            result = self.build_Person_dict(i)
            persons.append(result)

        return jsonify(Person=persons)
Exemple #8
0
    def getPersonByPhone(self, phone):
        dao = PersonDAO()
        persons = []
        items = dao.getPersonByPhone(phone)

        for i in items:
            result = self.build_Person_dict(i)
            persons.append(result)

        return jsonify(Person=persons)
Exemple #9
0
    def getPersonByAddress(self, location):
        dao = PersonDAO()
        persons = []
        items = dao.getPersonByLocation(location)

        for i in items:
            result = self.build_Person_dict(i)
            persons.append(result)

        return jsonify(Person=persons)
Exemple #10
0
    def getAllPersons(self):
        dao = PersonDAO()
        persons = []
        items = dao.getAllPersons()

        for i in items:
            result = self.build_Person_dict(i)
            persons.append(result)

        return jsonify(Person=persons)
Exemple #11
0
 def getReservedResourcesByPersonId(self, pid):
     dao = PersonDAO()
     person1 = dao.getPersonById(pid)
     if not person1:
         return jsonify(Error="Person Not Found"), 404
     resources_list = dao.getReservedResourcesByPersonId(pid)
     result_list = []
     for row in resources_list:
         result = self.build_reserved_and_purchased_resource_dict(row)
         result_list.append(result)
     return jsonify(ReservedResourcesByPersonID=result_list)
Exemple #12
0
 def getPersonByLocation(self, location):
     dao = PersonDAO()
     person_list = dao.getPersonByLocation(location)
     if not person_list:
         return jsonify(Error="Person Not Found"), 404
     else:
         result_list = []
         for row in person_list:
             result = self.build_person_dict(row)
             result_list.append(result)
         return jsonify(PersonList=result_list)
Exemple #13
0
 def searchPerson(self, args):
     if len(args) > 1:
         return jsonify(Error="Malformed search string."), 400
     else:
         location = args.get("location_of_p")
         if location:
             dao = PersonDAO()
             person_list = dao.getPersonByLocation(location)
             result_list = []
             for row in person_list:
                 result = self.build_person_dict(row)
                 result_list.append(row)
             return jsonify(PersonList=result_list)
         else:
             return jsonify(Error="Malformed search string."), 400
Exemple #14
0
 def getGroupsByPersonID(self, pID):
     dao = PersonDAO()
     if not dao.getPersonById(pID):
         dao.closeDB()
         return jsonify(Error="Person NOT FOUND"), 404
     groups_list = dao.getGroupsByPersonID(pID)
     if not groups_list:
         dao.closeDB()
         return jsonify(Error="Group NOT FOUND"), 404
     results = []
     for row in groups_list:
         result = mapGroupToDict(row)
         results.append(result)
     dao.closeDB()
     return jsonify(Group=results)
Exemple #15
0
 def getReactsByPersonID(self, pID):
     dao = PersonDAO()
     if not dao.getPersonById(pID):
         dao.closeDB()
         return jsonify(Error="Person NOT FOUND"), 404
     reacts_list = dao.getReactsByPersonID(pID)
     if not reacts_list:
         dao.closeDB()
         return jsonify(Error="React NOT FOUND"), 404
     results = []
     for row in reacts_list:
         result = mapToReactDict(row)
         results.append(result)
     dao.closeDB()
     return jsonify(React=results)
Exemple #16
0
 def getMessagesByPersonID(self, pID):
     dao = PersonDAO()
     if not dao.getPersonById(pID):
         dao.closeDB()
         return jsonify(Error="Person NOT FOUND"), 404
     message_list = dao.getMessagesByPersonID(pID)
     if not message_list:
         dao.closeDB()
         return jsonify(Error="Message NOT FOUND"), 404
     results = []
     for row in message_list:
         result = mapMessageToDict(row)
         results.append(result)
     dao.closeDB()
     return jsonify(Message=results)
Exemple #17
0
 def getPersonByUsername(self, args):
     dao = PersonDAO()
     username = args.get('username')
     if not username or len(args) != 1:
         dao.closeDB()
         return jsonify(Error="Bad Request Arguments"), 400
     result = dao.getPersonByUsername(username)
     if result is None:
         dao.closeDB()
         return jsonify(Error="Person NOT FOUND"), 404
     else:
         mapped = mapPersonToDict(result)
         dao.closeDB()
         return jsonify(Person=mapped)
Exemple #18
0
 def offerPayment(self, pid, form):
     dao = PersonDAO()
     if not dao.getPersonById(pid):
         return jsonify(Error="Person not found."), 404
     elif form and len(form) == 2:
         paytype = form['payment_type']
         paymenttotal = form['payment_total']
         if paytype and paymenttotal:
             text = dao.offerPayment(pid, paytype, paymenttotal)
             if text == "New payment":
                 result = {}
                 result['p_id'] = pid
                 result['payment_type'] = paytype
                 result['payment_total'] = paymenttotal
                 return jsonify(Payment=result), 201
         else:
             return jsonify('Unexpected attributes in post request'), 401
     else:
         return jsonify(Error="Malformed post request"), 400
Exemple #19
0
 def requestResource(self, pid, form):
     dao = PersonDAO()
     if not dao.getPersonById(pid):
         return jsonify(Error="Person not found."), 404
     else:
         if len(form) != 2:
             return jsonify(Error="Malformed update request"), 400
         else:
             rid = form['r_id']
             requestquantity = form['request_quantity']
             if rid and requestquantity:
                 dao.requestResource(pid, rid, requestquantity)
                 result = {}
                 result['p_id'] = pid
                 result['r_id'] = rid
                 result['request_quantity'] = requestquantity
                 return jsonify(Request=result), 200
             else:
                 return jsonify(
                     Error="Unexpected attributes in insert request"), 400
Exemple #20
0
 def getPersonById(self, pID):
     dao = PersonDAO()
     result = dao.getPersonById(pID)
     if result is None:
         dao.closeDB()
         return jsonify(Error="Person NOT FOUND"), 404
     else:
         mapped = mapPersonToDict(result)
         dao.closeDB()
         return jsonify(Person=mapped)
Exemple #21
0
 def getContactsByPersonID(self, pID):
     dao = PersonDAO()
     if not dao.getPersonById(pID):
         dao.closeDB()
         return jsonify(Error="Person NOT FOUND"), 404
     contact_list = dao.getContactsByPersonID(pID)
     if contact_list is None:
         dao.closeDB()
         return jsonify(Error="Contact NOT FOUND"), 404
     results = []
     for row in contact_list:
         mappedResult = {}
         mappedResult['pID'] = row[0]
         mappedResult['username'] = row[1]
         mappedResult['pFirstName'] = row[2]
         mappedResult['pLastName'] = row[3]
         mappedResult['pPhone'] = row[4]
         mappedResult['pEmail'] = row[5]
         results.append(mappedResult)
     dao.closeDB()
     return jsonify(Persons=results)
Exemple #22
0
 def getAllPersons(self):
     dao = PersonDAO()
     result = dao.getAllPersons()
     if not result:
         dao.closeDB()
         return jsonify(Error="Person NOT FOUND"), 404
     mapped_result = []
     for r in result:
         mapped_result.append(mapPersonToDict(r))
     dao.closeDB()
     return jsonify(Person=mapped_result)
Exemple #23
0
 def addPerson(self, json):
     dao = PersonDAO()
     if len(json) != 6:
         dao.closeDB()
         return jsonify(Error="Malformed post request"), 400
     else:
         username = json['username']
         password = json['password']
         firstname = json['pfirstname']
         lastname = json['plastname']
         phone = json['pphone']
         email = json['pemail']
         if username and password and firstname and lastname and phone and email:
             pid = dao.addPerson(username, password, firstname, lastname,
                                 phone, email)
             result = mapPersonToDict([
                 pid, username, password, firstname, lastname, phone, email
             ])
             dao.closeDB()
             return jsonify(Person=result), 201
         else:
             dao.closeDB()
             return jsonify(
                 Error="Unexpected attributes in post request"), 400
Exemple #24
0
 def getPersonById(self, perid):
     dao = PersonDAO()
     person = dao.getPersonByID(perid)
     return jsonify(person), 200
Exemple #25
0
 def deleteContact(self, ownerid, perid):
     dao = PersonDAO()
     status = dao.deleteContact(ownerid, perid)
     return jsonify(DeleteStatus=status), 200
Exemple #26
0
 def getPersonByArguments(self, args):
     dao = PersonDAO()
     person_list = dao.getPersonByFullName(args)
     return jsonify(person_list), 200
Exemple #27
0
 def addConctact(self, ownerid, perid):
     dao = PersonDAO()
     response = dao.addContact(ownerid, perid)
     return jsonify(response=response), 200
Exemple #28
0
 def insertPersonJson(self, json):
     dao = PersonDAO()
     new_person = dao.insert(json)
     return jsonify(new_person), 200
Exemple #29
0
 def updatePerson(self, perid, form):
     dao = PersonDAO()
     updated_person = dao.update(perid, form)
     return jsonify(updated_person), 200
Exemple #30
0
 def deletePerson(self, perid):
     dao = PersonDAO()
     id = dao.delete(perid)
     return jsonify(DeleteStatus='OK'), 200