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
예제 #2
0
    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
예제 #3
0
 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
예제 #4
0
 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
예제 #5
0
 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)
예제 #6
0
 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)
예제 #7
0
 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 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 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