示例#1
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)
示例#2
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)
示例#3
0
 def getPeopleByGroupID(self, gID):
     dao = GroupDAO()
     if not dao.getGroupById(gID):
         dao.closeDB()
         return jsonify(Error="Group NOT FOUND"), 404
     person_list = dao.getPeopleByGroupID(gID)
     results = []
     for row in person_list:
         result = mapPersonToDict(row)
         results.append(result)
     dao.closeDB()
     return jsonify(Person=results)
示例#4
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)
示例#5
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