From d3207d319c26f9852ae1b050409ec612e12bfbd6 Mon Sep 17 00:00:00 2001 From: vanderleik Date: Sun, 7 Apr 2024 11:59:27 -0300 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20VIN-397=20-=20refatorando=20exce?= =?UTF-8?q?=C3=A7=C3=B5es=20do=20CADASTRO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exceptions/BadRequestException.java | 12 ------- .../services/impl/AddressServiceImpl.java | 15 ++++---- .../services/impl/CountryServiceImpl.java | 16 +++++---- .../services/impl/PersonServiceImpl.java | 35 +++++++++---------- .../services/impl/StateServiceImpl.java | 19 +++++----- .../services/impl/UserServiceImpl.java | 15 ++++---- .../AddressExceptionHandler.java | 18 ++++++++++ .../CountryExceptionHandler.java | 25 +++++++++++++ .../GeneralExceptionHandler.java | 17 +++++++++ .../configuration/PersonExceptionHandler.java | 24 +++++++++++++ .../configuration/StateExceptionHandler.java | 24 +++++++++++++ .../configuration/UserExceptionHandler.java | 24 +++++++++++++ .../exceptions/AddressNotFoundException.java | 9 +++++ .../exceptions/BadRequestException.java | 9 +++++ .../CountryAlreadyExistsException.java | 8 +++++ .../exceptions/CountryNotFoundException.java | 8 +++++ .../PersonAlreadyExistsException.java | 9 +++++ .../exceptions/PersonNotFoundException.java | 9 +++++ .../StateAlreadyExistsException.java | 9 +++++ .../exceptions/StateNotFoundException.java | 8 +++++ .../UserAlreadyExistsException.java | 9 +++++ .../exceptions/UserNotFoundException.java | 9 +++++ .../ControllerExceptionHandler.java | 33 ----------------- .../controllers/exceptions/ErrorObject.java | 15 -------- .../controllers/exceptions/ErrorResponse.java | 18 ---------- .../dtos/general/ErrorResponseDTO.java | 4 +++ .../services/impl/CountryServiceImplTest.java | 2 +- .../services/impl/StateServiceImplTest.java | 2 +- .../services/impl/UserServiceImplTest.java | 15 +++----- .../controllers/AddressControllerTest.java | 11 +----- .../controllers/CountryControllerTest.java | 2 +- .../controllers/PersonControllerTest.java | 2 +- .../controllers/StateControllerTest.java | 2 +- .../controllers/UserControllerTest.java | 6 ++-- 34 files changed, 290 insertions(+), 153 deletions(-) delete mode 100644 cadastro/src/main/java/com/vinhonotas/cadastro/application/services/exceptions/BadRequestException.java create mode 100644 cadastro/src/main/java/com/vinhonotas/cadastro/configuration/AddressExceptionHandler.java create mode 100644 cadastro/src/main/java/com/vinhonotas/cadastro/configuration/CountryExceptionHandler.java create mode 100644 cadastro/src/main/java/com/vinhonotas/cadastro/configuration/GeneralExceptionHandler.java create mode 100644 cadastro/src/main/java/com/vinhonotas/cadastro/configuration/PersonExceptionHandler.java create mode 100644 cadastro/src/main/java/com/vinhonotas/cadastro/configuration/StateExceptionHandler.java create mode 100644 cadastro/src/main/java/com/vinhonotas/cadastro/configuration/UserExceptionHandler.java create mode 100644 cadastro/src/main/java/com/vinhonotas/cadastro/domain/entities/exceptions/AddressNotFoundException.java create mode 100644 cadastro/src/main/java/com/vinhonotas/cadastro/domain/entities/exceptions/BadRequestException.java create mode 100644 cadastro/src/main/java/com/vinhonotas/cadastro/domain/entities/exceptions/CountryAlreadyExistsException.java create mode 100644 cadastro/src/main/java/com/vinhonotas/cadastro/domain/entities/exceptions/CountryNotFoundException.java create mode 100644 cadastro/src/main/java/com/vinhonotas/cadastro/domain/entities/exceptions/PersonAlreadyExistsException.java create mode 100644 cadastro/src/main/java/com/vinhonotas/cadastro/domain/entities/exceptions/PersonNotFoundException.java create mode 100644 cadastro/src/main/java/com/vinhonotas/cadastro/domain/entities/exceptions/StateAlreadyExistsException.java create mode 100644 cadastro/src/main/java/com/vinhonotas/cadastro/domain/entities/exceptions/StateNotFoundException.java create mode 100644 cadastro/src/main/java/com/vinhonotas/cadastro/domain/entities/exceptions/UserAlreadyExistsException.java create mode 100644 cadastro/src/main/java/com/vinhonotas/cadastro/domain/entities/exceptions/UserNotFoundException.java delete mode 100644 cadastro/src/main/java/com/vinhonotas/cadastro/interfaces/controllers/exceptions/ControllerExceptionHandler.java delete mode 100644 cadastro/src/main/java/com/vinhonotas/cadastro/interfaces/controllers/exceptions/ErrorObject.java delete mode 100644 cadastro/src/main/java/com/vinhonotas/cadastro/interfaces/controllers/exceptions/ErrorResponse.java create mode 100644 cadastro/src/main/java/com/vinhonotas/cadastro/interfaces/dtos/general/ErrorResponseDTO.java diff --git a/cadastro/src/main/java/com/vinhonotas/cadastro/application/services/exceptions/BadRequestException.java b/cadastro/src/main/java/com/vinhonotas/cadastro/application/services/exceptions/BadRequestException.java deleted file mode 100644 index bd4dcdd2..00000000 --- a/cadastro/src/main/java/com/vinhonotas/cadastro/application/services/exceptions/BadRequestException.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.vinhonotas.cadastro.application.services.exceptions; - -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.ResponseStatus; - -@ResponseStatus(HttpStatus.BAD_REQUEST) -public class BadRequestException extends RuntimeException { - - public BadRequestException(String message) { - super(message); - } -} diff --git a/cadastro/src/main/java/com/vinhonotas/cadastro/application/services/impl/AddressServiceImpl.java b/cadastro/src/main/java/com/vinhonotas/cadastro/application/services/impl/AddressServiceImpl.java index 3055753d..0ce83f73 100644 --- a/cadastro/src/main/java/com/vinhonotas/cadastro/application/services/impl/AddressServiceImpl.java +++ b/cadastro/src/main/java/com/vinhonotas/cadastro/application/services/impl/AddressServiceImpl.java @@ -1,13 +1,12 @@ package com.vinhonotas.cadastro.application.services.impl; import com.vinhonotas.cadastro.application.converters.AddressConverter; -import com.vinhonotas.cadastro.application.converters.CountryConverter; -import com.vinhonotas.cadastro.application.converters.StateConverter; import com.vinhonotas.cadastro.application.services.AddressService; -import com.vinhonotas.cadastro.application.services.exceptions.BadRequestException; import com.vinhonotas.cadastro.domain.entities.AddressEntity; import com.vinhonotas.cadastro.domain.entities.CountryEntity; import com.vinhonotas.cadastro.domain.entities.StateEntity; +import com.vinhonotas.cadastro.domain.entities.exceptions.AddressNotFoundException; +import com.vinhonotas.cadastro.domain.entities.exceptions.BadRequestException; import com.vinhonotas.cadastro.infrastructure.AddressRepository; import com.vinhonotas.cadastro.infrastructure.CountryRepository; import com.vinhonotas.cadastro.infrastructure.StateRepository; @@ -28,8 +27,6 @@ public class AddressServiceImpl implements AddressService { private final AddressConverter addressConverter; - private final StateConverter stateConverter; - private final CountryConverter countryConverter; private final AddressRepository addressRepository; private final StateRepository stateRepository; private final CountryRepository countryRepository; @@ -45,7 +42,7 @@ public AddressEntity create(AddressInputDTO addressInputDTO) { AddressEntity addressEntity = addressConverter.convertToEntity(addressInputDTO); addressEntity.setUf(state); addressEntity.setCountry(country); - log.info("Endereço a ser salvo: {}", addressEntity.toString()); + log.info("Endereço a ser salvo: {}", addressEntity); return addressRepository.save(addressEntity); } catch (Exception e) { @@ -74,7 +71,7 @@ public List getAll() { List addressList = addressRepository.findAll(); if (addressList.isEmpty()) { log.error("getAll :: Ocorreu um erro ao buscar os endereços: {}", MessagesConstants.ADDRESS_NOT_FOUND); - throw new BadRequestException(MessagesConstants.ADDRESS_NOT_FOUND); + throw new AddressNotFoundException(MessagesConstants.ADDRESS_NOT_FOUND); } return addressList; } @@ -83,7 +80,7 @@ public List getAll() { public AddressEntity getById(UUID id) { log.info("getById :: Buscando endereço pelo id: {}", id.toString()); return addressRepository.findById(id) - .orElseThrow(() -> new BadRequestException(MessagesConstants.ADDRESS_NOT_FOUND)); + .orElseThrow(() -> new AddressNotFoundException(MessagesConstants.ADDRESS_NOT_FOUND)); } @Override @@ -114,7 +111,7 @@ public void delete(UUID id) { log.info("Endereço encontrado: {}", address.toString()); if (address.isEmpty()) { log.error("delete :: Ocorreu um erro ao deletar o endereço: {}", MessagesConstants.ADDRESS_NOT_FOUND); - throw new BadRequestException(MessagesConstants.ADDRESS_NOT_FOUND); + throw new AddressNotFoundException(MessagesConstants.ADDRESS_NOT_FOUND); } try { addressRepository.deleteById(id); diff --git a/cadastro/src/main/java/com/vinhonotas/cadastro/application/services/impl/CountryServiceImpl.java b/cadastro/src/main/java/com/vinhonotas/cadastro/application/services/impl/CountryServiceImpl.java index c2f09aa7..d15cd1b1 100644 --- a/cadastro/src/main/java/com/vinhonotas/cadastro/application/services/impl/CountryServiceImpl.java +++ b/cadastro/src/main/java/com/vinhonotas/cadastro/application/services/impl/CountryServiceImpl.java @@ -2,8 +2,10 @@ import com.vinhonotas.cadastro.application.converters.CountryConverter; import com.vinhonotas.cadastro.application.services.CountryService; -import com.vinhonotas.cadastro.application.services.exceptions.BadRequestException; import com.vinhonotas.cadastro.domain.entities.CountryEntity; +import com.vinhonotas.cadastro.domain.entities.exceptions.BadRequestException; +import com.vinhonotas.cadastro.domain.entities.exceptions.CountryAlreadyExistsException; +import com.vinhonotas.cadastro.domain.entities.exceptions.CountryNotFoundException; import com.vinhonotas.cadastro.infrastructure.CountryRepository; import com.vinhonotas.cadastro.interfaces.dtos.inputs.CountryInputDTO; import com.vinhonotas.cadastro.utils.MessagesConstants; @@ -32,7 +34,7 @@ public CountryEntity create(CountryInputDTO countryInputDTO) { CountryEntity entity = countryRepository.findByCountryName(countryInputDTO.getCountryName()); if (Objects.nonNull(entity)) { log.error("create :: Ocorreu um erro: {}", MessagesConstants.COUNTRY_ALREADY_EXISTS); - throw new BadRequestException(MessagesConstants.COUNTRY_ALREADY_EXISTS); + throw new CountryAlreadyExistsException(MessagesConstants.COUNTRY_ALREADY_EXISTS); } try { CountryEntity countryEntity = countryConverter.convertToEntity(countryInputDTO); @@ -49,7 +51,7 @@ public List getAll() { List entityList = countryRepository.findAll(); if (entityList.isEmpty()) { log.error("getAll :: Ocorreu um erro ao buscar os países: {}", MessagesConstants.COUNTRIES_NOT_FOUND); - throw new BadRequestException(MessagesConstants.COUNTRIES_NOT_FOUND); + throw new CountryNotFoundException(MessagesConstants.COUNTRIES_NOT_FOUND); } return entityList; } @@ -58,7 +60,7 @@ public List getAll() { public CountryEntity getById(UUID id) { log.info("getById :: Buscando país pelo id: {}", id.toString()); return countryRepository.findById(id) - .orElseThrow(() -> new BadRequestException(MessagesConstants.COUNTRY_NOT_FOUND)); + .orElseThrow(() -> new CountryNotFoundException(MessagesConstants.COUNTRY_NOT_FOUND)); } @Override @@ -67,7 +69,7 @@ public CountryEntity getByName(String name) { CountryEntity country = countryRepository.findByCountryName(name); if (Objects.isNull(country)) { log.error("getByName :: Ocorreu um erro: {}", MessagesConstants.COUNTRY_NOT_FOUND_WITH_NAME + name); - throw new BadRequestException(MessagesConstants.COUNTRY_NOT_FOUND_WITH_NAME + name); + throw new CountryNotFoundException(MessagesConstants.COUNTRY_NOT_FOUND_WITH_NAME + name); } return country; } @@ -78,7 +80,7 @@ public List getByContinent(String continent) { List entityList = countryRepository.findByContinentName(continent); if (Objects.isNull(entityList) || entityList.isEmpty()) { log.error("getByContinent :: Ocorreu um erro ao buscar os países: {}", MessagesConstants.COUNTRY_NOT_FOUND_WITH_CONTINENT + continent); - throw new BadRequestException(MessagesConstants.COUNTRY_NOT_FOUND_WITH_CONTINENT + continent); + throw new CountryNotFoundException(MessagesConstants.COUNTRY_NOT_FOUND_WITH_CONTINENT + continent); } return entityList; } @@ -104,7 +106,7 @@ public void delete(UUID id) { Optional entity = countryRepository.findById(id); if (entity.isEmpty()) { log.error("delete :: Ocorreu um erro: {}", MessagesConstants.COUNTRY_NOT_FOUND); - throw new BadRequestException(MessagesConstants.COUNTRY_NOT_FOUND); + throw new CountryNotFoundException(MessagesConstants.COUNTRY_NOT_FOUND); } try { countryRepository.deleteById(id); diff --git a/cadastro/src/main/java/com/vinhonotas/cadastro/application/services/impl/PersonServiceImpl.java b/cadastro/src/main/java/com/vinhonotas/cadastro/application/services/impl/PersonServiceImpl.java index 3dc753b0..a43a732c 100644 --- a/cadastro/src/main/java/com/vinhonotas/cadastro/application/services/impl/PersonServiceImpl.java +++ b/cadastro/src/main/java/com/vinhonotas/cadastro/application/services/impl/PersonServiceImpl.java @@ -1,10 +1,9 @@ package com.vinhonotas.cadastro.application.services.impl; -import com.vinhonotas.cadastro.application.converters.CountryConverter; import com.vinhonotas.cadastro.application.converters.PersonConverter; import com.vinhonotas.cadastro.application.services.PersonService; -import com.vinhonotas.cadastro.application.services.exceptions.BadRequestException; import com.vinhonotas.cadastro.domain.entities.*; +import com.vinhonotas.cadastro.domain.entities.exceptions.*; import com.vinhonotas.cadastro.infrastructure.PersonRepository; import com.vinhonotas.cadastro.interfaces.dtos.inputs.PersonInputDTO; import com.vinhonotas.cadastro.utils.MessagesConstants; @@ -28,7 +27,6 @@ public class PersonServiceImpl implements PersonService { private final PersonConverter personConverter; private final StateServiceImpl stateService; private final CountryServiceImpl countryService; - private final CountryConverter countryConverter; private final UserServiceImpl userService; @Override @@ -51,9 +49,10 @@ public PersonEntity create(PersonInputDTO personInputDTO) { private void existsCountryByCountryName(PersonInputDTO personInputDTO) { CountryEntity country = countryService.getByName(personInputDTO.getAddress().getCountry()); if (Objects.isNull(country)) { - throw new BadRequestException(MessagesConstants.COUNTRY_NOT_FOUND_WITH_NAME + personInputDTO.getAddress().getCountry()); + throw new CountryNotFoundException(MessagesConstants.COUNTRY_NOT_FOUND_WITH_NAME + + personInputDTO.getAddress().getCountry()); } - log.info("Salvando um país com os dados: {}", country.toString()); + log.info("Salvando um país com os dados: {}", country); personInputDTO.getAddress().setCountry(country.getCountryName()); } @@ -61,9 +60,9 @@ private void existsStateByUf(PersonInputDTO personInputDTO) { StateEntity state = stateService.getByUf(personInputDTO.getAddress().getUf()); if (Objects.isNull(state)) { log.error("create :: Ocorreu um erro: {}", MessagesConstants.STATE_NOT_FOUND); - throw new BadRequestException(MessagesConstants.STATE_NOT_FOUND); + throw new StateNotFoundException(MessagesConstants.STATE_NOT_FOUND); } else { - log.info("Salvando um estado com os dados: {}", state.toString()); + log.info("Salvando um estado com os dados: {}", state); personInputDTO.getAddress().setUf(state.getUf()); } } @@ -71,8 +70,8 @@ private void existsStateByUf(PersonInputDTO personInputDTO) { private void existsPersonByDocument(PersonInputDTO personInputDTO) { PersonEntity person = personRepository.findByDocument(personInputDTO.getDocument()); if (Objects.nonNull(person)) { - log.error("create :: Ocorreu um erro: {}", MessagesConstants.PERSON_ALREADY_EXISTS + person.toString()); - throw new BadRequestException(MessagesConstants.PERSON_ALREADY_EXISTS); + log.error("create :: Ocorreu um erro: {}", MessagesConstants.PERSON_ALREADY_EXISTS + person); + throw new PersonAlreadyExistsException(MessagesConstants.PERSON_ALREADY_EXISTS); } } @@ -82,7 +81,7 @@ public List getAll() { List personList = personRepository.findAll(); if (personList.isEmpty()) { log.error("getAll :: Ocorreu um erro ao buscar as pessoas: {}", MessagesConstants.PERSONS_NOT_FOUND); - throw new BadRequestException(MessagesConstants.PERSONS_NOT_FOUND); + throw new PersonNotFoundException(MessagesConstants.PERSONS_NOT_FOUND); } return personList; } @@ -91,7 +90,7 @@ public List getAll() { public PersonEntity getById(UUID id) { log.info("getById :: Buscando pessoa pelo id: {}", id.toString()); return personRepository.findById(id) - .orElseThrow(() -> new BadRequestException(MessagesConstants.PERSON_NOT_FOUND)); + .orElseThrow(() -> new PersonNotFoundException(MessagesConstants.PERSON_NOT_FOUND)); } @Override @@ -100,7 +99,7 @@ public PersonEntity getByName(String name) { PersonEntity person = personRepository.findByName(name); if (Objects.isNull(person)) { log.error("getByName :: Ocorreu um erro: {}", MessagesConstants.PERSON_NOT_FOUND_WITH_NAME + name); - throw new BadRequestException(MessagesConstants.PERSON_NOT_FOUND_WITH_NAME + name); + throw new PersonNotFoundException(MessagesConstants.PERSON_NOT_FOUND_WITH_NAME + name); } return person; } @@ -116,7 +115,7 @@ public PersonEntity update(UUID id, PersonInputDTO personInputDTO) { updateAuditingInfo(existingPerson); PersonEntity updatedPerson = personRepository.save(existingPerson); - log.info("Pessoa atualizada com sucesso: {}", updatedPerson.toString()); + log.info("Pessoa atualizada com sucesso: {}", updatedPerson); return updatedPerson; } catch (Exception e) { @@ -142,13 +141,14 @@ private void updatePersonAddress(PersonInputDTO personInputDTO, PersonEntity exi StateEntity state = stateService.getByUf(personInputDTO.getAddress().getUf()); if (state == null) { - throw new BadRequestException(MessagesConstants.STATE_NOT_FOUND); + throw new StateNotFoundException(MessagesConstants.STATE_NOT_FOUND); } address.setUf(state); CountryEntity country = countryService.getByName(personInputDTO.getAddress().getCountry()); if (country == null) { - throw new BadRequestException(MessagesConstants.COUNTRY_NOT_FOUND_WITH_NAME + personInputDTO.getAddress().getCountry()); + throw new CountryNotFoundException(MessagesConstants.COUNTRY_NOT_FOUND_WITH_NAME + + personInputDTO.getAddress().getCountry()); } address.setCountry(country); } @@ -159,7 +159,6 @@ private static void updatePersonData(PersonInputDTO personInputDTO, PersonEntity existingPerson.setBirthDate(personInputDTO.getBirthDate()); } - @Override @Transactional(rollbackFor = Exception.class) public void delete(UUID id) { @@ -167,13 +166,13 @@ public void delete(UUID id) { Optional person = personRepository.findById(id); if (person.isEmpty()) { log.error("delete :: Ocorreu um erro: {}", MessagesConstants.PERSON_NOT_FOUND); - throw new BadRequestException(MessagesConstants.PERSON_NOT_FOUND); + throw new PersonNotFoundException(MessagesConstants.PERSON_NOT_FOUND); } log.info("Buscando um usuário com o personId: {}", person.get().getId()); UserEntity user = userService.getByPersonId(person.get().getId()); if (Objects.nonNull(user)) { - log.info("Deletando a seguinte pessoa: {}", person.toString()); + log.info("Deletando a seguinte pessoa: {}", person); userService.delete(user.getId()); } diff --git a/cadastro/src/main/java/com/vinhonotas/cadastro/application/services/impl/StateServiceImpl.java b/cadastro/src/main/java/com/vinhonotas/cadastro/application/services/impl/StateServiceImpl.java index 47256511..69f88f77 100644 --- a/cadastro/src/main/java/com/vinhonotas/cadastro/application/services/impl/StateServiceImpl.java +++ b/cadastro/src/main/java/com/vinhonotas/cadastro/application/services/impl/StateServiceImpl.java @@ -3,9 +3,12 @@ import com.vinhonotas.cadastro.application.converters.CountryConverter; import com.vinhonotas.cadastro.application.converters.StateConverter; import com.vinhonotas.cadastro.application.services.StateService; -import com.vinhonotas.cadastro.application.services.exceptions.BadRequestException; import com.vinhonotas.cadastro.domain.entities.CountryEntity; import com.vinhonotas.cadastro.domain.entities.StateEntity; +import com.vinhonotas.cadastro.domain.entities.exceptions.BadRequestException; +import com.vinhonotas.cadastro.domain.entities.exceptions.CountryNotFoundException; +import com.vinhonotas.cadastro.domain.entities.exceptions.StateAlreadyExistsException; +import com.vinhonotas.cadastro.domain.entities.exceptions.StateNotFoundException; import com.vinhonotas.cadastro.infrastructure.CountryRepository; import com.vinhonotas.cadastro.infrastructure.StateRepository; import com.vinhonotas.cadastro.interfaces.dtos.inputs.StateInputDTO; @@ -51,7 +54,7 @@ private void existsCountryByName(StateInputDTO stateInputDTO) { stateInputDTO.setCountry(countryConverter.convertToInputDTO(country)); } else { log.error("create :: Ocorreu um erro: {}", MessagesConstants.COUNTRY_NOT_FOUND_WITH_NAME + stateInputDTO.getCountry().getCountryName()); - throw new BadRequestException(MessagesConstants.COUNTRY_NOT_FOUND_WITH_NAME + stateInputDTO.getCountry().getCountryName()); + throw new CountryNotFoundException(MessagesConstants.COUNTRY_NOT_FOUND_WITH_NAME + stateInputDTO.getCountry().getCountryName()); } } @@ -59,7 +62,7 @@ private void existsStateByName(StateInputDTO stateInputDTO) { StateEntity state = stateRepository.findByStateName(stateInputDTO.getStateName()); if (Objects.nonNull(state)) { log.error("create :: Ocorreu um erro: {}", MessagesConstants.STATE_ALREADY_EXISTS); - throw new BadRequestException(MessagesConstants.STATE_ALREADY_EXISTS); + throw new StateAlreadyExistsException(MessagesConstants.STATE_ALREADY_EXISTS); } } @@ -69,7 +72,7 @@ public List getAll() { List entityList = stateRepository.findAll(); if (entityList.isEmpty()) { log.error("getAll :: Ocorreu um erro ao buscar os estados: {}", MessagesConstants.STATES_NOT_FOUND); - throw new BadRequestException(MessagesConstants.STATES_NOT_FOUND); + throw new StateNotFoundException(MessagesConstants.STATES_NOT_FOUND); } return entityList; } @@ -78,7 +81,7 @@ public List getAll() { public StateEntity getById(UUID id) { log.info("getById :: Buscando estado pelo id: {}", id.toString()); return stateRepository.findById(id) - .orElseThrow(() -> new BadRequestException(MessagesConstants.STATE_NOT_FOUND)); + .orElseThrow(() -> new StateNotFoundException(MessagesConstants.STATE_NOT_FOUND)); } @Override @@ -87,7 +90,7 @@ public StateEntity getByName(String name) { StateEntity state = stateRepository.findByStateName(name); if (Objects.isNull(state)) { log.error("getByName :: Ocorreu um erro ao buscar o estado: {}", MessagesConstants.STATE_NOT_FOUND_WITH_NAME + name); - throw new BadRequestException(MessagesConstants.STATE_NOT_FOUND_WITH_NAME + name); + throw new StateNotFoundException(MessagesConstants.STATE_NOT_FOUND_WITH_NAME + name); } return state; } @@ -98,7 +101,7 @@ public StateEntity getByUf(String uf) { StateEntity state = stateRepository.findByUf(uf); if (Objects.isNull(state)) { log.error("getByUf :: Ocorreu um erro ao buscar o estado: {}", MessagesConstants.STATE_NOT_FOUND_WITH_UF + uf); - throw new BadRequestException(MessagesConstants.STATE_NOT_FOUND_WITH_UF + uf); + throw new StateNotFoundException(MessagesConstants.STATE_NOT_FOUND_WITH_UF + uf); } return state; } @@ -124,7 +127,7 @@ public void delete(UUID id) { Optional entity = stateRepository.findById(id); if (entity.isEmpty()) { log.error("delete :: Ocorreu um erro ao deletar o estado: {}", MessagesConstants.STATE_NOT_FOUND); - throw new BadRequestException(MessagesConstants.STATE_NOT_FOUND); + throw new StateNotFoundException(MessagesConstants.STATE_NOT_FOUND); } try { stateRepository.deleteById(id); diff --git a/cadastro/src/main/java/com/vinhonotas/cadastro/application/services/impl/UserServiceImpl.java b/cadastro/src/main/java/com/vinhonotas/cadastro/application/services/impl/UserServiceImpl.java index 18f3ae0e..78e6861b 100644 --- a/cadastro/src/main/java/com/vinhonotas/cadastro/application/services/impl/UserServiceImpl.java +++ b/cadastro/src/main/java/com/vinhonotas/cadastro/application/services/impl/UserServiceImpl.java @@ -2,9 +2,11 @@ import com.vinhonotas.cadastro.application.converters.UserConverter; import com.vinhonotas.cadastro.application.services.UserService; -import com.vinhonotas.cadastro.application.services.exceptions.BadRequestException; import com.vinhonotas.cadastro.domain.entities.PersonEntity; import com.vinhonotas.cadastro.domain.entities.UserEntity; +import com.vinhonotas.cadastro.domain.entities.exceptions.BadRequestException; +import com.vinhonotas.cadastro.domain.entities.exceptions.UserAlreadyExistsException; +import com.vinhonotas.cadastro.domain.entities.exceptions.UserNotFoundException; import com.vinhonotas.cadastro.infrastructure.PersonRepository; import com.vinhonotas.cadastro.infrastructure.UserRepository; import com.vinhonotas.cadastro.interfaces.dtos.inputs.UserInputDTO; @@ -27,6 +29,7 @@ public class UserServiceImpl implements UserService { private final UserRepository userRepository; private final UserConverter userConverter; private final PersonRepository personRepository; + @Override @Transactional(rollbackFor = Exception.class) public UserEntity create(UserInputDTO userInputDTO) { @@ -49,7 +52,7 @@ private void existsUser(UserInputDTO userInputDTO) { if (Objects.nonNull(user)) { log.error("existsUser :: Já existe um usuário com os dados: {}", user); - throw new BadRequestException(MessagesConstants.USER_ALREADY_EXISTS); + throw new UserAlreadyExistsException(MessagesConstants.USER_ALREADY_EXISTS); } } @@ -59,7 +62,7 @@ public List getAll() { List userList = userRepository.findAll(); if (userList.isEmpty()) { log.error("getAll :: Ocorreu um erro ao buscar os usuários: {}", MessagesConstants.USERS_NOT_FOUND); - throw new BadRequestException(MessagesConstants.USERS_NOT_FOUND); + throw new UserNotFoundException(MessagesConstants.USERS_NOT_FOUND); } return userList; } @@ -68,7 +71,7 @@ public List getAll() { public UserEntity getById(UUID id) { log.info("getById :: Buscando usuário pelo id: {}", id.toString()); return userRepository.findById(id) - .orElseThrow(() -> new BadRequestException(MessagesConstants.USER_NOT_FOUND)); + .orElseThrow(() -> new UserNotFoundException(MessagesConstants.USER_NOT_FOUND)); } @Override @@ -77,7 +80,7 @@ public UserEntity getByName(String name) { UserEntity user = userRepository.findByPersonName(name); if (Objects.isNull(user)) { log.error("getByName :: Ocorreu um erro ao buscar o usuário: {}", MessagesConstants.USER_NOT_FOUND_WITH_NAME + name); - throw new BadRequestException(MessagesConstants.USER_NOT_FOUND_WITH_NAME + name); + throw new UserNotFoundException(MessagesConstants.USER_NOT_FOUND_WITH_NAME + name); } return user; } @@ -103,7 +106,7 @@ public void delete(UUID id) { Optional user = userRepository.findById(id); if (user.isEmpty()) { log.error("delete :: Ocorreu um erro ao deletar o usuário: {}", MessagesConstants.USER_NOT_FOUND); - throw new BadRequestException(MessagesConstants.USER_NOT_FOUND); + throw new UserNotFoundException(MessagesConstants.USER_NOT_FOUND); } try { log.info("Deletando usuário com os seguintes dados: {}", user.toString()); diff --git a/cadastro/src/main/java/com/vinhonotas/cadastro/configuration/AddressExceptionHandler.java b/cadastro/src/main/java/com/vinhonotas/cadastro/configuration/AddressExceptionHandler.java new file mode 100644 index 00000000..38d3601c --- /dev/null +++ b/cadastro/src/main/java/com/vinhonotas/cadastro/configuration/AddressExceptionHandler.java @@ -0,0 +1,18 @@ +package com.vinhonotas.cadastro.configuration; + +import com.vinhonotas.cadastro.domain.entities.exceptions.AddressNotFoundException; +import com.vinhonotas.cadastro.interfaces.dtos.general.ErrorResponseDTO; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; + +@ControllerAdvice +public class AddressExceptionHandler { + + @ExceptionHandler(AddressNotFoundException.class) + public ResponseEntity handleAddressNotFoundException(AddressNotFoundException exception) { + return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new ErrorResponseDTO(exception.getMessage())); + } + +} diff --git a/cadastro/src/main/java/com/vinhonotas/cadastro/configuration/CountryExceptionHandler.java b/cadastro/src/main/java/com/vinhonotas/cadastro/configuration/CountryExceptionHandler.java new file mode 100644 index 00000000..6e2849c4 --- /dev/null +++ b/cadastro/src/main/java/com/vinhonotas/cadastro/configuration/CountryExceptionHandler.java @@ -0,0 +1,25 @@ +package com.vinhonotas.cadastro.configuration; + +import com.vinhonotas.cadastro.domain.entities.exceptions.CountryAlreadyExistsException; +import com.vinhonotas.cadastro.domain.entities.exceptions.CountryNotFoundException; +import com.vinhonotas.cadastro.interfaces.dtos.general.ErrorResponseDTO; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; + +@ControllerAdvice +public class CountryExceptionHandler { + + @ExceptionHandler(CountryNotFoundException.class) + public ResponseEntity handleCountryNotFoundException(CountryNotFoundException exception) { + return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new ErrorResponseDTO(exception.getMessage())); + } + + @ExceptionHandler(CountryAlreadyExistsException.class) + public ResponseEntity handleCountryAlreadyExistsException(CountryAlreadyExistsException exception) { + return ResponseEntity.status(HttpStatus.CONFLICT).body(new ErrorResponseDTO(exception.getMessage())); + } + + +} diff --git a/cadastro/src/main/java/com/vinhonotas/cadastro/configuration/GeneralExceptionHandler.java b/cadastro/src/main/java/com/vinhonotas/cadastro/configuration/GeneralExceptionHandler.java new file mode 100644 index 00000000..f13fe494 --- /dev/null +++ b/cadastro/src/main/java/com/vinhonotas/cadastro/configuration/GeneralExceptionHandler.java @@ -0,0 +1,17 @@ +package com.vinhonotas.cadastro.configuration; + +import com.vinhonotas.cadastro.domain.entities.exceptions.BadRequestException; +import com.vinhonotas.cadastro.interfaces.dtos.general.ErrorResponseDTO; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; + +@ControllerAdvice +public class GeneralExceptionHandler { + + @ExceptionHandler(BadRequestException.class) + public ResponseEntity handleBadRequestException(BadRequestException exception) { + return ResponseEntity.badRequest().body(new ErrorResponseDTO(exception.getMessage())); + } + +} diff --git a/cadastro/src/main/java/com/vinhonotas/cadastro/configuration/PersonExceptionHandler.java b/cadastro/src/main/java/com/vinhonotas/cadastro/configuration/PersonExceptionHandler.java new file mode 100644 index 00000000..d58278da --- /dev/null +++ b/cadastro/src/main/java/com/vinhonotas/cadastro/configuration/PersonExceptionHandler.java @@ -0,0 +1,24 @@ +package com.vinhonotas.cadastro.configuration; + +import com.vinhonotas.cadastro.domain.entities.exceptions.PersonAlreadyExistsException; +import com.vinhonotas.cadastro.domain.entities.exceptions.PersonNotFoundException; +import com.vinhonotas.cadastro.interfaces.dtos.general.ErrorResponseDTO; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; + +@ControllerAdvice +public class PersonExceptionHandler { + + @ExceptionHandler(PersonNotFoundException.class) + public ResponseEntity handlePersonNotFoundException(PersonNotFoundException exception) { + return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new ErrorResponseDTO(exception.getMessage())); + } + + @ExceptionHandler(PersonAlreadyExistsException.class) + public ResponseEntity handlePersonAlreadyExistsException(PersonAlreadyExistsException exception) { + return ResponseEntity.status(HttpStatus.CONFLICT).body(new ErrorResponseDTO(exception.getMessage())); + } + +} diff --git a/cadastro/src/main/java/com/vinhonotas/cadastro/configuration/StateExceptionHandler.java b/cadastro/src/main/java/com/vinhonotas/cadastro/configuration/StateExceptionHandler.java new file mode 100644 index 00000000..03dfa707 --- /dev/null +++ b/cadastro/src/main/java/com/vinhonotas/cadastro/configuration/StateExceptionHandler.java @@ -0,0 +1,24 @@ +package com.vinhonotas.cadastro.configuration; + +import com.vinhonotas.cadastro.domain.entities.exceptions.StateAlreadyExistsException; +import com.vinhonotas.cadastro.domain.entities.exceptions.StateNotFoundException; +import com.vinhonotas.cadastro.interfaces.dtos.general.ErrorResponseDTO; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; + +@ControllerAdvice +public class StateExceptionHandler { + + @ExceptionHandler(StateAlreadyExistsException.class) + public ResponseEntity handleStateAlreadyExistsException(StateAlreadyExistsException exception) { + return ResponseEntity.status(HttpStatus.CONFLICT).body(new ErrorResponseDTO(exception.getMessage())); + } + + @ExceptionHandler(StateNotFoundException.class) + public ResponseEntity handleStateNotFoundException(StateNotFoundException exception) { + return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new ErrorResponseDTO(exception.getMessage())); + } + +} diff --git a/cadastro/src/main/java/com/vinhonotas/cadastro/configuration/UserExceptionHandler.java b/cadastro/src/main/java/com/vinhonotas/cadastro/configuration/UserExceptionHandler.java new file mode 100644 index 00000000..c732e96f --- /dev/null +++ b/cadastro/src/main/java/com/vinhonotas/cadastro/configuration/UserExceptionHandler.java @@ -0,0 +1,24 @@ +package com.vinhonotas.cadastro.configuration; + +import com.vinhonotas.cadastro.domain.entities.exceptions.UserAlreadyExistsException; +import com.vinhonotas.cadastro.domain.entities.exceptions.UserNotFoundException; +import com.vinhonotas.cadastro.interfaces.dtos.general.ErrorResponseDTO; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; + +@ControllerAdvice +public class UserExceptionHandler { + + @ExceptionHandler(UserAlreadyExistsException.class) + public ResponseEntity handleUserAlreadyExistsException(UserAlreadyExistsException exception) { + return ResponseEntity.status(HttpStatus.CONFLICT).body(new ErrorResponseDTO(exception.getMessage())); + } + + @ExceptionHandler(UserNotFoundException.class) + public ResponseEntity handleUserNotFoundException(UserNotFoundException exception) { + return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new ErrorResponseDTO(exception.getMessage())); + } + +} diff --git a/cadastro/src/main/java/com/vinhonotas/cadastro/domain/entities/exceptions/AddressNotFoundException.java b/cadastro/src/main/java/com/vinhonotas/cadastro/domain/entities/exceptions/AddressNotFoundException.java new file mode 100644 index 00000000..343cf878 --- /dev/null +++ b/cadastro/src/main/java/com/vinhonotas/cadastro/domain/entities/exceptions/AddressNotFoundException.java @@ -0,0 +1,9 @@ +package com.vinhonotas.cadastro.domain.entities.exceptions; + +public class AddressNotFoundException extends RuntimeException { + + public AddressNotFoundException(String message) { + super(message); + } + +} diff --git a/cadastro/src/main/java/com/vinhonotas/cadastro/domain/entities/exceptions/BadRequestException.java b/cadastro/src/main/java/com/vinhonotas/cadastro/domain/entities/exceptions/BadRequestException.java new file mode 100644 index 00000000..88cc8781 --- /dev/null +++ b/cadastro/src/main/java/com/vinhonotas/cadastro/domain/entities/exceptions/BadRequestException.java @@ -0,0 +1,9 @@ +package com.vinhonotas.cadastro.domain.entities.exceptions; + +public class BadRequestException extends RuntimeException { + + public BadRequestException(String message) { + super(message); + } + +} diff --git a/cadastro/src/main/java/com/vinhonotas/cadastro/domain/entities/exceptions/CountryAlreadyExistsException.java b/cadastro/src/main/java/com/vinhonotas/cadastro/domain/entities/exceptions/CountryAlreadyExistsException.java new file mode 100644 index 00000000..490a47d6 --- /dev/null +++ b/cadastro/src/main/java/com/vinhonotas/cadastro/domain/entities/exceptions/CountryAlreadyExistsException.java @@ -0,0 +1,8 @@ +package com.vinhonotas.cadastro.domain.entities.exceptions; + +public class CountryAlreadyExistsException extends RuntimeException { + + public CountryAlreadyExistsException(String message) { + super(message); + } +} diff --git a/cadastro/src/main/java/com/vinhonotas/cadastro/domain/entities/exceptions/CountryNotFoundException.java b/cadastro/src/main/java/com/vinhonotas/cadastro/domain/entities/exceptions/CountryNotFoundException.java new file mode 100644 index 00000000..481b3cc3 --- /dev/null +++ b/cadastro/src/main/java/com/vinhonotas/cadastro/domain/entities/exceptions/CountryNotFoundException.java @@ -0,0 +1,8 @@ +package com.vinhonotas.cadastro.domain.entities.exceptions; + +public class CountryNotFoundException extends RuntimeException { + + public CountryNotFoundException(String message) { + super(message); + } +} diff --git a/cadastro/src/main/java/com/vinhonotas/cadastro/domain/entities/exceptions/PersonAlreadyExistsException.java b/cadastro/src/main/java/com/vinhonotas/cadastro/domain/entities/exceptions/PersonAlreadyExistsException.java new file mode 100644 index 00000000..4ed75b61 --- /dev/null +++ b/cadastro/src/main/java/com/vinhonotas/cadastro/domain/entities/exceptions/PersonAlreadyExistsException.java @@ -0,0 +1,9 @@ +package com.vinhonotas.cadastro.domain.entities.exceptions; + +public class PersonAlreadyExistsException extends RuntimeException { + + public PersonAlreadyExistsException(String message) { + super(message); + } + +} diff --git a/cadastro/src/main/java/com/vinhonotas/cadastro/domain/entities/exceptions/PersonNotFoundException.java b/cadastro/src/main/java/com/vinhonotas/cadastro/domain/entities/exceptions/PersonNotFoundException.java new file mode 100644 index 00000000..783f658f --- /dev/null +++ b/cadastro/src/main/java/com/vinhonotas/cadastro/domain/entities/exceptions/PersonNotFoundException.java @@ -0,0 +1,9 @@ +package com.vinhonotas.cadastro.domain.entities.exceptions; + +public class PersonNotFoundException extends RuntimeException { + + public PersonNotFoundException(String message) { + super(message); + } + +} diff --git a/cadastro/src/main/java/com/vinhonotas/cadastro/domain/entities/exceptions/StateAlreadyExistsException.java b/cadastro/src/main/java/com/vinhonotas/cadastro/domain/entities/exceptions/StateAlreadyExistsException.java new file mode 100644 index 00000000..5792aabf --- /dev/null +++ b/cadastro/src/main/java/com/vinhonotas/cadastro/domain/entities/exceptions/StateAlreadyExistsException.java @@ -0,0 +1,9 @@ +package com.vinhonotas.cadastro.domain.entities.exceptions; + +public class StateAlreadyExistsException extends RuntimeException { + + public StateAlreadyExistsException(String message) { + super(message); + } + +} diff --git a/cadastro/src/main/java/com/vinhonotas/cadastro/domain/entities/exceptions/StateNotFoundException.java b/cadastro/src/main/java/com/vinhonotas/cadastro/domain/entities/exceptions/StateNotFoundException.java new file mode 100644 index 00000000..f9650a68 --- /dev/null +++ b/cadastro/src/main/java/com/vinhonotas/cadastro/domain/entities/exceptions/StateNotFoundException.java @@ -0,0 +1,8 @@ +package com.vinhonotas.cadastro.domain.entities.exceptions; + +public class StateNotFoundException extends RuntimeException { + + public StateNotFoundException(String message) { + super(message); + } +} diff --git a/cadastro/src/main/java/com/vinhonotas/cadastro/domain/entities/exceptions/UserAlreadyExistsException.java b/cadastro/src/main/java/com/vinhonotas/cadastro/domain/entities/exceptions/UserAlreadyExistsException.java new file mode 100644 index 00000000..5ef52d41 --- /dev/null +++ b/cadastro/src/main/java/com/vinhonotas/cadastro/domain/entities/exceptions/UserAlreadyExistsException.java @@ -0,0 +1,9 @@ +package com.vinhonotas.cadastro.domain.entities.exceptions; + +public class UserAlreadyExistsException extends RuntimeException { + + public UserAlreadyExistsException(String message) { + super(message); + } + +} diff --git a/cadastro/src/main/java/com/vinhonotas/cadastro/domain/entities/exceptions/UserNotFoundException.java b/cadastro/src/main/java/com/vinhonotas/cadastro/domain/entities/exceptions/UserNotFoundException.java new file mode 100644 index 00000000..5f32970a --- /dev/null +++ b/cadastro/src/main/java/com/vinhonotas/cadastro/domain/entities/exceptions/UserNotFoundException.java @@ -0,0 +1,9 @@ +package com.vinhonotas.cadastro.domain.entities.exceptions; + +public class UserNotFoundException extends RuntimeException { + + public UserNotFoundException(String message) { + super(message); + } + +} diff --git a/cadastro/src/main/java/com/vinhonotas/cadastro/interfaces/controllers/exceptions/ControllerExceptionHandler.java b/cadastro/src/main/java/com/vinhonotas/cadastro/interfaces/controllers/exceptions/ControllerExceptionHandler.java deleted file mode 100644 index 388725cb..00000000 --- a/cadastro/src/main/java/com/vinhonotas/cadastro/interfaces/controllers/exceptions/ControllerExceptionHandler.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.vinhonotas.cadastro.interfaces.controllers.exceptions; - -import com.vinhonotas.cadastro.utils.MessagesConstants; -import org.springframework.http.HttpStatusCode; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.MethodArgumentNotValidException; -import org.springframework.web.bind.annotation.ExceptionHandler; -import org.springframework.web.bind.annotation.RestControllerAdvice; - -import java.util.List; - -@RestControllerAdvice -public class ControllerExceptionHandler { - - @ExceptionHandler(MethodArgumentNotValidException.class) - public ResponseEntity handleMethodArgumentNotValid(MethodArgumentNotValidException ex) { - List errors = getErrors(ex); - ErrorResponse errorResponse = getErrorResponse(ex, ex.getStatusCode(), errors); - return ResponseEntity.badRequest().body(errorResponse); - } - - private ErrorResponse getErrorResponse(MethodArgumentNotValidException ex, HttpStatusCode statusCode, List errors) { - return new ErrorResponse(MessagesConstants.INVALID_FIELDS, statusCode.value(), ex.getBindingResult().getObjectName(), errors); - } - - private List getErrors(MethodArgumentNotValidException ex) { - return ex.getBindingResult() - .getFieldErrors() - .stream() - .map(error -> new ErrorObject(error.getDefaultMessage(), error.getField(), error.getRejectedValue())) - .toList(); - } -} diff --git a/cadastro/src/main/java/com/vinhonotas/cadastro/interfaces/controllers/exceptions/ErrorObject.java b/cadastro/src/main/java/com/vinhonotas/cadastro/interfaces/controllers/exceptions/ErrorObject.java deleted file mode 100644 index 7afaa4bd..00000000 --- a/cadastro/src/main/java/com/vinhonotas/cadastro/interfaces/controllers/exceptions/ErrorObject.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.vinhonotas.cadastro.interfaces.controllers.exceptions; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import lombok.Setter; - -@RequiredArgsConstructor -@Getter -@Setter -public class ErrorObject { - - private final String message; - private final String field; - private final Object parameter; -} diff --git a/cadastro/src/main/java/com/vinhonotas/cadastro/interfaces/controllers/exceptions/ErrorResponse.java b/cadastro/src/main/java/com/vinhonotas/cadastro/interfaces/controllers/exceptions/ErrorResponse.java deleted file mode 100644 index 1af20696..00000000 --- a/cadastro/src/main/java/com/vinhonotas/cadastro/interfaces/controllers/exceptions/ErrorResponse.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.vinhonotas.cadastro.interfaces.controllers.exceptions; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import lombok.Setter; - -import java.util.List; - -@RequiredArgsConstructor -@Getter -@Setter -public class ErrorResponse { - - private final String message; - private final int code; - private final String objectName; - private final List errors; -} diff --git a/cadastro/src/main/java/com/vinhonotas/cadastro/interfaces/dtos/general/ErrorResponseDTO.java b/cadastro/src/main/java/com/vinhonotas/cadastro/interfaces/dtos/general/ErrorResponseDTO.java new file mode 100644 index 00000000..f6794426 --- /dev/null +++ b/cadastro/src/main/java/com/vinhonotas/cadastro/interfaces/dtos/general/ErrorResponseDTO.java @@ -0,0 +1,4 @@ +package com.vinhonotas.cadastro.interfaces.dtos.general; + +public record ErrorResponseDTO(String message) { +} diff --git a/cadastro/src/test/java/com/vinhonotas/cadastro/application/services/impl/CountryServiceImplTest.java b/cadastro/src/test/java/com/vinhonotas/cadastro/application/services/impl/CountryServiceImplTest.java index 0dc1e43e..df3a0bf2 100644 --- a/cadastro/src/test/java/com/vinhonotas/cadastro/application/services/impl/CountryServiceImplTest.java +++ b/cadastro/src/test/java/com/vinhonotas/cadastro/application/services/impl/CountryServiceImplTest.java @@ -1,8 +1,8 @@ package com.vinhonotas.cadastro.application.services.impl; import com.vinhonotas.cadastro.application.converters.CountryConverter; -import com.vinhonotas.cadastro.application.services.exceptions.BadRequestException; import com.vinhonotas.cadastro.domain.entities.CountryEntity; +import com.vinhonotas.cadastro.domain.entities.exceptions.BadRequestException; import com.vinhonotas.cadastro.infrastructure.CountryRepository; import com.vinhonotas.cadastro.interfaces.dtos.inputs.CountryInputDTO; import com.vinhonotas.cadastro.utils.MessagesConstants; diff --git a/cadastro/src/test/java/com/vinhonotas/cadastro/application/services/impl/StateServiceImplTest.java b/cadastro/src/test/java/com/vinhonotas/cadastro/application/services/impl/StateServiceImplTest.java index 1d2a66d6..e0bb0a80 100644 --- a/cadastro/src/test/java/com/vinhonotas/cadastro/application/services/impl/StateServiceImplTest.java +++ b/cadastro/src/test/java/com/vinhonotas/cadastro/application/services/impl/StateServiceImplTest.java @@ -2,9 +2,9 @@ import com.vinhonotas.cadastro.application.converters.CountryConverter; import com.vinhonotas.cadastro.application.converters.StateConverter; -import com.vinhonotas.cadastro.application.services.exceptions.BadRequestException; import com.vinhonotas.cadastro.domain.entities.CountryEntity; import com.vinhonotas.cadastro.domain.entities.StateEntity; +import com.vinhonotas.cadastro.domain.entities.exceptions.BadRequestException; import com.vinhonotas.cadastro.infrastructure.CountryRepository; import com.vinhonotas.cadastro.infrastructure.StateRepository; import com.vinhonotas.cadastro.interfaces.dtos.inputs.CountryInputDTO; diff --git a/cadastro/src/test/java/com/vinhonotas/cadastro/application/services/impl/UserServiceImplTest.java b/cadastro/src/test/java/com/vinhonotas/cadastro/application/services/impl/UserServiceImplTest.java index 0e39d4d9..10f76abb 100644 --- a/cadastro/src/test/java/com/vinhonotas/cadastro/application/services/impl/UserServiceImplTest.java +++ b/cadastro/src/test/java/com/vinhonotas/cadastro/application/services/impl/UserServiceImplTest.java @@ -2,12 +2,15 @@ import com.vinhonotas.cadastro.application.converters.PersonConverter; import com.vinhonotas.cadastro.application.converters.UserConverter; -import com.vinhonotas.cadastro.application.services.exceptions.BadRequestException; import com.vinhonotas.cadastro.domain.entities.*; +import com.vinhonotas.cadastro.domain.entities.exceptions.BadRequestException; import com.vinhonotas.cadastro.domain.enums.EnumProfile; import com.vinhonotas.cadastro.infrastructure.PersonRepository; import com.vinhonotas.cadastro.infrastructure.UserRepository; -import com.vinhonotas.cadastro.interfaces.dtos.inputs.*; +import com.vinhonotas.cadastro.interfaces.dtos.inputs.AddressInputDTO; +import com.vinhonotas.cadastro.interfaces.dtos.inputs.CountryInputDTO; +import com.vinhonotas.cadastro.interfaces.dtos.inputs.PersonInputDTO; +import com.vinhonotas.cadastro.interfaces.dtos.inputs.UserInputDTO; import com.vinhonotas.cadastro.utils.MessagesConstants; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -264,14 +267,6 @@ private StateEntity createUf() { .build(); } - private StateInputDTO createUfInputDTO() { - return StateInputDTO.builder() - .stateName("Santa Catarina") - .uf("SC") - .country(createCountryInputDTO()) - .build(); - } - private CountryEntity createCountry() { return CountryEntity.builder() .id(UUID.fromString("2cb051aa-5beb-4678-82cb-af44490c16af")) diff --git a/cadastro/src/test/java/com/vinhonotas/cadastro/interfaces/controllers/AddressControllerTest.java b/cadastro/src/test/java/com/vinhonotas/cadastro/interfaces/controllers/AddressControllerTest.java index 81cdc640..8159bf97 100644 --- a/cadastro/src/test/java/com/vinhonotas/cadastro/interfaces/controllers/AddressControllerTest.java +++ b/cadastro/src/test/java/com/vinhonotas/cadastro/interfaces/controllers/AddressControllerTest.java @@ -3,13 +3,12 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.vinhonotas.cadastro.application.converters.AddressConverter; import com.vinhonotas.cadastro.application.services.AddressService; -import com.vinhonotas.cadastro.application.services.exceptions.BadRequestException; import com.vinhonotas.cadastro.domain.entities.AddressEntity; import com.vinhonotas.cadastro.domain.entities.CountryEntity; import com.vinhonotas.cadastro.domain.entities.StateEntity; +import com.vinhonotas.cadastro.domain.entities.exceptions.BadRequestException; import com.vinhonotas.cadastro.interfaces.dtos.inputs.AddressInputDTO; import com.vinhonotas.cadastro.interfaces.dtos.inputs.CountryInputDTO; -import com.vinhonotas.cadastro.interfaces.dtos.inputs.StateInputDTO; import com.vinhonotas.cadastro.interfaces.dtos.outputs.AddressOutputDTO; import com.vinhonotas.cadastro.interfaces.dtos.outputs.CountryOutputDTO; import com.vinhonotas.cadastro.interfaces.dtos.outputs.StateOutputDTO; @@ -255,14 +254,6 @@ private AddressInputDTO createAddressInputDTO() { .build(); } - private StateInputDTO createStateInputDTO() { - return StateInputDTO.builder() - .stateName("Santa Catarina") - .uf("SC") - .country(createCountryInputDTO()) - .build(); - } - private CountryInputDTO createCountryInputDTO() { return CountryInputDTO.builder() .countryName("Brasil") diff --git a/cadastro/src/test/java/com/vinhonotas/cadastro/interfaces/controllers/CountryControllerTest.java b/cadastro/src/test/java/com/vinhonotas/cadastro/interfaces/controllers/CountryControllerTest.java index bcdbd843..516e7110 100644 --- a/cadastro/src/test/java/com/vinhonotas/cadastro/interfaces/controllers/CountryControllerTest.java +++ b/cadastro/src/test/java/com/vinhonotas/cadastro/interfaces/controllers/CountryControllerTest.java @@ -3,8 +3,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.vinhonotas.cadastro.application.converters.CountryConverter; import com.vinhonotas.cadastro.application.services.CountryService; -import com.vinhonotas.cadastro.application.services.exceptions.BadRequestException; import com.vinhonotas.cadastro.domain.entities.CountryEntity; +import com.vinhonotas.cadastro.domain.entities.exceptions.BadRequestException; import com.vinhonotas.cadastro.interfaces.dtos.inputs.CountryInputDTO; import com.vinhonotas.cadastro.interfaces.dtos.outputs.CountryOutputDTO; import com.vinhonotas.cadastro.utils.MessagesConstants; diff --git a/cadastro/src/test/java/com/vinhonotas/cadastro/interfaces/controllers/PersonControllerTest.java b/cadastro/src/test/java/com/vinhonotas/cadastro/interfaces/controllers/PersonControllerTest.java index 183de5d2..fe1fc05a 100644 --- a/cadastro/src/test/java/com/vinhonotas/cadastro/interfaces/controllers/PersonControllerTest.java +++ b/cadastro/src/test/java/com/vinhonotas/cadastro/interfaces/controllers/PersonControllerTest.java @@ -3,11 +3,11 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.vinhonotas.cadastro.application.converters.PersonConverter; import com.vinhonotas.cadastro.application.services.PersonService; -import com.vinhonotas.cadastro.application.services.exceptions.BadRequestException; import com.vinhonotas.cadastro.domain.entities.AddressEntity; import com.vinhonotas.cadastro.domain.entities.CountryEntity; import com.vinhonotas.cadastro.domain.entities.PersonEntity; import com.vinhonotas.cadastro.domain.entities.StateEntity; +import com.vinhonotas.cadastro.domain.entities.exceptions.BadRequestException; import com.vinhonotas.cadastro.interfaces.dtos.inputs.AddressInputDTO; import com.vinhonotas.cadastro.interfaces.dtos.inputs.CountryInputDTO; import com.vinhonotas.cadastro.interfaces.dtos.inputs.PersonInputDTO; diff --git a/cadastro/src/test/java/com/vinhonotas/cadastro/interfaces/controllers/StateControllerTest.java b/cadastro/src/test/java/com/vinhonotas/cadastro/interfaces/controllers/StateControllerTest.java index e0fee517..7eede75b 100644 --- a/cadastro/src/test/java/com/vinhonotas/cadastro/interfaces/controllers/StateControllerTest.java +++ b/cadastro/src/test/java/com/vinhonotas/cadastro/interfaces/controllers/StateControllerTest.java @@ -3,9 +3,9 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.vinhonotas.cadastro.application.converters.StateConverter; import com.vinhonotas.cadastro.application.services.StateService; -import com.vinhonotas.cadastro.application.services.exceptions.BadRequestException; import com.vinhonotas.cadastro.domain.entities.CountryEntity; import com.vinhonotas.cadastro.domain.entities.StateEntity; +import com.vinhonotas.cadastro.domain.entities.exceptions.BadRequestException; import com.vinhonotas.cadastro.interfaces.dtos.inputs.CountryInputDTO; import com.vinhonotas.cadastro.interfaces.dtos.inputs.StateInputDTO; import com.vinhonotas.cadastro.interfaces.dtos.outputs.CountryOutputDTO; diff --git a/cadastro/src/test/java/com/vinhonotas/cadastro/interfaces/controllers/UserControllerTest.java b/cadastro/src/test/java/com/vinhonotas/cadastro/interfaces/controllers/UserControllerTest.java index 2b76c353..e9b36ab2 100644 --- a/cadastro/src/test/java/com/vinhonotas/cadastro/interfaces/controllers/UserControllerTest.java +++ b/cadastro/src/test/java/com/vinhonotas/cadastro/interfaces/controllers/UserControllerTest.java @@ -3,10 +3,12 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.vinhonotas.cadastro.application.converters.UserConverter; import com.vinhonotas.cadastro.application.services.UserService; -import com.vinhonotas.cadastro.application.services.exceptions.BadRequestException; import com.vinhonotas.cadastro.domain.entities.*; +import com.vinhonotas.cadastro.domain.entities.exceptions.BadRequestException; import com.vinhonotas.cadastro.domain.enums.EnumProfile; -import com.vinhonotas.cadastro.interfaces.dtos.inputs.*; +import com.vinhonotas.cadastro.interfaces.dtos.inputs.AddressInputDTO; +import com.vinhonotas.cadastro.interfaces.dtos.inputs.PersonInputDTO; +import com.vinhonotas.cadastro.interfaces.dtos.inputs.UserInputDTO; import com.vinhonotas.cadastro.interfaces.dtos.outputs.*; import com.vinhonotas.cadastro.utils.MessagesConstants; import org.junit.jupiter.api.BeforeEach; From d04a94fc3b10500b8404892324475925f91eb79f Mon Sep 17 00:00:00 2001 From: vanderleik Date: Sun, 7 Apr 2024 12:12:45 -0300 Subject: [PATCH 2/4] =?UTF-8?q?feat:=20VIN-397=20-=20refatorando=20exce?= =?UTF-8?q?=C3=A7=C3=B5es=20do=20VINHO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exceptions/BadRequestException.java | 12 ---------- .../services/impl/WineServiceImpl.java | 9 +++---- .../configuration/WineExceptionHandler.java | 24 +++++++++++++++++++ .../exceptions/BadRequestException.java | 9 +++++++ .../exceptions/WineNotFoundException.java | 8 +++++++ .../vinho/domain/enums/EnumWineType.java | 2 -- .../dtos/general/ErrorResponseDTO.java | 4 ++++ .../services/impl/WineServiceImplTest.java | 2 +- .../controllers/WineControllerTest.java | 2 +- 9 files changed, 52 insertions(+), 20 deletions(-) delete mode 100644 vinho/src/main/java/com/vinhonotas/vinho/application/services/exceptions/BadRequestException.java create mode 100644 vinho/src/main/java/com/vinhonotas/vinho/configuration/WineExceptionHandler.java create mode 100644 vinho/src/main/java/com/vinhonotas/vinho/domain/entities/exceptions/BadRequestException.java create mode 100644 vinho/src/main/java/com/vinhonotas/vinho/domain/entities/exceptions/WineNotFoundException.java create mode 100644 vinho/src/main/java/com/vinhonotas/vinho/interfaces/dtos/general/ErrorResponseDTO.java diff --git a/vinho/src/main/java/com/vinhonotas/vinho/application/services/exceptions/BadRequestException.java b/vinho/src/main/java/com/vinhonotas/vinho/application/services/exceptions/BadRequestException.java deleted file mode 100644 index c030bca8..00000000 --- a/vinho/src/main/java/com/vinhonotas/vinho/application/services/exceptions/BadRequestException.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.vinhonotas.vinho.application.services.exceptions; - -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.ResponseStatus; - -@ResponseStatus(HttpStatus.BAD_REQUEST) -public class BadRequestException extends RuntimeException{ - - public BadRequestException(String message) { - super(message); - } -} diff --git a/vinho/src/main/java/com/vinhonotas/vinho/application/services/impl/WineServiceImpl.java b/vinho/src/main/java/com/vinhonotas/vinho/application/services/impl/WineServiceImpl.java index e379e1cf..ff9cc177 100644 --- a/vinho/src/main/java/com/vinhonotas/vinho/application/services/impl/WineServiceImpl.java +++ b/vinho/src/main/java/com/vinhonotas/vinho/application/services/impl/WineServiceImpl.java @@ -2,8 +2,9 @@ import com.vinhonotas.vinho.application.converters.WineConverter; import com.vinhonotas.vinho.application.services.WineService; -import com.vinhonotas.vinho.application.services.exceptions.BadRequestException; import com.vinhonotas.vinho.domain.entities.WineEntity; +import com.vinhonotas.vinho.domain.entities.exceptions.BadRequestException; +import com.vinhonotas.vinho.domain.entities.exceptions.WineNotFoundException; import com.vinhonotas.vinho.infraestructure.WineRepository; import com.vinhonotas.vinho.interfaces.dtos.inputs.WineInputDTO; import com.vinhonotas.vinho.utils.MessagesConstants; @@ -42,7 +43,7 @@ public List getAll() { List wineList = wineRepository.findAll(); if (wineList.isEmpty()) { log.error("getAll :: Ocorreu um erro ao listar os vinhos: {} ", MessagesConstants.ERROR_WINE_NOT_FOUND); - throw new BadRequestException(MessagesConstants.ERROR_WINE_NOT_FOUND); + throw new WineNotFoundException(MessagesConstants.ERROR_WINE_NOT_FOUND); } return wineList; } @@ -51,7 +52,7 @@ public List getAll() { public WineEntity getById(UUID id) { log.info("getById :: Buscando vinho pelo id: {}", id.toString()); return wineRepository.findById(id) - .orElseThrow(() -> new BadRequestException(MessagesConstants.ERROR_WINE_NOT_FOUND)); + .orElseThrow(() -> new WineNotFoundException(MessagesConstants.ERROR_WINE_NOT_FOUND)); } @Override @@ -74,7 +75,7 @@ public void delete(UUID id) { Optional wine = wineRepository.findById(id); if (wine.isEmpty()) { log.error("delete :: Ocorreu um erro ao deletar o vinho: {} ", MessagesConstants.ERROR_WINE_NOT_FOUND); - throw new BadRequestException(MessagesConstants.ERROR_WINE_NOT_FOUND); + throw new WineNotFoundException(MessagesConstants.ERROR_WINE_NOT_FOUND); } try { wineRepository.deleteById(id); diff --git a/vinho/src/main/java/com/vinhonotas/vinho/configuration/WineExceptionHandler.java b/vinho/src/main/java/com/vinhonotas/vinho/configuration/WineExceptionHandler.java new file mode 100644 index 00000000..779feceb --- /dev/null +++ b/vinho/src/main/java/com/vinhonotas/vinho/configuration/WineExceptionHandler.java @@ -0,0 +1,24 @@ +package com.vinhonotas.vinho.configuration; + +import com.vinhonotas.vinho.domain.entities.exceptions.BadRequestException; +import com.vinhonotas.vinho.domain.entities.exceptions.WineNotFoundException; +import com.vinhonotas.vinho.interfaces.dtos.general.ErrorResponseDTO; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; + +@ControllerAdvice +public class WineExceptionHandler { + + @ExceptionHandler(BadRequestException.class) + public ResponseEntity handleBadRequestException(BadRequestException exception) { + return ResponseEntity.badRequest().body(new ErrorResponseDTO(exception.getMessage())); + } + + @ExceptionHandler(WineNotFoundException.class) + public ResponseEntity handleWineNotFoundException(WineNotFoundException exception) { + return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new ErrorResponseDTO(exception.getMessage())); + } + +} diff --git a/vinho/src/main/java/com/vinhonotas/vinho/domain/entities/exceptions/BadRequestException.java b/vinho/src/main/java/com/vinhonotas/vinho/domain/entities/exceptions/BadRequestException.java new file mode 100644 index 00000000..22a05983 --- /dev/null +++ b/vinho/src/main/java/com/vinhonotas/vinho/domain/entities/exceptions/BadRequestException.java @@ -0,0 +1,9 @@ +package com.vinhonotas.vinho.domain.entities.exceptions; + +public class BadRequestException extends RuntimeException { + + public BadRequestException(String message) { + super(message); + } + +} diff --git a/vinho/src/main/java/com/vinhonotas/vinho/domain/entities/exceptions/WineNotFoundException.java b/vinho/src/main/java/com/vinhonotas/vinho/domain/entities/exceptions/WineNotFoundException.java new file mode 100644 index 00000000..7da6dca1 --- /dev/null +++ b/vinho/src/main/java/com/vinhonotas/vinho/domain/entities/exceptions/WineNotFoundException.java @@ -0,0 +1,8 @@ +package com.vinhonotas.vinho.domain.entities.exceptions; + +public class WineNotFoundException extends RuntimeException { + + public WineNotFoundException(String message) { + super(message); + } +} diff --git a/vinho/src/main/java/com/vinhonotas/vinho/domain/enums/EnumWineType.java b/vinho/src/main/java/com/vinhonotas/vinho/domain/enums/EnumWineType.java index 049a6274..208787d1 100644 --- a/vinho/src/main/java/com/vinhonotas/vinho/domain/enums/EnumWineType.java +++ b/vinho/src/main/java/com/vinhonotas/vinho/domain/enums/EnumWineType.java @@ -1,7 +1,5 @@ package com.vinhonotas.vinho.domain.enums; -import com.vinhonotas.vinho.application.services.exceptions.BadRequestException; -import com.vinhonotas.vinho.utils.MessagesConstants; import lombok.Getter; import lombok.RequiredArgsConstructor; diff --git a/vinho/src/main/java/com/vinhonotas/vinho/interfaces/dtos/general/ErrorResponseDTO.java b/vinho/src/main/java/com/vinhonotas/vinho/interfaces/dtos/general/ErrorResponseDTO.java new file mode 100644 index 00000000..b52aba63 --- /dev/null +++ b/vinho/src/main/java/com/vinhonotas/vinho/interfaces/dtos/general/ErrorResponseDTO.java @@ -0,0 +1,4 @@ +package com.vinhonotas.vinho.interfaces.dtos.general; + +public record ErrorResponseDTO(String message) { +} diff --git a/vinho/src/test/java/com/vinhonotas/vinho/application/services/impl/WineServiceImplTest.java b/vinho/src/test/java/com/vinhonotas/vinho/application/services/impl/WineServiceImplTest.java index 000cfcc0..5880e9bf 100644 --- a/vinho/src/test/java/com/vinhonotas/vinho/application/services/impl/WineServiceImplTest.java +++ b/vinho/src/test/java/com/vinhonotas/vinho/application/services/impl/WineServiceImplTest.java @@ -1,8 +1,8 @@ package com.vinhonotas.vinho.application.services.impl; import com.vinhonotas.vinho.application.converters.WineConverter; -import com.vinhonotas.vinho.application.services.exceptions.BadRequestException; import com.vinhonotas.vinho.domain.entities.WineEntity; +import com.vinhonotas.vinho.domain.entities.exceptions.BadRequestException; import com.vinhonotas.vinho.domain.enums.EnumWineClassification; import com.vinhonotas.vinho.domain.enums.EnumWineType; import com.vinhonotas.vinho.infraestructure.WineRepository; diff --git a/vinho/src/test/java/com/vinhonotas/vinho/interfaces/controllers/WineControllerTest.java b/vinho/src/test/java/com/vinhonotas/vinho/interfaces/controllers/WineControllerTest.java index fd5d2bf7..4b05f64f 100644 --- a/vinho/src/test/java/com/vinhonotas/vinho/interfaces/controllers/WineControllerTest.java +++ b/vinho/src/test/java/com/vinhonotas/vinho/interfaces/controllers/WineControllerTest.java @@ -3,8 +3,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.vinhonotas.vinho.application.converters.WineConverter; import com.vinhonotas.vinho.application.services.WineService; -import com.vinhonotas.vinho.application.services.exceptions.BadRequestException; import com.vinhonotas.vinho.domain.entities.WineEntity; +import com.vinhonotas.vinho.domain.entities.exceptions.BadRequestException; import com.vinhonotas.vinho.domain.enums.EnumWineClassification; import com.vinhonotas.vinho.domain.enums.EnumWineType; import com.vinhonotas.vinho.interfaces.dtos.inputs.WineInputDTO; From ef7cab49ab48363e3926d018d3ff385d1d31b881 Mon Sep 17 00:00:00 2001 From: vanderleik Date: Sun, 7 Apr 2024 12:28:10 -0300 Subject: [PATCH 3/4] =?UTF-8?q?feat:=20VIN-397=20-=20refatorando=20exce?= =?UTF-8?q?=C3=A7=C3=B5es=20do=20AVALIACAO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exceptions/BadRequestException.java | 12 ---------- .../services/impl/PointScaleServiceImpl.java | 10 ++++---- .../PointScaleExceptionHandler.java | 24 +++++++++++++++++++ .../exceptions/BadRequestException.java | 9 +++++++ .../PointScaleNotFoundException.java | 9 +++++++ .../dtos/general/ErrorResponseDTO.java | 4 ++++ .../impl/PointScaleServiceImplTest.java | 2 +- .../controllers/PointScaleControllerTest.java | 2 +- 8 files changed, 54 insertions(+), 18 deletions(-) delete mode 100644 avaliacao/src/main/java/com/vinhonotas/avaliacao/application/services/exceptions/BadRequestException.java create mode 100644 avaliacao/src/main/java/com/vinhonotas/avaliacao/configuration/PointScaleExceptionHandler.java create mode 100644 avaliacao/src/main/java/com/vinhonotas/avaliacao/domain/entities/exceptions/BadRequestException.java create mode 100644 avaliacao/src/main/java/com/vinhonotas/avaliacao/domain/entities/exceptions/PointScaleNotFoundException.java create mode 100644 avaliacao/src/main/java/com/vinhonotas/avaliacao/interfaces/dtos/general/ErrorResponseDTO.java diff --git a/avaliacao/src/main/java/com/vinhonotas/avaliacao/application/services/exceptions/BadRequestException.java b/avaliacao/src/main/java/com/vinhonotas/avaliacao/application/services/exceptions/BadRequestException.java deleted file mode 100644 index 1ff25f01..00000000 --- a/avaliacao/src/main/java/com/vinhonotas/avaliacao/application/services/exceptions/BadRequestException.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.vinhonotas.avaliacao.application.services.exceptions; - -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.ResponseStatus; - -@ResponseStatus(HttpStatus.BAD_REQUEST) -public class BadRequestException extends RuntimeException { - - public BadRequestException(String message) { - super(message); - } -} diff --git a/avaliacao/src/main/java/com/vinhonotas/avaliacao/application/services/impl/PointScaleServiceImpl.java b/avaliacao/src/main/java/com/vinhonotas/avaliacao/application/services/impl/PointScaleServiceImpl.java index 9fc28980..4878fea5 100644 --- a/avaliacao/src/main/java/com/vinhonotas/avaliacao/application/services/impl/PointScaleServiceImpl.java +++ b/avaliacao/src/main/java/com/vinhonotas/avaliacao/application/services/impl/PointScaleServiceImpl.java @@ -2,8 +2,9 @@ import com.vinhonotas.avaliacao.application.converters.PointScaleConverter; import com.vinhonotas.avaliacao.application.services.PointScaleService; -import com.vinhonotas.avaliacao.application.services.exceptions.BadRequestException; import com.vinhonotas.avaliacao.domain.entities.PointScaleEntity; +import com.vinhonotas.avaliacao.domain.entities.exceptions.BadRequestException; +import com.vinhonotas.avaliacao.domain.entities.exceptions.PointScaleNotFoundException; import com.vinhonotas.avaliacao.infraestructure.PointScaleRepository; import com.vinhonotas.avaliacao.interfaces.dtos.inputs.PointScaleInputDTO; import com.vinhonotas.avaliacao.utils.MessagesConstants; @@ -42,7 +43,7 @@ public List getAll() { List list = pointScaleRepository.findAll(); if (list.isEmpty()) { log.error("getAll :: Ocorreu um erro ao buscar as avaliações: {}", MessagesConstants.ERROR_POINT_SCALE_NOT_FOUND); - throw new BadRequestException(MessagesConstants.ERROR_POINT_SCALE_NOT_FOUND); + throw new PointScaleNotFoundException(MessagesConstants.ERROR_POINT_SCALE_NOT_FOUND); } return list; } @@ -50,7 +51,8 @@ public List getAll() { @Override public PointScaleEntity getById(UUID id) { log.info("getById :: Buscando uma avaliação pelo id: {}", id.toString()); - return pointScaleRepository.findById(id).orElseThrow(() -> new BadRequestException(MessagesConstants.ERROR_POINT_SCALE_NOT_FOUND)); + return pointScaleRepository.findById(id).orElseThrow(() -> + new PointScaleNotFoundException(MessagesConstants.ERROR_POINT_SCALE_NOT_FOUND)); } @Override @@ -73,7 +75,7 @@ public void delete(UUID id) { Optional pointScale = pointScaleRepository.findById(id); if (pointScale.isEmpty()) { log.error("delete :: Ocorreu um erro ao deletar a avaliação: {}", MessagesConstants.ERROR_POINT_SCALE_NOT_FOUND); - throw new BadRequestException(MessagesConstants.ERROR_POINT_SCALE_NOT_FOUND); + throw new PointScaleNotFoundException(MessagesConstants.ERROR_POINT_SCALE_NOT_FOUND); } try { pointScaleRepository.deleteById(id); diff --git a/avaliacao/src/main/java/com/vinhonotas/avaliacao/configuration/PointScaleExceptionHandler.java b/avaliacao/src/main/java/com/vinhonotas/avaliacao/configuration/PointScaleExceptionHandler.java new file mode 100644 index 00000000..d5a42103 --- /dev/null +++ b/avaliacao/src/main/java/com/vinhonotas/avaliacao/configuration/PointScaleExceptionHandler.java @@ -0,0 +1,24 @@ +package com.vinhonotas.avaliacao.configuration; + +import com.vinhonotas.avaliacao.domain.entities.exceptions.BadRequestException; +import com.vinhonotas.avaliacao.domain.entities.exceptions.PointScaleNotFoundException; +import com.vinhonotas.avaliacao.interfaces.dtos.general.ErrorResponseDTO; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; + +@ControllerAdvice +public class PointScaleExceptionHandler { + + @ExceptionHandler(PointScaleNotFoundException.class) + public ResponseEntity handlePointScaleNotFoundException(PointScaleNotFoundException exception) { + return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new ErrorResponseDTO(exception.getMessage())); + } + + @ExceptionHandler(BadRequestException.class) + public ResponseEntity handleBadRequestException(BadRequestException exception) { + return ResponseEntity.badRequest().body(new ErrorResponseDTO(exception.getMessage())); + } + +} diff --git a/avaliacao/src/main/java/com/vinhonotas/avaliacao/domain/entities/exceptions/BadRequestException.java b/avaliacao/src/main/java/com/vinhonotas/avaliacao/domain/entities/exceptions/BadRequestException.java new file mode 100644 index 00000000..0067a36d --- /dev/null +++ b/avaliacao/src/main/java/com/vinhonotas/avaliacao/domain/entities/exceptions/BadRequestException.java @@ -0,0 +1,9 @@ +package com.vinhonotas.avaliacao.domain.entities.exceptions; + +public class BadRequestException extends RuntimeException { + + public BadRequestException(String message) { + super(message); + } + +} diff --git a/avaliacao/src/main/java/com/vinhonotas/avaliacao/domain/entities/exceptions/PointScaleNotFoundException.java b/avaliacao/src/main/java/com/vinhonotas/avaliacao/domain/entities/exceptions/PointScaleNotFoundException.java new file mode 100644 index 00000000..cb21743e --- /dev/null +++ b/avaliacao/src/main/java/com/vinhonotas/avaliacao/domain/entities/exceptions/PointScaleNotFoundException.java @@ -0,0 +1,9 @@ +package com.vinhonotas.avaliacao.domain.entities.exceptions; + +public class PointScaleNotFoundException extends RuntimeException { + + public PointScaleNotFoundException(String message) { + super(message); + } + +} diff --git a/avaliacao/src/main/java/com/vinhonotas/avaliacao/interfaces/dtos/general/ErrorResponseDTO.java b/avaliacao/src/main/java/com/vinhonotas/avaliacao/interfaces/dtos/general/ErrorResponseDTO.java new file mode 100644 index 00000000..d6215d13 --- /dev/null +++ b/avaliacao/src/main/java/com/vinhonotas/avaliacao/interfaces/dtos/general/ErrorResponseDTO.java @@ -0,0 +1,4 @@ +package com.vinhonotas.avaliacao.interfaces.dtos.general; + +public record ErrorResponseDTO(String message) { +} diff --git a/avaliacao/src/test/java/com/vinhonotas/avaliacao/application/services/impl/PointScaleServiceImplTest.java b/avaliacao/src/test/java/com/vinhonotas/avaliacao/application/services/impl/PointScaleServiceImplTest.java index f7267cce..4e3c1966 100644 --- a/avaliacao/src/test/java/com/vinhonotas/avaliacao/application/services/impl/PointScaleServiceImplTest.java +++ b/avaliacao/src/test/java/com/vinhonotas/avaliacao/application/services/impl/PointScaleServiceImplTest.java @@ -1,8 +1,8 @@ package com.vinhonotas.avaliacao.application.services.impl; import com.vinhonotas.avaliacao.application.converters.PointScaleConverter; -import com.vinhonotas.avaliacao.application.services.exceptions.BadRequestException; import com.vinhonotas.avaliacao.domain.entities.PointScaleEntity; +import com.vinhonotas.avaliacao.domain.entities.exceptions.BadRequestException; import com.vinhonotas.avaliacao.domain.enums.EnumPointScale; import com.vinhonotas.avaliacao.infraestructure.PointScaleRepository; import com.vinhonotas.avaliacao.interfaces.dtos.inputs.PointScaleInputDTO; diff --git a/avaliacao/src/test/java/com/vinhonotas/avaliacao/interfaces/controllers/PointScaleControllerTest.java b/avaliacao/src/test/java/com/vinhonotas/avaliacao/interfaces/controllers/PointScaleControllerTest.java index 01310341..1778a440 100644 --- a/avaliacao/src/test/java/com/vinhonotas/avaliacao/interfaces/controllers/PointScaleControllerTest.java +++ b/avaliacao/src/test/java/com/vinhonotas/avaliacao/interfaces/controllers/PointScaleControllerTest.java @@ -3,8 +3,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.vinhonotas.avaliacao.application.converters.PointScaleConverter; import com.vinhonotas.avaliacao.application.services.PointScaleService; -import com.vinhonotas.avaliacao.application.services.exceptions.BadRequestException; import com.vinhonotas.avaliacao.domain.entities.PointScaleEntity; +import com.vinhonotas.avaliacao.domain.entities.exceptions.BadRequestException; import com.vinhonotas.avaliacao.domain.enums.EnumPointScale; import com.vinhonotas.avaliacao.interfaces.dtos.inputs.PointScaleInputDTO; import com.vinhonotas.avaliacao.interfaces.dtos.outputs.PointScaleOutputDTO; From 53a9b156d87f2078c7be05b06e86184a938e9876 Mon Sep 17 00:00:00 2001 From: vanderleik Date: Sun, 7 Apr 2024 12:59:13 -0300 Subject: [PATCH 4/4] =?UTF-8?q?feat:=20VIN-397=20-=20refatorando=20as=20ex?= =?UTF-8?q?ce=C3=A7=C3=B5es=20do=20DEGUSTACAO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../converters/TastingCardConverter.java | 4 ---- .../exceptions/BadRequestException.java | 13 ------------- .../services/impl/AromasServiceImpl.java | 9 +++++---- .../impl/GustatoryInspectionServiceImpl.java | 9 +++++---- .../impl/OlfactoryInspectionServiceImpl.java | 9 +++++---- .../services/impl/TastingCardServiceImpl.java | 14 +++++++++----- .../services/impl/TastingServiceImpl.java | 14 +++++++++----- .../impl/VisualInspectionServiceImpl.java | 9 +++++---- .../configuration/AromasExceptionHandler.java | 18 ++++++++++++++++++ .../configuration/GeneralExceptionHandler.java | 17 +++++++++++++++++ .../GustatoryInspectionExceptionHandler.java | 18 ++++++++++++++++++ .../OlfactoryInspectionExceptionHandler.java | 18 ++++++++++++++++++ .../TastingCardExceptionHandler.java | 18 ++++++++++++++++++ .../configuration/TastingExceptionHandler.java | 17 +++++++++++++++++ .../VisualInspectionExceptionHandler.java | 18 ++++++++++++++++++ .../exceptions/AromasNotFoundException.java | 9 +++++++++ .../exceptions/BadRequestException.java | 9 +++++++++ .../GustatoryInspectionNotFoundException.java | 9 +++++++++ .../OlfactoryInspectionNotFoundException.java | 9 +++++++++ .../TastingCardNotFoundException.java | 9 +++++++++ .../exceptions/TastingNotFoundException.java | 9 +++++++++ .../VisualInspectionNotFoundException.java | 9 +++++++++ .../dtos/general/ErrorResponseDTO.java | 4 ++++ .../converters/TastingCardConverterTest.java | 6 +----- .../services/impl/AromasServiceImplTest.java | 2 +- .../GustatoryInspectionServiceImplTest.java | 2 +- .../OlfactoryInspectionServiceImplTest.java | 2 +- .../impl/TastingCardServiceImplTest.java | 2 +- .../services/impl/TastingServiceImplTest.java | 2 +- .../impl/VisualInspectionServiceImplTest.java | 2 +- .../controllers/AromasControllerTest.java | 2 +- .../GustatoryInspectionControllerTest.java | 2 +- .../OlfactoryInspectionControllerTest.java | 2 +- .../controllers/TastingCardControllerTest.java | 2 +- .../controllers/TastingControllerTest.java | 2 +- .../VisualInspectionControllerTest.java | 2 +- 36 files changed, 242 insertions(+), 60 deletions(-) delete mode 100644 degustacao/src/main/java/com/vinhonotas/degustacao/application/services/exceptions/BadRequestException.java create mode 100644 degustacao/src/main/java/com/vinhonotas/degustacao/configuration/AromasExceptionHandler.java create mode 100644 degustacao/src/main/java/com/vinhonotas/degustacao/configuration/GeneralExceptionHandler.java create mode 100644 degustacao/src/main/java/com/vinhonotas/degustacao/configuration/GustatoryInspectionExceptionHandler.java create mode 100644 degustacao/src/main/java/com/vinhonotas/degustacao/configuration/OlfactoryInspectionExceptionHandler.java create mode 100644 degustacao/src/main/java/com/vinhonotas/degustacao/configuration/TastingCardExceptionHandler.java create mode 100644 degustacao/src/main/java/com/vinhonotas/degustacao/configuration/TastingExceptionHandler.java create mode 100644 degustacao/src/main/java/com/vinhonotas/degustacao/configuration/VisualInspectionExceptionHandler.java create mode 100644 degustacao/src/main/java/com/vinhonotas/degustacao/domain/entities/exceptions/AromasNotFoundException.java create mode 100644 degustacao/src/main/java/com/vinhonotas/degustacao/domain/entities/exceptions/BadRequestException.java create mode 100644 degustacao/src/main/java/com/vinhonotas/degustacao/domain/entities/exceptions/GustatoryInspectionNotFoundException.java create mode 100644 degustacao/src/main/java/com/vinhonotas/degustacao/domain/entities/exceptions/OlfactoryInspectionNotFoundException.java create mode 100644 degustacao/src/main/java/com/vinhonotas/degustacao/domain/entities/exceptions/TastingCardNotFoundException.java create mode 100644 degustacao/src/main/java/com/vinhonotas/degustacao/domain/entities/exceptions/TastingNotFoundException.java create mode 100644 degustacao/src/main/java/com/vinhonotas/degustacao/domain/entities/exceptions/VisualInspectionNotFoundException.java create mode 100644 degustacao/src/main/java/com/vinhonotas/degustacao/interfaces/dtos/general/ErrorResponseDTO.java diff --git a/degustacao/src/main/java/com/vinhonotas/degustacao/application/converters/TastingCardConverter.java b/degustacao/src/main/java/com/vinhonotas/degustacao/application/converters/TastingCardConverter.java index a6cdfdfd..7994d8a3 100644 --- a/degustacao/src/main/java/com/vinhonotas/degustacao/application/converters/TastingCardConverter.java +++ b/degustacao/src/main/java/com/vinhonotas/degustacao/application/converters/TastingCardConverter.java @@ -20,7 +20,6 @@ public class TastingCardConverter { private final VisualInspectionConverter visualInspectionConverter; private final OlfactoryInspectionConverter olfactoryInspectionConverter; private final GustatoryInspectionConverter gustatoryInspectionConverter; - private final TastingConverter tastingConverter; public TastingCardEntity toEntity(TastingCardInputDTO tastingCardInputDTO) { return TastingCardEntity.builder() @@ -81,7 +80,6 @@ public TastingCardOutputDTO toOutputDTO(TastingCardEntity tastingCardEntity) { .gustatoryInspection(gustatoryInspectionConverter.toOutputDTO(tastingCardEntity.getGustatoryInspection())) .opinion(tastingCardEntity.getOpinion()) .pointScale(EnumConverter.toString(tastingCardEntity.getPointScale())) - .tasting(tastingConverter.toOutputDTO(tastingCardEntity.getTasting())) .build(); } @@ -117,8 +115,6 @@ public TastingCardOutputDTO toOutputDTOUpdate(TastingCardEntity tastingCardEntit .opinion(tastingCardOutputDTO.getOpinion() != null ? tastingCardOutputDTO.getOpinion() : tastingCardEntity.getOpinion()) .pointScale(tastingCardOutputDTO.getPointScale() != null ? tastingCardOutputDTO.getPointScale() : EnumConverter.toString(tastingCardEntity.getPointScale())) - .tasting(tastingCardOutputDTO.getTasting() != null ? tastingCardOutputDTO.getTasting() : tastingConverter - .toOutputDTO(tastingCardEntity.getTasting())) .build(); } diff --git a/degustacao/src/main/java/com/vinhonotas/degustacao/application/services/exceptions/BadRequestException.java b/degustacao/src/main/java/com/vinhonotas/degustacao/application/services/exceptions/BadRequestException.java deleted file mode 100644 index 2f64315d..00000000 --- a/degustacao/src/main/java/com/vinhonotas/degustacao/application/services/exceptions/BadRequestException.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.vinhonotas.degustacao.application.services.exceptions; - -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.ResponseStatus; - -@ResponseStatus(HttpStatus.BAD_REQUEST) -public class BadRequestException extends RuntimeException { - - public BadRequestException(String message) { - super(message); - } - -} diff --git a/degustacao/src/main/java/com/vinhonotas/degustacao/application/services/impl/AromasServiceImpl.java b/degustacao/src/main/java/com/vinhonotas/degustacao/application/services/impl/AromasServiceImpl.java index fa290768..cca6c951 100644 --- a/degustacao/src/main/java/com/vinhonotas/degustacao/application/services/impl/AromasServiceImpl.java +++ b/degustacao/src/main/java/com/vinhonotas/degustacao/application/services/impl/AromasServiceImpl.java @@ -2,8 +2,9 @@ import com.vinhonotas.degustacao.application.converters.AromasConverter; import com.vinhonotas.degustacao.application.services.AromasService; -import com.vinhonotas.degustacao.application.services.exceptions.BadRequestException; import com.vinhonotas.degustacao.domain.entities.AromasEntity; +import com.vinhonotas.degustacao.domain.entities.exceptions.AromasNotFoundException; +import com.vinhonotas.degustacao.domain.entities.exceptions.BadRequestException; import com.vinhonotas.degustacao.infraestructure.AromasRepository; import com.vinhonotas.degustacao.interfaces.dtos.inputs.AromasInputDTO; import com.vinhonotas.degustacao.utils.MessagesConstants; @@ -43,7 +44,7 @@ public List getAll() { List list = aromasRepository.findAll(); if (list.isEmpty()) { log.error("getAll :: Ocorreu um erro ao listar os aromas: {} ", MessagesConstants.AROMAS_NOT_FOUND); - throw new BadRequestException(MessagesConstants.AROMAS_NOT_FOUND); + throw new AromasNotFoundException(MessagesConstants.AROMAS_NOT_FOUND); } return list; } @@ -52,7 +53,7 @@ public List getAll() { public AromasEntity getById(UUID id) { log.info("getById :: Buscando aroma pelo id: {}", id.toString()); return aromasRepository.findById(id) - .orElseThrow(() -> new BadRequestException(MessagesConstants.AROMAS_NOT_FOUND)); + .orElseThrow(() -> new AromasNotFoundException(MessagesConstants.AROMAS_NOT_FOUND)); } @Override @@ -75,7 +76,7 @@ public void delete(UUID id) { Optional opt = aromasRepository.findById(id); if (opt.isEmpty()) { log.error("delete :: Ocorreu um erro ao deletar o aroma: {} ", MessagesConstants.AROMAS_NOT_FOUND); - throw new BadRequestException(MessagesConstants.AROMAS_NOT_FOUND); + throw new AromasNotFoundException(MessagesConstants.AROMAS_NOT_FOUND); } try { diff --git a/degustacao/src/main/java/com/vinhonotas/degustacao/application/services/impl/GustatoryInspectionServiceImpl.java b/degustacao/src/main/java/com/vinhonotas/degustacao/application/services/impl/GustatoryInspectionServiceImpl.java index 55bf07dd..794eeee2 100644 --- a/degustacao/src/main/java/com/vinhonotas/degustacao/application/services/impl/GustatoryInspectionServiceImpl.java +++ b/degustacao/src/main/java/com/vinhonotas/degustacao/application/services/impl/GustatoryInspectionServiceImpl.java @@ -2,8 +2,9 @@ import com.vinhonotas.degustacao.application.converters.GustatoryInspectionConverter; import com.vinhonotas.degustacao.application.services.GustatoryInspectionService; -import com.vinhonotas.degustacao.application.services.exceptions.BadRequestException; import com.vinhonotas.degustacao.domain.entities.GustatoryInspectionEntity; +import com.vinhonotas.degustacao.domain.entities.exceptions.BadRequestException; +import com.vinhonotas.degustacao.domain.entities.exceptions.GustatoryInspectionNotFoundException; import com.vinhonotas.degustacao.infraestructure.GustatoryInspectionRepository; import com.vinhonotas.degustacao.interfaces.dtos.inputs.GustatoryInspectionInputDTO; import com.vinhonotas.degustacao.utils.MessagesConstants; @@ -42,7 +43,7 @@ public List getAll() { List list = gustatoryInspectionRepository.findAll(); if (list.isEmpty()) { log.error("getAll :: Ocorreu um erro ao listar as inspeções gustativas: {} ", MessagesConstants.GUSTATORY_INSPECTION_NOT_FOUND); - throw new BadRequestException(MessagesConstants.GUSTATORY_INSPECTION_NOT_FOUND); + throw new GustatoryInspectionNotFoundException(MessagesConstants.GUSTATORY_INSPECTION_NOT_FOUND); } return list; } @@ -51,7 +52,7 @@ public List getAll() { public GustatoryInspectionEntity getById(UUID id) { log.info("getById :: Buscando inspeção gustativa pelo id: {}", id.toString()); return gustatoryInspectionRepository.findById(id) - .orElseThrow(() -> new BadRequestException(MessagesConstants.GUSTATORY_INSPECTION_NOT_FOUND)); + .orElseThrow(() -> new GustatoryInspectionNotFoundException(MessagesConstants.GUSTATORY_INSPECTION_NOT_FOUND)); } @Override @@ -74,7 +75,7 @@ public void delete(UUID id) { Optional opt = gustatoryInspectionRepository.findById(id); if (opt.isEmpty()) { log.error("delete :: Ocorreu um erro ao deletar a inspeção gustativa: {} ", MessagesConstants.GUSTATORY_INSPECTION_NOT_FOUND); - throw new BadRequestException(MessagesConstants.GUSTATORY_INSPECTION_NOT_FOUND); + throw new GustatoryInspectionNotFoundException(MessagesConstants.GUSTATORY_INSPECTION_NOT_FOUND); } try { gustatoryInspectionRepository.deleteById(id); diff --git a/degustacao/src/main/java/com/vinhonotas/degustacao/application/services/impl/OlfactoryInspectionServiceImpl.java b/degustacao/src/main/java/com/vinhonotas/degustacao/application/services/impl/OlfactoryInspectionServiceImpl.java index dbd4fd8d..6ecc6306 100644 --- a/degustacao/src/main/java/com/vinhonotas/degustacao/application/services/impl/OlfactoryInspectionServiceImpl.java +++ b/degustacao/src/main/java/com/vinhonotas/degustacao/application/services/impl/OlfactoryInspectionServiceImpl.java @@ -2,8 +2,9 @@ import com.vinhonotas.degustacao.application.converters.OlfactoryInspectionConverter; import com.vinhonotas.degustacao.application.services.OlfactoryInspectionService; -import com.vinhonotas.degustacao.application.services.exceptions.BadRequestException; import com.vinhonotas.degustacao.domain.entities.OlfactoryInspectionEntity; +import com.vinhonotas.degustacao.domain.entities.exceptions.BadRequestException; +import com.vinhonotas.degustacao.domain.entities.exceptions.OlfactoryInspectionNotFoundException; import com.vinhonotas.degustacao.infraestructure.OlfactoryInspectionRepository; import com.vinhonotas.degustacao.interfaces.dtos.inputs.OlfactoryInspectionInputDTO; import com.vinhonotas.degustacao.utils.MessagesConstants; @@ -43,7 +44,7 @@ public List getAll() { List list = olfactoryInspectionRepository.findAll(); if (list.isEmpty()) { log.error("getAll :: Ocorreu um erro ao listar as inspeções olfativas: {} ", MessagesConstants.OLFACTORY_INSPECTION_NOT_FOUND); - throw new BadRequestException(MessagesConstants.OLFACTORY_INSPECTION_NOT_FOUND); + throw new OlfactoryInspectionNotFoundException(MessagesConstants.OLFACTORY_INSPECTION_NOT_FOUND); } return list; } @@ -52,7 +53,7 @@ public List getAll() { public OlfactoryInspectionEntity getById(UUID id) { log.info("getById :: Buscando inspeção olfativa pelo id: {}", id.toString()); return olfactoryInspectionRepository.findById(id) - .orElseThrow(() -> new BadRequestException(MessagesConstants.OLFACTORY_INSPECTION_NOT_FOUND)); + .orElseThrow(() -> new OlfactoryInspectionNotFoundException(MessagesConstants.OLFACTORY_INSPECTION_NOT_FOUND)); } @Override @@ -75,7 +76,7 @@ public void delete(UUID id) { Optional opt = olfactoryInspectionRepository.findById(id); if (opt.isEmpty()) { log.error("delete :: Ocorreu um erro ao deletar a inspeção olfativa: {} ", MessagesConstants.OLFACTORY_INSPECTION_NOT_FOUND); - throw new BadRequestException(MessagesConstants.OLFACTORY_INSPECTION_NOT_FOUND); + throw new OlfactoryInspectionNotFoundException(MessagesConstants.OLFACTORY_INSPECTION_NOT_FOUND); } try { olfactoryInspectionRepository.deleteById(id); diff --git a/degustacao/src/main/java/com/vinhonotas/degustacao/application/services/impl/TastingCardServiceImpl.java b/degustacao/src/main/java/com/vinhonotas/degustacao/application/services/impl/TastingCardServiceImpl.java index b7215e84..b14da52d 100644 --- a/degustacao/src/main/java/com/vinhonotas/degustacao/application/services/impl/TastingCardServiceImpl.java +++ b/degustacao/src/main/java/com/vinhonotas/degustacao/application/services/impl/TastingCardServiceImpl.java @@ -2,8 +2,9 @@ import com.vinhonotas.degustacao.application.converters.TastingCardConverter; import com.vinhonotas.degustacao.application.services.TastingCardService; -import com.vinhonotas.degustacao.application.services.exceptions.BadRequestException; import com.vinhonotas.degustacao.domain.entities.TastingCardEntity; +import com.vinhonotas.degustacao.domain.entities.exceptions.BadRequestException; +import com.vinhonotas.degustacao.domain.entities.exceptions.TastingCardNotFoundException; import com.vinhonotas.degustacao.infraestructure.TastingCardRepository; import com.vinhonotas.degustacao.interfaces.dtos.inputs.TastingCardInputDTO; import com.vinhonotas.degustacao.utils.MessagesConstants; @@ -12,7 +13,10 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.*; +import java.util.HashSet; +import java.util.Optional; +import java.util.Set; +import java.util.UUID; @Service @RequiredArgsConstructor @@ -41,7 +45,7 @@ public Set getAll() { var list = tastingCardRepository.findAll(); if (list.isEmpty()) { log.error("getAll :: Ocorreu um erro ao listar as fichas de degustações: {} ", MessagesConstants.TASTING_CARD_NOT_FOUND); - throw new BadRequestException(MessagesConstants.TASTING_CARD_NOT_FOUND); + throw new TastingCardNotFoundException(MessagesConstants.TASTING_CARD_NOT_FOUND); } return new HashSet<>(list); } @@ -50,7 +54,7 @@ public Set getAll() { public TastingCardEntity getById(UUID id) { log.info("getById :: Buscando ficha de degustação pelo id: {}", id); return tastingCardRepository.findById(id) - .orElseThrow(() -> new BadRequestException(MessagesConstants.TASTING_CARD_NOT_FOUND)); + .orElseThrow(() -> new TastingCardNotFoundException(MessagesConstants.TASTING_CARD_NOT_FOUND)); } @Override @@ -73,7 +77,7 @@ public void delete(UUID id) { Optional opt = tastingCardRepository.findById(id); if (opt.isEmpty()) { log.error("delete :: Ocorreu um erro ao deletar a ficha de degustação: {} ", MessagesConstants.TASTING_CARD_NOT_FOUND); - throw new BadRequestException(MessagesConstants.TASTING_CARD_NOT_FOUND); + throw new TastingCardNotFoundException(MessagesConstants.TASTING_CARD_NOT_FOUND); } try { tastingCardRepository.deleteById(id); diff --git a/degustacao/src/main/java/com/vinhonotas/degustacao/application/services/impl/TastingServiceImpl.java b/degustacao/src/main/java/com/vinhonotas/degustacao/application/services/impl/TastingServiceImpl.java index 8f5934fc..8aea9fa7 100644 --- a/degustacao/src/main/java/com/vinhonotas/degustacao/application/services/impl/TastingServiceImpl.java +++ b/degustacao/src/main/java/com/vinhonotas/degustacao/application/services/impl/TastingServiceImpl.java @@ -2,8 +2,9 @@ import com.vinhonotas.degustacao.application.converters.TastingConverter; import com.vinhonotas.degustacao.application.services.TastingService; -import com.vinhonotas.degustacao.application.services.exceptions.BadRequestException; import com.vinhonotas.degustacao.domain.entities.TastingEntity; +import com.vinhonotas.degustacao.domain.entities.exceptions.BadRequestException; +import com.vinhonotas.degustacao.domain.entities.exceptions.TastingNotFoundException; import com.vinhonotas.degustacao.infraestructure.TastingRepository; import com.vinhonotas.degustacao.interfaces.dtos.inputs.TastingInputDTO; import com.vinhonotas.degustacao.utils.MessagesConstants; @@ -12,7 +13,10 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.*; +import java.util.HashSet; +import java.util.Optional; +import java.util.Set; +import java.util.UUID; @Service @RequiredArgsConstructor @@ -41,7 +45,7 @@ public Set getAll() { var list = tastingRepository.findAll(); if (list.isEmpty()) { log.error("getAll :: Ocorreu um erro ao listar as degustações: {} ", MessagesConstants.TASTING_NOT_FOUND); - throw new BadRequestException(MessagesConstants.TASTING_NOT_FOUND); + throw new TastingNotFoundException(MessagesConstants.TASTING_NOT_FOUND); } return new HashSet<>(list); } @@ -50,7 +54,7 @@ public Set getAll() { public TastingEntity getById(UUID id) { log.info("getById :: Buscando degustação pelo id: {}", id); return tastingRepository.findById(id) - .orElseThrow(() -> new BadRequestException(MessagesConstants.TASTING_NOT_FOUND)); + .orElseThrow(() -> new TastingNotFoundException(MessagesConstants.TASTING_NOT_FOUND)); } @Override @@ -73,7 +77,7 @@ public void delete(UUID id) { Optional opt = tastingRepository.findById(id); if (opt.isEmpty()) { log.error("delete :: Ocorreu um erro ao deletar a degustação: {} ", MessagesConstants.TASTING_NOT_FOUND); - throw new BadRequestException(MessagesConstants.TASTING_NOT_FOUND); + throw new TastingNotFoundException(MessagesConstants.TASTING_NOT_FOUND); } try { tastingRepository.deleteById(id); diff --git a/degustacao/src/main/java/com/vinhonotas/degustacao/application/services/impl/VisualInspectionServiceImpl.java b/degustacao/src/main/java/com/vinhonotas/degustacao/application/services/impl/VisualInspectionServiceImpl.java index 95b2eef3..7d0086ac 100644 --- a/degustacao/src/main/java/com/vinhonotas/degustacao/application/services/impl/VisualInspectionServiceImpl.java +++ b/degustacao/src/main/java/com/vinhonotas/degustacao/application/services/impl/VisualInspectionServiceImpl.java @@ -2,8 +2,9 @@ import com.vinhonotas.degustacao.application.converters.VisualInspectionConverter; import com.vinhonotas.degustacao.application.services.VisualInspectionService; -import com.vinhonotas.degustacao.application.services.exceptions.BadRequestException; import com.vinhonotas.degustacao.domain.entities.VisualInspectionEntity; +import com.vinhonotas.degustacao.domain.entities.exceptions.BadRequestException; +import com.vinhonotas.degustacao.domain.entities.exceptions.VisualInspectionNotFoundException; import com.vinhonotas.degustacao.infraestructure.VisualInspectionRepository; import com.vinhonotas.degustacao.interfaces.dtos.inputs.VisualInspectionInputDTO; import com.vinhonotas.degustacao.utils.MessagesConstants; @@ -43,7 +44,7 @@ public List getAll() { List list = visualInspectionRepository.findAll(); if (list.isEmpty()) { log.error("getAll :: Ocorreu um erro ao listar as inspeções visuais: {} ", MessagesConstants.VISUAL_INSPECTION_NOT_FOUND); - throw new BadRequestException(MessagesConstants.VISUAL_INSPECTION_NOT_FOUND); + throw new VisualInspectionNotFoundException(MessagesConstants.VISUAL_INSPECTION_NOT_FOUND); } return list; } @@ -52,7 +53,7 @@ public List getAll() { public VisualInspectionEntity getById(UUID id) { log.info("getById :: Buscando inspeção visual pelo id: {}", id); return visualInspectionRepository.findById(id) - .orElseThrow(() -> new BadRequestException(MessagesConstants.VISUAL_INSPECTION_NOT_FOUND)); + .orElseThrow(() -> new VisualInspectionNotFoundException(MessagesConstants.VISUAL_INSPECTION_NOT_FOUND)); } @Override @@ -75,7 +76,7 @@ public void delete(UUID id) { Optional opt = visualInspectionRepository.findById(id); if (opt.isEmpty()) { log.error("delete :: Ocorreu um erro ao deletar a inspeção visual: {} ", MessagesConstants.VISUAL_INSPECTION_NOT_FOUND); - throw new BadRequestException(MessagesConstants.VISUAL_INSPECTION_NOT_FOUND); + throw new VisualInspectionNotFoundException(MessagesConstants.VISUAL_INSPECTION_NOT_FOUND); } try { visualInspectionRepository.deleteById(id); diff --git a/degustacao/src/main/java/com/vinhonotas/degustacao/configuration/AromasExceptionHandler.java b/degustacao/src/main/java/com/vinhonotas/degustacao/configuration/AromasExceptionHandler.java new file mode 100644 index 00000000..4d5c7682 --- /dev/null +++ b/degustacao/src/main/java/com/vinhonotas/degustacao/configuration/AromasExceptionHandler.java @@ -0,0 +1,18 @@ +package com.vinhonotas.degustacao.configuration; + +import com.vinhonotas.degustacao.domain.entities.exceptions.AromasNotFoundException; +import com.vinhonotas.degustacao.interfaces.dtos.general.ErrorResponseDTO; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; + +@ControllerAdvice +public class AromasExceptionHandler { + + @ExceptionHandler(AromasNotFoundException.class) + public ResponseEntity handleAromasNotFoundException(AromasNotFoundException exception) { + return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new ErrorResponseDTO(exception.getMessage())); + } + +} diff --git a/degustacao/src/main/java/com/vinhonotas/degustacao/configuration/GeneralExceptionHandler.java b/degustacao/src/main/java/com/vinhonotas/degustacao/configuration/GeneralExceptionHandler.java new file mode 100644 index 00000000..25984fbf --- /dev/null +++ b/degustacao/src/main/java/com/vinhonotas/degustacao/configuration/GeneralExceptionHandler.java @@ -0,0 +1,17 @@ +package com.vinhonotas.degustacao.configuration; + +import com.vinhonotas.degustacao.domain.entities.exceptions.BadRequestException; +import com.vinhonotas.degustacao.interfaces.dtos.general.ErrorResponseDTO; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; + +@ControllerAdvice +public class GeneralExceptionHandler { + + @ExceptionHandler(BadRequestException.class) + public ResponseEntity handleBadRequestException(BadRequestException exception) { + return ResponseEntity.badRequest().body(new ErrorResponseDTO(exception.getMessage())); + } + +} diff --git a/degustacao/src/main/java/com/vinhonotas/degustacao/configuration/GustatoryInspectionExceptionHandler.java b/degustacao/src/main/java/com/vinhonotas/degustacao/configuration/GustatoryInspectionExceptionHandler.java new file mode 100644 index 00000000..ebe581ac --- /dev/null +++ b/degustacao/src/main/java/com/vinhonotas/degustacao/configuration/GustatoryInspectionExceptionHandler.java @@ -0,0 +1,18 @@ +package com.vinhonotas.degustacao.configuration; + +import com.vinhonotas.degustacao.domain.entities.exceptions.GustatoryInspectionNotFoundException; +import com.vinhonotas.degustacao.interfaces.dtos.general.ErrorResponseDTO; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; + +@ControllerAdvice +public class GustatoryInspectionExceptionHandler { + + @ExceptionHandler(GustatoryInspectionNotFoundException.class) + public ResponseEntity handleGustatoryInspectionNotFoundException(GustatoryInspectionNotFoundException exception) { + return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new ErrorResponseDTO(exception.getMessage())); + } + +} diff --git a/degustacao/src/main/java/com/vinhonotas/degustacao/configuration/OlfactoryInspectionExceptionHandler.java b/degustacao/src/main/java/com/vinhonotas/degustacao/configuration/OlfactoryInspectionExceptionHandler.java new file mode 100644 index 00000000..830e8952 --- /dev/null +++ b/degustacao/src/main/java/com/vinhonotas/degustacao/configuration/OlfactoryInspectionExceptionHandler.java @@ -0,0 +1,18 @@ +package com.vinhonotas.degustacao.configuration; + +import com.vinhonotas.degustacao.domain.entities.exceptions.OlfactoryInspectionNotFoundException; +import com.vinhonotas.degustacao.interfaces.dtos.general.ErrorResponseDTO; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; + +@ControllerAdvice +public class OlfactoryInspectionExceptionHandler { + + @ExceptionHandler(OlfactoryInspectionNotFoundException.class) + public ResponseEntity handleOlfactoryInspectionNotFoundException(OlfactoryInspectionNotFoundException exception) { + return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new ErrorResponseDTO(exception.getMessage())); + } + +} diff --git a/degustacao/src/main/java/com/vinhonotas/degustacao/configuration/TastingCardExceptionHandler.java b/degustacao/src/main/java/com/vinhonotas/degustacao/configuration/TastingCardExceptionHandler.java new file mode 100644 index 00000000..3e7c507b --- /dev/null +++ b/degustacao/src/main/java/com/vinhonotas/degustacao/configuration/TastingCardExceptionHandler.java @@ -0,0 +1,18 @@ +package com.vinhonotas.degustacao.configuration; + +import com.vinhonotas.degustacao.domain.entities.exceptions.TastingCardNotFoundException; +import com.vinhonotas.degustacao.interfaces.dtos.general.ErrorResponseDTO; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; + +@ControllerAdvice +public class TastingCardExceptionHandler { + + @ExceptionHandler(TastingCardNotFoundException.class) + public ResponseEntity handleTastingCardNotFoundException(TastingCardNotFoundException exception) { + return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new ErrorResponseDTO(exception.getMessage())); + } + +} diff --git a/degustacao/src/main/java/com/vinhonotas/degustacao/configuration/TastingExceptionHandler.java b/degustacao/src/main/java/com/vinhonotas/degustacao/configuration/TastingExceptionHandler.java new file mode 100644 index 00000000..9ce9765e --- /dev/null +++ b/degustacao/src/main/java/com/vinhonotas/degustacao/configuration/TastingExceptionHandler.java @@ -0,0 +1,17 @@ +package com.vinhonotas.degustacao.configuration; + +import com.vinhonotas.degustacao.domain.entities.exceptions.TastingNotFoundException; +import com.vinhonotas.degustacao.interfaces.dtos.general.ErrorResponseDTO; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; + +@ControllerAdvice +public class TastingExceptionHandler { + + @ExceptionHandler(TastingNotFoundException.class) + public ResponseEntity handleTastingNotFoundException(TastingNotFoundException exception) { + return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new ErrorResponseDTO(exception.getMessage())); + } +} diff --git a/degustacao/src/main/java/com/vinhonotas/degustacao/configuration/VisualInspectionExceptionHandler.java b/degustacao/src/main/java/com/vinhonotas/degustacao/configuration/VisualInspectionExceptionHandler.java new file mode 100644 index 00000000..3054d0ab --- /dev/null +++ b/degustacao/src/main/java/com/vinhonotas/degustacao/configuration/VisualInspectionExceptionHandler.java @@ -0,0 +1,18 @@ +package com.vinhonotas.degustacao.configuration; + +import com.vinhonotas.degustacao.domain.entities.exceptions.VisualInspectionNotFoundException; +import com.vinhonotas.degustacao.interfaces.dtos.general.ErrorResponseDTO; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; + +@ControllerAdvice +public class VisualInspectionExceptionHandler { + + @ExceptionHandler(VisualInspectionNotFoundException.class) + public ResponseEntity handleVisualInspectionNotFoundException(VisualInspectionNotFoundException exception) { + return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new ErrorResponseDTO(exception.getMessage())); + } + +} diff --git a/degustacao/src/main/java/com/vinhonotas/degustacao/domain/entities/exceptions/AromasNotFoundException.java b/degustacao/src/main/java/com/vinhonotas/degustacao/domain/entities/exceptions/AromasNotFoundException.java new file mode 100644 index 00000000..63dab217 --- /dev/null +++ b/degustacao/src/main/java/com/vinhonotas/degustacao/domain/entities/exceptions/AromasNotFoundException.java @@ -0,0 +1,9 @@ +package com.vinhonotas.degustacao.domain.entities.exceptions; + +public class AromasNotFoundException extends RuntimeException { + + public AromasNotFoundException(String message) { + super(message); + } + +} diff --git a/degustacao/src/main/java/com/vinhonotas/degustacao/domain/entities/exceptions/BadRequestException.java b/degustacao/src/main/java/com/vinhonotas/degustacao/domain/entities/exceptions/BadRequestException.java new file mode 100644 index 00000000..3849ad83 --- /dev/null +++ b/degustacao/src/main/java/com/vinhonotas/degustacao/domain/entities/exceptions/BadRequestException.java @@ -0,0 +1,9 @@ +package com.vinhonotas.degustacao.domain.entities.exceptions; + +public class BadRequestException extends RuntimeException { + + public BadRequestException(String message) { + super(message); + } + +} diff --git a/degustacao/src/main/java/com/vinhonotas/degustacao/domain/entities/exceptions/GustatoryInspectionNotFoundException.java b/degustacao/src/main/java/com/vinhonotas/degustacao/domain/entities/exceptions/GustatoryInspectionNotFoundException.java new file mode 100644 index 00000000..fec8a839 --- /dev/null +++ b/degustacao/src/main/java/com/vinhonotas/degustacao/domain/entities/exceptions/GustatoryInspectionNotFoundException.java @@ -0,0 +1,9 @@ +package com.vinhonotas.degustacao.domain.entities.exceptions; + +public class GustatoryInspectionNotFoundException extends RuntimeException { + + public GustatoryInspectionNotFoundException(String message) { + super(message); + } + +} diff --git a/degustacao/src/main/java/com/vinhonotas/degustacao/domain/entities/exceptions/OlfactoryInspectionNotFoundException.java b/degustacao/src/main/java/com/vinhonotas/degustacao/domain/entities/exceptions/OlfactoryInspectionNotFoundException.java new file mode 100644 index 00000000..95ac93ca --- /dev/null +++ b/degustacao/src/main/java/com/vinhonotas/degustacao/domain/entities/exceptions/OlfactoryInspectionNotFoundException.java @@ -0,0 +1,9 @@ +package com.vinhonotas.degustacao.domain.entities.exceptions; + +public class OlfactoryInspectionNotFoundException extends RuntimeException { + + public OlfactoryInspectionNotFoundException(String message) { + super(message); + } + +} diff --git a/degustacao/src/main/java/com/vinhonotas/degustacao/domain/entities/exceptions/TastingCardNotFoundException.java b/degustacao/src/main/java/com/vinhonotas/degustacao/domain/entities/exceptions/TastingCardNotFoundException.java new file mode 100644 index 00000000..43e3f33f --- /dev/null +++ b/degustacao/src/main/java/com/vinhonotas/degustacao/domain/entities/exceptions/TastingCardNotFoundException.java @@ -0,0 +1,9 @@ +package com.vinhonotas.degustacao.domain.entities.exceptions; + +public class TastingCardNotFoundException extends RuntimeException { + + public TastingCardNotFoundException(String message) { + super(message); + } + +} diff --git a/degustacao/src/main/java/com/vinhonotas/degustacao/domain/entities/exceptions/TastingNotFoundException.java b/degustacao/src/main/java/com/vinhonotas/degustacao/domain/entities/exceptions/TastingNotFoundException.java new file mode 100644 index 00000000..f3bc0191 --- /dev/null +++ b/degustacao/src/main/java/com/vinhonotas/degustacao/domain/entities/exceptions/TastingNotFoundException.java @@ -0,0 +1,9 @@ +package com.vinhonotas.degustacao.domain.entities.exceptions; + +public class TastingNotFoundException extends RuntimeException { + + public TastingNotFoundException(String message) { + super(message); + } + +} diff --git a/degustacao/src/main/java/com/vinhonotas/degustacao/domain/entities/exceptions/VisualInspectionNotFoundException.java b/degustacao/src/main/java/com/vinhonotas/degustacao/domain/entities/exceptions/VisualInspectionNotFoundException.java new file mode 100644 index 00000000..669ba81e --- /dev/null +++ b/degustacao/src/main/java/com/vinhonotas/degustacao/domain/entities/exceptions/VisualInspectionNotFoundException.java @@ -0,0 +1,9 @@ +package com.vinhonotas.degustacao.domain.entities.exceptions; + +public class VisualInspectionNotFoundException extends RuntimeException { + + public VisualInspectionNotFoundException(String message) { + super(message); + } + +} diff --git a/degustacao/src/main/java/com/vinhonotas/degustacao/interfaces/dtos/general/ErrorResponseDTO.java b/degustacao/src/main/java/com/vinhonotas/degustacao/interfaces/dtos/general/ErrorResponseDTO.java new file mode 100644 index 00000000..548967d7 --- /dev/null +++ b/degustacao/src/main/java/com/vinhonotas/degustacao/interfaces/dtos/general/ErrorResponseDTO.java @@ -0,0 +1,4 @@ +package com.vinhonotas.degustacao.interfaces.dtos.general; + +public record ErrorResponseDTO(String message) { +} diff --git a/degustacao/src/test/java/com/vinhonotas/degustacao/application/converters/TastingCardConverterTest.java b/degustacao/src/test/java/com/vinhonotas/degustacao/application/converters/TastingCardConverterTest.java index 2826a269..13c42d7b 100644 --- a/degustacao/src/test/java/com/vinhonotas/degustacao/application/converters/TastingCardConverterTest.java +++ b/degustacao/src/test/java/com/vinhonotas/degustacao/application/converters/TastingCardConverterTest.java @@ -92,7 +92,6 @@ void testToOutputDTO() { .thenReturn(OlfactoryInspectionOutputDTO.builder().build()); when(gustatoryInspectionConverter.toOutputDTO(Mockito.any(GustatoryInspectionEntity.class))) .thenReturn(GustatoryInspectionOutputDTO.builder().build()); - when(tastingConverter.toOutputDTO(Mockito.any(TastingEntity.class))).thenReturn(TastingOutputDTO.builder().build()); TastingCardOutputDTO outputDTO = assertDoesNotThrow(() -> tastingCardConverter.toOutputDTO(tastingCardEntity)); @@ -112,7 +111,6 @@ void testToOutputDTO() { outputDTO.getGustatoryInspection()); assertEquals(tastingCardEntity.getOpinion(), outputDTO.getOpinion()); assertEquals(EnumConverter.toString(tastingCardEntity.getPointScale()), outputDTO.getPointScale()); - assertEquals(tastingConverter.toOutputDTO(tastingCardEntity.getTasting()), outputDTO.getTasting()); } @Test @@ -124,7 +122,6 @@ void testToOutputDTOList() { .thenReturn(OlfactoryInspectionOutputDTO.builder().build()); when(gustatoryInspectionConverter.toOutputDTO(Mockito.any(GustatoryInspectionEntity.class))) .thenReturn(GustatoryInspectionOutputDTO.builder().build()); - when(tastingConverter.toOutputDTO(Mockito.any(TastingEntity.class))).thenReturn(TastingOutputDTO.builder().build()); var list = assertDoesNotThrow(() -> tastingCardConverter.toOutputDTOList(Set.of(tastingCardEntity))); @@ -145,8 +142,7 @@ void testToOutputDTOList() { list.stream().toList().get(0).getGustatoryInspection()); assertEquals(tastingCardEntity.getOpinion(), list.stream().toList().get(0).getOpinion()); assertEquals(EnumConverter.toString(tastingCardEntity.getPointScale()), list.stream().toList().get(0).getPointScale()); - assertEquals(tastingConverter.toOutputDTO(tastingCardEntity.getTasting()), - list.stream().toList().get(0).getTasting()); + list.stream().toList().get(0).getTasting(); } @Test diff --git a/degustacao/src/test/java/com/vinhonotas/degustacao/application/services/impl/AromasServiceImplTest.java b/degustacao/src/test/java/com/vinhonotas/degustacao/application/services/impl/AromasServiceImplTest.java index fdecb097..e5a6a612 100644 --- a/degustacao/src/test/java/com/vinhonotas/degustacao/application/services/impl/AromasServiceImplTest.java +++ b/degustacao/src/test/java/com/vinhonotas/degustacao/application/services/impl/AromasServiceImplTest.java @@ -1,8 +1,8 @@ package com.vinhonotas.degustacao.application.services.impl; import com.vinhonotas.degustacao.application.converters.AromasConverter; -import com.vinhonotas.degustacao.application.services.exceptions.BadRequestException; import com.vinhonotas.degustacao.domain.entities.AromasEntity; +import com.vinhonotas.degustacao.domain.entities.exceptions.BadRequestException; import com.vinhonotas.degustacao.domain.enums.*; import com.vinhonotas.degustacao.infraestructure.AromasRepository; import com.vinhonotas.degustacao.interfaces.dtos.inputs.AromasInputDTO; diff --git a/degustacao/src/test/java/com/vinhonotas/degustacao/application/services/impl/GustatoryInspectionServiceImplTest.java b/degustacao/src/test/java/com/vinhonotas/degustacao/application/services/impl/GustatoryInspectionServiceImplTest.java index 0d808c6d..f33626b1 100644 --- a/degustacao/src/test/java/com/vinhonotas/degustacao/application/services/impl/GustatoryInspectionServiceImplTest.java +++ b/degustacao/src/test/java/com/vinhonotas/degustacao/application/services/impl/GustatoryInspectionServiceImplTest.java @@ -1,8 +1,8 @@ package com.vinhonotas.degustacao.application.services.impl; import com.vinhonotas.degustacao.application.converters.GustatoryInspectionConverter; -import com.vinhonotas.degustacao.application.services.exceptions.BadRequestException; import com.vinhonotas.degustacao.domain.entities.GustatoryInspectionEntity; +import com.vinhonotas.degustacao.domain.entities.exceptions.BadRequestException; import com.vinhonotas.degustacao.domain.enums.*; import com.vinhonotas.degustacao.infraestructure.GustatoryInspectionRepository; import com.vinhonotas.degustacao.interfaces.dtos.inputs.GustatoryInspectionInputDTO; diff --git a/degustacao/src/test/java/com/vinhonotas/degustacao/application/services/impl/OlfactoryInspectionServiceImplTest.java b/degustacao/src/test/java/com/vinhonotas/degustacao/application/services/impl/OlfactoryInspectionServiceImplTest.java index a7371747..12a66529 100644 --- a/degustacao/src/test/java/com/vinhonotas/degustacao/application/services/impl/OlfactoryInspectionServiceImplTest.java +++ b/degustacao/src/test/java/com/vinhonotas/degustacao/application/services/impl/OlfactoryInspectionServiceImplTest.java @@ -1,9 +1,9 @@ package com.vinhonotas.degustacao.application.services.impl; import com.vinhonotas.degustacao.application.converters.OlfactoryInspectionConverter; -import com.vinhonotas.degustacao.application.services.exceptions.BadRequestException; import com.vinhonotas.degustacao.domain.entities.AromasEntity; import com.vinhonotas.degustacao.domain.entities.OlfactoryInspectionEntity; +import com.vinhonotas.degustacao.domain.entities.exceptions.BadRequestException; import com.vinhonotas.degustacao.domain.enums.EnumClassificationType; import com.vinhonotas.degustacao.domain.enums.EnumIntensityType; import com.vinhonotas.degustacao.domain.enums.EnumPersistenceType; diff --git a/degustacao/src/test/java/com/vinhonotas/degustacao/application/services/impl/TastingCardServiceImplTest.java b/degustacao/src/test/java/com/vinhonotas/degustacao/application/services/impl/TastingCardServiceImplTest.java index 75ab9e92..938f5dd2 100644 --- a/degustacao/src/test/java/com/vinhonotas/degustacao/application/services/impl/TastingCardServiceImplTest.java +++ b/degustacao/src/test/java/com/vinhonotas/degustacao/application/services/impl/TastingCardServiceImplTest.java @@ -1,8 +1,8 @@ package com.vinhonotas.degustacao.application.services.impl; import com.vinhonotas.degustacao.application.converters.TastingCardConverter; -import com.vinhonotas.degustacao.application.services.exceptions.BadRequestException; import com.vinhonotas.degustacao.domain.entities.*; +import com.vinhonotas.degustacao.domain.entities.exceptions.BadRequestException; import com.vinhonotas.degustacao.domain.enums.EnumPointScale; import com.vinhonotas.degustacao.infraestructure.TastingCardRepository; import com.vinhonotas.degustacao.interfaces.dtos.inputs.GustatoryInspectionInputDTO; diff --git a/degustacao/src/test/java/com/vinhonotas/degustacao/application/services/impl/TastingServiceImplTest.java b/degustacao/src/test/java/com/vinhonotas/degustacao/application/services/impl/TastingServiceImplTest.java index 9c07a1f0..cf369b94 100644 --- a/degustacao/src/test/java/com/vinhonotas/degustacao/application/services/impl/TastingServiceImplTest.java +++ b/degustacao/src/test/java/com/vinhonotas/degustacao/application/services/impl/TastingServiceImplTest.java @@ -1,9 +1,9 @@ package com.vinhonotas.degustacao.application.services.impl; import com.vinhonotas.degustacao.application.converters.TastingConverter; -import com.vinhonotas.degustacao.application.services.exceptions.BadRequestException; import com.vinhonotas.degustacao.domain.entities.TastingCardEntity; import com.vinhonotas.degustacao.domain.entities.TastingEntity; +import com.vinhonotas.degustacao.domain.entities.exceptions.BadRequestException; import com.vinhonotas.degustacao.domain.enums.EnumTastingType; import com.vinhonotas.degustacao.infraestructure.TastingRepository; import com.vinhonotas.degustacao.interfaces.dtos.inputs.TastingCardInputDTO; diff --git a/degustacao/src/test/java/com/vinhonotas/degustacao/application/services/impl/VisualInspectionServiceImplTest.java b/degustacao/src/test/java/com/vinhonotas/degustacao/application/services/impl/VisualInspectionServiceImplTest.java index 04eed70d..53675817 100644 --- a/degustacao/src/test/java/com/vinhonotas/degustacao/application/services/impl/VisualInspectionServiceImplTest.java +++ b/degustacao/src/test/java/com/vinhonotas/degustacao/application/services/impl/VisualInspectionServiceImplTest.java @@ -1,8 +1,8 @@ package com.vinhonotas.degustacao.application.services.impl; import com.vinhonotas.degustacao.application.converters.VisualInspectionConverter; -import com.vinhonotas.degustacao.application.services.exceptions.BadRequestException; import com.vinhonotas.degustacao.domain.entities.VisualInspectionEntity; +import com.vinhonotas.degustacao.domain.entities.exceptions.BadRequestException; import com.vinhonotas.degustacao.domain.enums.*; import com.vinhonotas.degustacao.infraestructure.VisualInspectionRepository; import com.vinhonotas.degustacao.interfaces.dtos.inputs.VisualInspectionInputDTO; diff --git a/degustacao/src/test/java/com/vinhonotas/degustacao/interfaces/controllers/AromasControllerTest.java b/degustacao/src/test/java/com/vinhonotas/degustacao/interfaces/controllers/AromasControllerTest.java index dcb29dab..90a128d3 100644 --- a/degustacao/src/test/java/com/vinhonotas/degustacao/interfaces/controllers/AromasControllerTest.java +++ b/degustacao/src/test/java/com/vinhonotas/degustacao/interfaces/controllers/AromasControllerTest.java @@ -3,8 +3,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.vinhonotas.degustacao.application.converters.AromasConverter; import com.vinhonotas.degustacao.application.services.AromasService; -import com.vinhonotas.degustacao.application.services.exceptions.BadRequestException; import com.vinhonotas.degustacao.domain.entities.AromasEntity; +import com.vinhonotas.degustacao.domain.entities.exceptions.BadRequestException; import com.vinhonotas.degustacao.domain.enums.*; import com.vinhonotas.degustacao.interfaces.dtos.inputs.AromasInputDTO; import com.vinhonotas.degustacao.interfaces.dtos.outputs.AromasOutputDTO; diff --git a/degustacao/src/test/java/com/vinhonotas/degustacao/interfaces/controllers/GustatoryInspectionControllerTest.java b/degustacao/src/test/java/com/vinhonotas/degustacao/interfaces/controllers/GustatoryInspectionControllerTest.java index 614c05ac..a70a2073 100644 --- a/degustacao/src/test/java/com/vinhonotas/degustacao/interfaces/controllers/GustatoryInspectionControllerTest.java +++ b/degustacao/src/test/java/com/vinhonotas/degustacao/interfaces/controllers/GustatoryInspectionControllerTest.java @@ -3,8 +3,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.vinhonotas.degustacao.application.converters.GustatoryInspectionConverter; import com.vinhonotas.degustacao.application.services.GustatoryInspectionService; -import com.vinhonotas.degustacao.application.services.exceptions.BadRequestException; import com.vinhonotas.degustacao.domain.entities.GustatoryInspectionEntity; +import com.vinhonotas.degustacao.domain.entities.exceptions.BadRequestException; import com.vinhonotas.degustacao.domain.enums.*; import com.vinhonotas.degustacao.interfaces.dtos.inputs.GustatoryInspectionInputDTO; import com.vinhonotas.degustacao.interfaces.dtos.outputs.GustatoryInspectionOutputDTO; diff --git a/degustacao/src/test/java/com/vinhonotas/degustacao/interfaces/controllers/OlfactoryInspectionControllerTest.java b/degustacao/src/test/java/com/vinhonotas/degustacao/interfaces/controllers/OlfactoryInspectionControllerTest.java index 9c2b611f..fd1564ff 100644 --- a/degustacao/src/test/java/com/vinhonotas/degustacao/interfaces/controllers/OlfactoryInspectionControllerTest.java +++ b/degustacao/src/test/java/com/vinhonotas/degustacao/interfaces/controllers/OlfactoryInspectionControllerTest.java @@ -3,9 +3,9 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.vinhonotas.degustacao.application.converters.OlfactoryInspectionConverter; import com.vinhonotas.degustacao.application.services.OlfactoryInspectionService; -import com.vinhonotas.degustacao.application.services.exceptions.BadRequestException; import com.vinhonotas.degustacao.domain.entities.AromasEntity; import com.vinhonotas.degustacao.domain.entities.OlfactoryInspectionEntity; +import com.vinhonotas.degustacao.domain.entities.exceptions.BadRequestException; import com.vinhonotas.degustacao.domain.enums.EnumClassificationType; import com.vinhonotas.degustacao.domain.enums.EnumIntensityType; import com.vinhonotas.degustacao.domain.enums.EnumPersistenceType; diff --git a/degustacao/src/test/java/com/vinhonotas/degustacao/interfaces/controllers/TastingCardControllerTest.java b/degustacao/src/test/java/com/vinhonotas/degustacao/interfaces/controllers/TastingCardControllerTest.java index 1ace65b2..10348669 100644 --- a/degustacao/src/test/java/com/vinhonotas/degustacao/interfaces/controllers/TastingCardControllerTest.java +++ b/degustacao/src/test/java/com/vinhonotas/degustacao/interfaces/controllers/TastingCardControllerTest.java @@ -3,8 +3,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.vinhonotas.degustacao.application.converters.TastingCardConverter; import com.vinhonotas.degustacao.application.services.TastingCardService; -import com.vinhonotas.degustacao.application.services.exceptions.BadRequestException; import com.vinhonotas.degustacao.domain.entities.*; +import com.vinhonotas.degustacao.domain.entities.exceptions.BadRequestException; import com.vinhonotas.degustacao.domain.enums.EnumPointScale; import com.vinhonotas.degustacao.interfaces.dtos.inputs.GustatoryInspectionInputDTO; import com.vinhonotas.degustacao.interfaces.dtos.inputs.OlfactoryInspectionInputDTO; diff --git a/degustacao/src/test/java/com/vinhonotas/degustacao/interfaces/controllers/TastingControllerTest.java b/degustacao/src/test/java/com/vinhonotas/degustacao/interfaces/controllers/TastingControllerTest.java index 6fd5560d..9601f975 100644 --- a/degustacao/src/test/java/com/vinhonotas/degustacao/interfaces/controllers/TastingControllerTest.java +++ b/degustacao/src/test/java/com/vinhonotas/degustacao/interfaces/controllers/TastingControllerTest.java @@ -3,9 +3,9 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.vinhonotas.degustacao.application.converters.TastingConverter; import com.vinhonotas.degustacao.application.services.TastingService; -import com.vinhonotas.degustacao.application.services.exceptions.BadRequestException; import com.vinhonotas.degustacao.domain.entities.TastingCardEntity; import com.vinhonotas.degustacao.domain.entities.TastingEntity; +import com.vinhonotas.degustacao.domain.entities.exceptions.BadRequestException; import com.vinhonotas.degustacao.domain.enums.EnumTastingType; import com.vinhonotas.degustacao.interfaces.dtos.inputs.TastingCardInputDTO; import com.vinhonotas.degustacao.interfaces.dtos.inputs.TastingInputDTO; diff --git a/degustacao/src/test/java/com/vinhonotas/degustacao/interfaces/controllers/VisualInspectionControllerTest.java b/degustacao/src/test/java/com/vinhonotas/degustacao/interfaces/controllers/VisualInspectionControllerTest.java index 3b3ff6e0..243b4419 100644 --- a/degustacao/src/test/java/com/vinhonotas/degustacao/interfaces/controllers/VisualInspectionControllerTest.java +++ b/degustacao/src/test/java/com/vinhonotas/degustacao/interfaces/controllers/VisualInspectionControllerTest.java @@ -3,8 +3,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.vinhonotas.degustacao.application.converters.VisualInspectionConverter; import com.vinhonotas.degustacao.application.services.VisualInspectionService; -import com.vinhonotas.degustacao.application.services.exceptions.BadRequestException; import com.vinhonotas.degustacao.domain.entities.VisualInspectionEntity; +import com.vinhonotas.degustacao.domain.entities.exceptions.BadRequestException; import com.vinhonotas.degustacao.domain.enums.*; import com.vinhonotas.degustacao.interfaces.dtos.inputs.VisualInspectionInputDTO; import com.vinhonotas.degustacao.interfaces.dtos.outputs.TastingCardOutputDTO;