def get_all_persons(self): repository = PersonRepository() playload = Paginate().include_paginate_args_playload(request) persons = repository.get_all_persons(playload) status_result = SetStatusResponseHandler() return status_result.default(persons)
def get_by_params(self): contract = GetByParamsUserProfileSystemContract() playload = request.args if not(contract.validate(playload)): return ResultModel('Parametro incorreto.', False, contract.errors).to_dict(), 406 params_filter = {} _id = playload.get('id') user_id = playload.get('user_id') profile_system_id = playload.get('profile_system_id') system_id = playload.get('system_id') if _id: params_filter['id'] = int(_id) if user_id: params_filter['user_id'] = int(user_id) if profile_system_id: params_filter['profile_system_id'] = int(profile_system_id) if system_id: params_filter['system_id'] = int(system_id) repository = UserProfileSystemRepository() _filter = Paginate().include_paginate_args_playload(request) _filter['data'] = params_filter user_profile_system = repository.get_search_by_params(_filter) status_result = SetStatusResponseHandler() return status_result.default(user_profile_system)
def get_by_params(self): contract = GetByParamsProfilePermissionContract() playload = request.args if not (contract.validate(playload)): return ResultModel('Parametro incorreto.', False, contract.errors).to_dict(), 406 params_filter = {} profile_system_id = playload.get('profile_system_id') system_permission_id = playload.get('system_permission_id') _id = playload.get('id') if _id: params_filter['id'] = int(_id) if profile_system_id: params_filter['profile_system_id'] = int(profile_system_id) if system_permission_id: params_filter['system_permission_id'] = int(system_permission_id) params_filter = Paginate().include_paginate_args_playload( request, playload) repository = ProfilePermissionRepository() profile_permission = repository.get_search_by_params(params_filter) status_result = SetStatusResponseHandler() return status_result.default(profile_permission)
def get_all(self): repository = ProfilePermissionRepository() playload = Paginate().include_paginate_args_playload(request) profile_permission = repository.get_all(playload) status_result = SetStatusResponseHandler() return status_result.default(profile_permission)
def get_all_users(self): user = UserRepository() playload = Paginate().include_paginate_args_playload(request) users = user.get_all(playload) status_result = SetStatusResponseHandler() return status_result.default(users)
def get_all(self): repository = UserProfileSystemRepository() playload = Paginate().include_paginate_args_playload(request) profiles_systems = repository.get_all(playload) status_result = SetStatusResponseHandler() return status_result.default(profiles_systems)
def get_by_id(self, _id): contract = GetByIdProfileSystemAndDependenciesContract() if not (contract.validate(_id)): return ResultModel('Parametro incorreto.', False, contract.errors).to_dict(), 406 _id = int(_id) repo_prof_sys = ProfileSystemRepository() profile_system_db_result = repo_prof_sys.get_by_id(_id) if not profile_system_db_result['data']['result']['id']: return ResultModel('ID não encontrado.', False, contract.errors).to_dict(), 406 profile_system = profile_system_db_result['data']['result'] repo_prof_permi = ProfilePermissionRepository() _filter = dict(profile_system_id=_id) filter_dto = Paginate().include_paginate_args_playload( request, _filter) profile_permission = repo_prof_permi.get_search_by_params( filter_dto)['data']['result'] repo_user_prof_system = UserProfileSystemRepository() user_profile_system = repo_user_prof_system.get_search_by_params( filter_dto)['data']['result'] data = dict(profile_system=profile_system, profile_permission=profile_permission, user_profile_system=user_profile_system) result = ResultModel('Pesquisa realizada com sucesso.', data, False).to_dict() status_result = SetStatusResponseHandler() return status_result.default(data)
def create(self): contract = CreateUserProfileSystemContract() playload = request.json if not(contract.validate(playload)): return ResultModel('Problema nos parametros enviados.', False, contract.errors).to_dict(), 406 repository = UserProfileSystemRepository() user_profile_system = repository.create(playload) status_result = SetStatusResponseHandler() return status_result.default(user_profile_system)
def get_by_id(self, _id): contract = GetByIdUserContract() if not (contract.validate(_id)): return ResultModel('Envie todos parametros obrigatorios.', False, contract.errors).to_dict(), 406 repository = UserRepository() user = repository.get_by_id(_id) status_result = SetStatusResponseHandler() return status_result.default(user)
def delete_address(self): contract = DeleteAddressContract() playload = request.json if not(contract.validate(playload)): return ResultModel('Problema nos parametros enviados.', False, contract.errors).to_dict(), 406 repository = AddressRepository() address = repository.delete_address(playload) status_result = SetStatusResponseHandler() return status_result.default(address)
def get_by_id(self, playload): _id = playload.get('id') if _id: playload['id'] = int(_id) contract = GetByIdAddressContract() if not(contract.validate(playload)): return ResultModel('Problema nos parametros enviados.', False, contract.errors).to_dict(), 406 repository = AddressRepository() person = repository.get_by_id(playload) status_result = SetStatusResponseHandler() return status_result.default(person)
def delete_user(self): contract = DeleteUserContract() playload = request.json if not (contract.validate(playload)): return ResultModel('Envie todos parametros obrigatorios.', False, contract.errors).to_dict(), 406 repository = UserRepository() user = repository.delete(playload.get('id')) status_result = SetStatusResponseHandler() return status_result.default(user)
def create(self): contract = CreateSystemPermissionContract() playload = request.json if not (contract.validate(playload)): return ResultModel('Problema nos parametros enviados.', False, contract.errors).to_dict(), 406 repository = SystemPermissionRepository() system_permission = repository.create(playload) status_result = SetStatusResponseHandler() return status_result.default(system_permission)
def get_by_person_id(self, playload): contract = GetByIdAddressContract() _id = playload.get('id') if _id: playload['id'] = int(_id) if not(contract.validate(playload)): return ResultModel('Problema nos parametros enviados.', False, contract.errors).to_dict(), 406 repository = AddressRepository() playload = Paginate().include_paginate_args_playload(request, playload) address = repository.get_by_person_id(playload) status_result = SetStatusResponseHandler() return status_result.default(address)
def delete(self): contract = DeleteProfilePermissionContract() playload = request.json if not (contract.validate(playload)): return ResultModel('Problema nos parametros enviados.', False, contract.errors).to_dict(), 406 repository = ProfilePermissionRepository() profile_permission = repository.delete(playload.get('id')) status_result = SetStatusResponseHandler() return status_result.default(profile_permission)
def update_person(self): contract = UpdatePersonContract() playload = request.json if not (contract.validate(playload)): return ResultModel('Problema nos parametros enviados.', False, contract.errors).to_dict(), 406 playload = GenericHelper().captalize_full_dict(playload) repository = PersonRepository() person = repository.update_person(playload) status_result = SetStatusResponseHandler() return status_result.default(person)
def create_user(self): contract = CreateUserContract() playload = request.json if not (contract.validate(playload)): return ResultModel('Envie todos parametros obrigatorios.', False, contract.errors).to_dict(), 406 if playload.get('is_admin') and not Admin().is_admin(): return ResultModel( 'Só um administrador pode criar outro administrador.', False, contract.errors).to_dict(), 406 user = UserRepository() new_user = user.create(playload) status_result = SetStatusResponseHandler() return status_result.created(new_user)
def update_user(self): contract = UpdateUserContract() playload = request.json if not (contract.validate(playload)): return ResultModel('Envie todos parametros obrigatorios.', False, contract.errors).to_dict(), 406 if playload.get('is_admin') and not Admin().is_admin(): return ResultModel( 'Só um administrador pode editar outro administrador.', False, contract.errors).to_dict(), 406 repository = UserRepository() user = repository.update(playload.get('id'), playload.get('username'), playload.get('password'), playload.get('is_admin')) status_result = SetStatusResponseHandler() return status_result.default(user)
def create(self): contract = CreateProfilePermissionContract() playload = request.json if not (contract.validate(playload)): return ResultModel('Problema nos parametros enviados.', False, contract.errors).to_dict(), 406 repository = ProfilePermissionRepository() # data = [] # for system_permision_id in playload['system_permisions_ids']: # data.append(dict( # system_permision_id=system_permision_id, # profile_system_id=playload.get('profile_system_id') # )) profile_permission = repository.create(playload) status_result = SetStatusResponseHandler() return status_result.default(profile_permission)
def create_person(self): contract = CreatePersonContract() playload = request.json if not (contract.validate(playload)): return ResultModel('Problema nos parametros enviados.', False, contract.errors).to_dict(), 406 playload = GenericHelper().captalize_full_dict(playload) repository = PersonRepository() cpf = playload.get('cpf') cnpj = playload.get('cnpj') helper = PersonHelper() if cpf: playload['cpf'] = helper.remove_characters(cpf) if cnpj: playload['cnpj'] = helper.remove_characters(cnpj) person = repository.create_person(playload) status_result = SetStatusResponseHandler() return status_result.default(person)
def get_by_params(self): contract = GetByParamsSystemContract() playload = request.args if not (contract.validate(playload)): return ResultModel('Parametro incorreto.', False, contract.errors).to_dict(), 406 params_filter = {} _id = playload.get('id') name = playload.get('name') url = playload.get('url') if _id: params_filter['id'] = int(_id) if name: params_filter['name'] = name if url: params_filter['url'] = url repository = SystemRepository() systems = repository.get_search_by_params(params_filter) status_result = SetStatusResponseHandler() return status_result.default(systems)
def get_by_params(self): contract = GetByParamsPersonContract() playload = request.args if not (contract.validate(playload)): return ResultModel('Parametro incorreto.', False, contract.errors).to_dict(), 406 generic_helper = GenericHelper() params_filter = {} _id = playload.get('id') cnpj = playload.get('cnpj') cpf = playload.get('cpf') birth_date = playload.get('birth_date') gender = playload.get('gender') name = playload.get('name') _type = playload.get('type') if _id: params_filter['id'] = int(_id) if cnpj: params_filter['cnpj'] = cnpj if cpf: params_filter['cpf'] = cpf if birth_date: params_filter['birth_date'] = generic_helper.str_date_to_datetime( birth_date) if gender: params_filter['gender'] = gender if name: params_filter['name'] = name if _type: params_filter['type'] = _type params_filter = Paginate().include_paginate_args_playload( request, params_filter) repository = PersonRepository() systems = repository.get_search_by_params(params_filter) status_result = SetStatusResponseHandler() return status_result.default(systems)
def create(self): contract = CreateProfileSystemAndDependenciesContract() playload = request.json if not (contract.validate(playload)): return ResultModel('Problema nos parametros enviados.', False, contract.errors).to_dict(), 406 system_id = playload.get('system_id') repo_prof_sys = ProfileSystemRepository() profile_system_dto = dict( system_id=system_id, name=playload.get('name_profile_system'), description=playload.get('description_profile_system')) profile_system_db_result = repo_prof_sys.create(profile_system_dto) status_result = SetStatusResponseHandler() if (not profile_system_db_result['data']['result']): return status_result.default(profile_system_db_result) profile_system = profile_system_db_result['data']['result'] profile_system_id = profile_system.get('id') system_permisions_ids = playload.get('system_permisions_ids') dto_multiple_profile_permission = dict( profile_system_id=profile_system_id, system_permisions_ids=system_permisions_ids) repo_prof_permis = ProfilePermissionRepository() prof_permis_db_result = repo_prof_permis.create( dto_multiple_profile_permission) if (not prof_permis_db_result['data']['result']): return status_result.default(prof_permis_db_result) profile_permission = prof_permis_db_result['data']['result'] repo_user_prof_sys = UserProfileSystemRepository() users_ids = playload.get('users_ids') user_profile_system_dto = dict(users_ids=users_ids, profile_system_id=profile_system_id) user_prof_sys_db_result = repo_user_prof_sys.create_multiples( user_profile_system_dto) if (not user_prof_sys_db_result['data']['result']): return status_result.default(user_prof_sys_db_result) user_profile_system = user_prof_sys_db_result['data']['result'] data = dict(profile_system=profile_system, profile_permission=profile_permission, user_profile_system=user_profile_system) result = ResultModel( 'Sucesso na criação do perfil de sistema e suas dependencias.', data, False).to_dict() return status_result.created(result)
def get_all_address(self): repository = AddressRepository() paginate = Paginate().url_intercept_args(request) address = repository.get_all_address(paginate) status_result = SetStatusResponseHandler() return status_result.default(address)
def create_user_person_address(self, first_admin=False): helper = Helper() contract = CreateUserAndpersonAndAddressContract() playload = request.json if not (contract.validate(playload)): return ResultModel('Envie todos parametros obrigatorios.', False, contract.errors).to_dict(), 406 user_dto = playload.get('user') person_dto = helper.captalize_full_dict(playload.get('person')) address_dto = helper.captalize_full_dict(playload.get('address')) user_repository = UserRepository() person_repository = PersonRepository() address_repository = AddressRepository() status_result = SetStatusResponseHandler() user_exist = user_repository.get_by_username(user_dto.get('username')) if user_exist['message'] != 'Nome de usuario não encontrado.': if user_exist.get('exeption'): return user_exist, 500 elif user_exist['message'] == 'Pesquisa realizada com sucesso.': username = user_dto.get('username') return ResultModel(f'Usuario "{username}" já existe.', False, True).to_dict(), 406 return user_exist, 406 if user_dto.get( 'is_admin') and not Admin().is_admin() and not first_admin: return ResultModel( 'Só um administrador pode criar outro administrador.', False, contract.errors).to_dict(), 406 cpf = person_dto.get('cpf') cnpj = person_dto.get('cnpj') person_helper = PersonHelper() if cpf: person_dto['cpf'] = person_helper.remove_characters(cpf) exist_cpf = person_repository.get_by_cpf_or_cnpj( person_dto['type'], person_dto['cpf'])['data']['result'] if exist_cpf: return ResultModel(f'O CPF "{cpf}" já foi cadastrado.', False, True).to_dict(), 406 elif cnpj: person_dto['cnpj'] = person_helper.remove_characters(cnpj) exist_cnpj = person_repository.get_by_cpf_or_cnpj( person_dto['type'], person_dto['cnpj'])['data']['result'] if exist_cnpj: return ResultModel(f'O CNPJ "{cnpj}" já foi cadastrado.', False, True).to_dict(), 406 person = person_repository.create_person(person_dto) if not person['data']['result']: return status_result.default(person) person = person['data']['result'] address_dto['person_id'] = person.get('id') address = address_repository.create_address(address_dto) if not address['data']['result']: return status_result.default(address) address = address['data']['result'] user_repository.create(user_dto) user_dto['person_id'] = person['id'] user = user_repository.create(user_dto) if user['error']: return status_result.default(user) user = user['data']['result'] result = dict( user=user, person=person, address=address, ) return result, 201