def deleteAdmin(self, admin_id): dao = AdminDAO() admin = dao.getAdminById(admin_id) if not admin: return jsonify(Error="Admin Not Found"), 404 dao.deleteAdmin(admin_id) return jsonify(DeleteStatus="OK"), 200
def deleteAdmin(self, admin_id): dao = AdminDAO() if not dao.getAdminById(admin_id): return jsonify(Error="Admin not found."), 404 else: dao.delete(admin_id) return jsonify(DeleteStatus="OK"), 200
def updateAdmin(self, admin_id, json): dao_admin = AdminDAO() if not dao_admin.getAdminById(admin_id): return jsonify(Error="Admin not found."), 404 else: admin_firstname = json['admin_firstname'] admin_lastname = json['admin_lastname'] admin_date_birth = json['admin_date_birth'] admin_email = json['admin_email'] admin_phone = json['admin_phone'] admin_phone_id = json["admin_phone_id"] if admin_firstname and admin_lastname and admin_date_birth and admin_email and admin_phone and admin_phone_id: user_id = dao_admin.update(admin_id) dao_user = UserDAO() dao_user.update(user_id, admin_firstname, admin_lastname, admin_date_birth, admin_email) dao_phone = UserPhoneDAO() dao_phone.update(user_id, admin_phone) result = self.build_admin_attributes( user_id, admin_id, admin_firstname, admin_lastname, admin_date_birth, admin_email, admin_phone_id, admin_phone) return jsonify(Admin=result), 200 else: return jsonify( Error="Unexpected attributes in update request"), 400
def insertAdmin(self, form): if len(form) != 9: return jsonify(Error="Malformed post request"), 400 else: u_name = form['u_name'] u_lastname = form['u_lastname'] u_email = form['u_email'] u_password = form['u_password'] u_address = form['u_address'] u_city = form['u_city'] u_region = form['u_region'] u_phone = form['u_phone'] u_age = form['u_age'] if u_name and u_lastname and u_email and u_password and u_address and u_city and u_region and u_phone and u_age: dao = AdminDAO() admin_id = dao.insert(u_name, u_lastname, u_email, u_password, u_address, u_city, u_region, u_phone, u_age) result = self.build_admin_attributes(admin_id, u_name, u_lastname, u_email, u_password, u_address, u_city, u_region, u_phone, u_age) return jsonify(Admin=result), 201 else: return jsonify( Error="Unexpected attributes in post request"), 400
def getAllAdmins(self): dao = AdminDAO() result = dao.getAllAdmins() result_list = [] for row in result: result = self.build_admin_dict(row) result_list.append(result) return jsonify(Admins=result_list)
def getAdminById(self, admin_id): dao = AdminDAO() row = dao.getAdminById(admin_id) if not row: return jsonify(Error="Admin Not Found"), 404 else: admin = self.build_admin_dict(row) return jsonify(Admin=admin)
def getAdminById(self, admin_id): dao = AdminDAO() admin_list = dao.getAdminById(admin_id) if not admin_list: return jsonify(Error="Administrator Not Found"), 404 else: result = self.build_admin_dict(admin_list) return jsonify(Administrator=result)
def getAdminByPhone(self, phone): dao = AdminDAO() users = [] items = dao.getAdminByPhone(phone) for i in items: result = self.build_admin_dict(i) users.append(result) return jsonify(User=users)
def getAdminByAddress(self, location): dao = AdminDAO() users = [] items = dao.getAdminByLocation(location) for i in items: result = self.build_admin_dict(i) users.append(result) return jsonify(User=users)
def getAdminByID(self, person_id): dao = AdminDAO() users = [] items = dao.getAdminByID(person_id) for i in items: result = self.build_admin_dict(i) users.append(result) return jsonify(User=users)
def getAllAdmins(self): dao = AdminDAO() users = [] items = dao.getAllAdmins() for i in items: result = self.build_admin_dict(i) users.append(result) return jsonify(User=users)
def getAdminByEmail(self, email): dao = AdminDAO() users = [] items = dao.getAdminByEmail(email) for i in items: result = self.build_admin_dict(i) users.append(result) return jsonify(User=users)
def getAllAdmins(self): dao = AdminDAO() admin_list = dao.getAllAdmins() if not admin_list: return jsonify(Error="Administrator Not Found"), 404 else: result_list = [] for row in admin_list: result = self.build_admin_dict(row) result_list.append(result) return jsonify(Administrators=result_list)
def getResourcesByAdminId(self, admin_id): dao = AdminDAO() admin1 = dao.getAdminById(admin_id) if not admin1: return jsonify(Error="Admin Not Found"), 404 resources_list = dao.getResourcesByAdminId(admin_id) result_list = [] for row in resources_list: result = self.build_resource_dict(row) result_list.append(result) return jsonify(ResourcesByAdminID=result_list)
def deleteAdmin(self, admin_id): dao_admin = AdminDAO() if not dao_admin.getAdminById(admin_id): return jsonify(Error="Admin not found."), 404 else: dao_user = UserDAO() dao_phone = UserPhoneDAO() user_id = dao_admin.delete(admin_id) dao_phone.delete(user_id) dao_user.delete(user_id) return jsonify(DeleteStatus="OK"), 200
def searchAdmins(self, args): admin_firstname = args.get("admin_firstname") admin_lastname = args.get("admin_lastname") admin_email = args.get('admin_email') admin_phone = args.get('admin_phone') admin_date_birth = args.get('admin_date_birth') dao = AdminDAO() admin_list = [] if (len(args) == 2) and admin_firstname and admin_lastname: admin_list = dao.getAdminsByFirstnameAndLastname( admin_firstname, admin_lastname) elif (len(args) == 1) and admin_firstname: admin_list = dao.getAdminsByFirstname(admin_firstname) elif (len(args) == 1) and admin_lastname: admin_list = dao.getAdminsByLastname(admin_lastname) elif (len(args) == 1) and admin_email: admin_list = dao.getAdminsByEmail(admin_email) elif (len(args) == 1) and admin_phone: admin_list = dao.getAdminsByPhone(admin_phone) elif (len(args) == 1) and admin_date_birth: admin_list = dao.getAdminsByDateOfBirth(admin_date_birth) else: return jsonify(Error="Malformed query string"), 400 result_list = [] for row in admin_list: result = self.build_admin_dict(row) result_list.append(result) return jsonify(Admins=result_list)
def getAllAdmins(self): dao = AdminDAO() dao1 = UserDAO() dao2 = ChatDAO() result = dao.getAllAdmins() mapped_result = [] for r in result: result2 = dao1.getUserById(r[0]) result3 = dao2.getChatById(r[1]) r[0] = result2[1] + " " + result2[2] r[1] = result3[1] mapped_result.append(self.mapToDict(r)) return jsonify(Admins=mapped_result)
def insert(self, item): pfname = item['person_firstname'] plname = item['person_lastname'] pdob = item['person_dob'] pcity = item['person_city'] pphone = item['person_phone_number'] pemail = item['person_email'] if pfname and plname and pdob and pcity and pphone and pemail: dao = AdminDAO() dao.insert(pfname, plname, pdob, pcity, pphone, pemail) return jsonify(admin=self.build_attribute_dict( pfname, plname, pdob, pcity, pphone, pemail)), 201 else: return jsonify(Error="Unexpected attributes in post request"), 400
def getChatsAdministratedByUser(self, user_id): dao = AdminDAO() dao1 = UserDAO() dao2 = ChatDAO() result = dao.getChatsAdministratedByUser(user_id) if result == None: return jsonify(Error="CHAT NOT FOUND") else: mapped_result = [] for r in result: result2 = dao1.getUserById(r[0]) result3 = dao2.getChatById(r[1]) r[0] = result2[1] + " " + result2[2] r[1] = result3[1] mapped_result.append(self.mapToDict(r)) return jsonify(Admins=mapped_result)
def getAdminByChatID(self, chat_id): dao = AdminDAO() dao1 = UserDAO() dao2 = ChatDAO() result = dao.getAdminsByChatID(chat_id) # print(result) if result == None: return jsonify(Error="ADMIN NOT FOUND") else: mapped_result = [] for r in result: result2 = dao1.getUserById(r[0]) result3 = dao2.getChatById(r[1]) r[0] = result2[1] + " " + result2[2] r[1] = result3[1] mapped_result.append(self.mapToDict(r)) return jsonify(Admins=mapped_result)
def insertAdmin(self, form): if form and len(form) == 2: permission_key = form['permission_key'] p_id = form['p_id'] if permission_key and p_id: dao = AdminDAO() admin_id = dao.insertAdmin(permission_key, p_id) result = {} result['admin_id'] = admin_id result['permission_key'] = permission_key result['p_id'] = p_id return jsonify(Admin=result), 201 else: return jsonify('Unexpected attributes in post request'), 401 else: return jsonify(Error="Malformed post request"), 400
def updateAdmin(self, admin_id, form): dao = AdminDAO() if not dao.getAdminById(admin_id): return jsonify(Error="Admin not found."), 404 else: if len(form) != 9: return jsonify(Error="Malformed update request"), 400 else: u_name = form['u_name'] u_lastname = form['u_lastname'] u_email = form['u_email'] u_password = form['u_password'] u_address = form['u_address'] u_city = form['u_city'] u_region = form['u_region'] u_phone = form['u_phone'] u_age = form['u_age'] if u_name and u_lastname and u_email and u_password and u_address and u_city and u_region and u_phone and u_age: dao = AdminDAO() dao.update(admin_id, u_name, u_lastname, u_email, u_password, u_address, u_city, u_region, u_phone, u_age) result = self.build_admin_attributes( admin_id, u_name, u_lastname, u_email, u_password, u_address, u_city, u_region, u_phone, u_age) return jsonify(Admin=result), 201 else: return jsonify( Error="Unexpected attributes in update request"), 400
def manageResource(self, admin_id, form): dao = AdminDAO() if not dao.getAdminById(admin_id): return jsonify(Error="Admin not found."), 404 else: if len(form) != 1: return jsonify(Error="Malformed update request"), 400 else: rid = form['r_id'] if rid: dao.manageResource(admin_id, rid) result = {} result['admin_id'] = admin_id result['r_id'] = rid return jsonify(Manage=result), 200 else: return jsonify( Error="Unexpected attributes in insert request"), 400
def updateAdmin(self, admin_id, form): dao = AdminDAO() admin = dao.getAdminById(admin_id) if not admin: return jsonify(Error="Admin Not Found"), 404 if len(form) != 2: return jsonify(Error="Malformed update request"), 400 else: permission_key = form['permission_key'] p_id = form['p_id'] if permission_key and p_id: dao.updateAdmin(admin_id, permission_key, p_id) result = {} result['admid_id'] = admin_id result['permission_key'] = permission_key result['p_id'] = p_id return jsonify(Admin=result), 200 else: return jsonify( Error="Unexpected attributes in update request"), 400
def insertAdmin(self, json): admin_firstname = json['admin_firstname'] admin_lastname = json['admin_lastname'] admin_date_birth = json['admin_date_birth'] admin_email = json['admin_email'] admin_phone = json['admin_phone'] if admin_firstname and admin_lastname and admin_date_birth and admin_email and admin_phone: dao_user = UserDAO() user_id = dao_user.insert(admin_firstname, admin_lastname, admin_date_birth, admin_email) dao_phone = UserPhoneDAO() admin_phone_id = dao_phone.insert(user_id, admin_phone) dao_admin = AdminDAO() admin_id = dao_admin.insert(user_id) result = self.build_admin_attributes(user_id, admin_id, admin_firstname, admin_lastname, admin_date_birth, admin_email, admin_phone_id, admin_phone) return jsonify(Admin=result), 201 else: return jsonify(Error="Unexpected attributes in post request"), 400