diff --git a/rent-service/src/main/java/it/vincenzocorso/carsharing/rentservice/adapters/messaging/CommandsHandler.java b/rent-service/src/main/java/it/vincenzocorso/carsharing/rentservice/adapters/messaging/CommandsHandler.java index 287e07d..ab66f40 100644 --- a/rent-service/src/main/java/it/vincenzocorso/carsharing/rentservice/adapters/messaging/CommandsHandler.java +++ b/rent-service/src/main/java/it/vincenzocorso/carsharing/rentservice/adapters/messaging/CommandsHandler.java @@ -4,7 +4,7 @@ import it.vincenzocorso.carsharing.common.exceptions.InternalServerException; import it.vincenzocorso.carsharing.common.messaging.commands.Command; import it.vincenzocorso.carsharing.common.messaging.commands.CommandHeaders; -import it.vincenzocorso.carsharing.rentservice.domain.ports.in.RentVehicleUseCase; +import it.vincenzocorso.carsharing.rentservice.domain.ports.in.RentVehicle; import jakarta.transaction.Transactional; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -18,7 +18,7 @@ @Slf4j public class CommandsHandler { private final ObjectMapper objectMapper; - private final RentVehicleUseCase rentVehicleUseCase; + private final RentVehicle rentVehicle; @KafkaListener(topics = "rent-service-commands") @Transactional @@ -45,13 +45,13 @@ public void dispatchMessage( private void processRejectRentCommand(RejectRentCommand command) { log.info("Processing command: " + command); - this.rentVehicleUseCase.rejectRent(command.rentId()); + this.rentVehicle.rejectRent(command.rentId()); } private void processAcceptRentCommand(AcceptRentCommand command) { log.info("Processing command: " + command); - this.rentVehicleUseCase.acceptRent(command.rentId()); + this.rentVehicle.acceptRent(command.rentId()); } } diff --git a/rent-service/src/main/java/it/vincenzocorso/carsharing/rentservice/adapters/web/RentController.java b/rent-service/src/main/java/it/vincenzocorso/carsharing/rentservice/adapters/web/RentController.java index d3addb5..c1c2bf2 100644 --- a/rent-service/src/main/java/it/vincenzocorso/carsharing/rentservice/adapters/web/RentController.java +++ b/rent-service/src/main/java/it/vincenzocorso/carsharing/rentservice/adapters/web/RentController.java @@ -7,8 +7,8 @@ import it.vincenzocorso.carsharing.rentservice.domain.exceptions.RentNotFoundException; import it.vincenzocorso.carsharing.rentservice.domain.models.Rent; import it.vincenzocorso.carsharing.rentservice.domain.models.SearchRentCriteria; -import it.vincenzocorso.carsharing.rentservice.domain.ports.in.RentVehicleUseCase; -import it.vincenzocorso.carsharing.rentservice.domain.ports.in.SearchRentUseCase; +import it.vincenzocorso.carsharing.rentservice.domain.ports.in.RentVehicle; +import it.vincenzocorso.carsharing.rentservice.domain.ports.in.SearchRent; import lombok.AllArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.validation.annotation.Validated; @@ -20,8 +20,8 @@ @Validated @AllArgsConstructor public class RentController implements RentRestApi { - private final SearchRentUseCase searchRentUseCase; - private final RentVehicleUseCase rentVehicleUseCase; + private final SearchRent searchRent; + private final RentVehicle rentVehicle; private final RentMapper rentMapper; @@ -33,18 +33,18 @@ public List getRents(String customerId, List states, Integ .limit(limit) .offset(offset) .build(); - return this.searchRentUseCase.getRents(searchRentCriteria).stream().map(this.rentMapper::convertToDto).toList(); + return this.searchRent.getRents(searchRentCriteria).stream().map(this.rentMapper::convertToDto).toList(); } @Override public RentResponse getRent(String rentId) { - Rent retrievedRent = this.searchRentUseCase.getRent(rentId); + Rent retrievedRent = this.searchRent.getRent(rentId); return this.rentMapper.convertToDto(retrievedRent); } @Override public RentResponse createRent(CreateRentRequest request) { - Rent createdRent = this.rentVehicleUseCase.createRent(request.customerId(), request.vehicleId()); + Rent createdRent = this.rentVehicle.createRent(request.customerId(), request.vehicleId()); return this.rentMapper.convertToDto(createdRent); } diff --git a/rent-service/src/main/java/it/vincenzocorso/carsharing/rentservice/domain/RentService.java b/rent-service/src/main/java/it/vincenzocorso/carsharing/rentservice/domain/RentService.java index 71a54b0..8dcb346 100644 --- a/rent-service/src/main/java/it/vincenzocorso/carsharing/rentservice/domain/RentService.java +++ b/rent-service/src/main/java/it/vincenzocorso/carsharing/rentservice/domain/RentService.java @@ -7,8 +7,8 @@ import it.vincenzocorso.carsharing.rentservice.domain.models.Rent; import it.vincenzocorso.carsharing.rentservice.domain.models.RentDetails; import it.vincenzocorso.carsharing.rentservice.domain.models.SearchRentCriteria; -import it.vincenzocorso.carsharing.rentservice.domain.ports.in.RentVehicleUseCase; -import it.vincenzocorso.carsharing.rentservice.domain.ports.in.SearchRentUseCase; +import it.vincenzocorso.carsharing.rentservice.domain.ports.in.RentVehicle; +import it.vincenzocorso.carsharing.rentservice.domain.ports.in.SearchRent; import it.vincenzocorso.carsharing.rentservice.domain.ports.out.RentRepository; import jakarta.transaction.Transactional; import lombok.AllArgsConstructor; @@ -16,7 +16,7 @@ import java.util.List; @AllArgsConstructor -public class RentService implements RentVehicleUseCase, SearchRentUseCase { +public class RentService implements RentVehicle, SearchRent { public static final String EVENTS_CHANNEL = "rent-service-events"; private final RentRepository rentRepository; private final DomainEventProducer domainEventProducer; diff --git a/rent-service/src/main/java/it/vincenzocorso/carsharing/rentservice/domain/ports/in/RentVehicleUseCase.java b/rent-service/src/main/java/it/vincenzocorso/carsharing/rentservice/domain/ports/in/RentVehicle.java similarity index 98% rename from rent-service/src/main/java/it/vincenzocorso/carsharing/rentservice/domain/ports/in/RentVehicleUseCase.java rename to rent-service/src/main/java/it/vincenzocorso/carsharing/rentservice/domain/ports/in/RentVehicle.java index 4dc9514..6f3cbfa 100644 --- a/rent-service/src/main/java/it/vincenzocorso/carsharing/rentservice/domain/ports/in/RentVehicleUseCase.java +++ b/rent-service/src/main/java/it/vincenzocorso/carsharing/rentservice/domain/ports/in/RentVehicle.java @@ -2,7 +2,7 @@ import it.vincenzocorso.carsharing.rentservice.domain.models.Rent; -public interface RentVehicleUseCase { +public interface RentVehicle { /** * Creates a new rent * @param customerId The id of the customer that started the rent diff --git a/rent-service/src/main/java/it/vincenzocorso/carsharing/rentservice/domain/ports/in/SearchRentUseCase.java b/rent-service/src/main/java/it/vincenzocorso/carsharing/rentservice/domain/ports/in/SearchRent.java similarity index 95% rename from rent-service/src/main/java/it/vincenzocorso/carsharing/rentservice/domain/ports/in/SearchRentUseCase.java rename to rent-service/src/main/java/it/vincenzocorso/carsharing/rentservice/domain/ports/in/SearchRent.java index a2d934e..626e30f 100644 --- a/rent-service/src/main/java/it/vincenzocorso/carsharing/rentservice/domain/ports/in/SearchRentUseCase.java +++ b/rent-service/src/main/java/it/vincenzocorso/carsharing/rentservice/domain/ports/in/SearchRent.java @@ -5,7 +5,7 @@ import java.util.List; -public interface SearchRentUseCase { +public interface SearchRent { /** * Gets all the rents with the given criteria * @param criteria The search criteria. Null attributes are not considered diff --git a/rent-service/src/test/java/it/vincenzocorso/carsharing/rentservice/adapters/web/RentControllerTest.java b/rent-service/src/test/java/it/vincenzocorso/carsharing/rentservice/adapters/web/RentControllerTest.java index 5d9c76e..4fb0a99 100644 --- a/rent-service/src/test/java/it/vincenzocorso/carsharing/rentservice/adapters/web/RentControllerTest.java +++ b/rent-service/src/test/java/it/vincenzocorso/carsharing/rentservice/adapters/web/RentControllerTest.java @@ -5,8 +5,8 @@ import it.vincenzocorso.carsharing.rentservice.domain.exceptions.RentNotFoundException; import it.vincenzocorso.carsharing.rentservice.domain.models.RentState; import it.vincenzocorso.carsharing.rentservice.domain.models.SearchRentCriteria; -import it.vincenzocorso.carsharing.rentservice.domain.ports.in.RentVehicleUseCase; -import it.vincenzocorso.carsharing.rentservice.domain.ports.in.SearchRentUseCase; +import it.vincenzocorso.carsharing.rentservice.domain.ports.in.RentVehicle; +import it.vincenzocorso.carsharing.rentservice.domain.ports.in.SearchRent; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; @@ -35,15 +35,15 @@ class RentControllerTest { private ObjectMapper objectMapper; @MockBean - private RentVehicleUseCase rentVehicleUseCase; + private RentVehicle rentVehicle; @MockBean - private SearchRentUseCase searchRentUseCase; + private SearchRent searchRent; @ParameterizedTest @ValueSource(strings = {"", "?limit=150", "?offset=0", "?states=PENDING,REJECTED,ACCEPTED,STARTED,ENDED"}) void shouldGetRents(String queryParameters) throws Exception { - when(this.searchRentUseCase.getRents(any(SearchRentCriteria.class))).thenReturn(List.of(RENT)); + when(this.searchRent.getRents(any(SearchRentCriteria.class))).thenReturn(List.of(RENT)); this.mockMvc.perform(get("/rents" + queryParameters)) .andExpect(status().isOk()) @@ -70,7 +70,7 @@ void shouldNotGetRentsWhenCriteriaAreNotValid(String queryParameters) throws Exc @Test void shouldGetRent() throws Exception { - when(this.searchRentUseCase.getRent(RENT_ID)).thenReturn(RENT); + when(this.searchRent.getRent(RENT_ID)).thenReturn(RENT); this.mockMvc.perform(get("/rents/" + RENT_ID)) .andExpect(status().isOk()) @@ -86,7 +86,7 @@ void shouldGetRent() throws Exception { @Test void shouldNotGetRent() throws Exception { - when(this.searchRentUseCase.getRent(RENT_ID)).thenThrow(RentNotFoundException.class); + when(this.searchRent.getRent(RENT_ID)).thenThrow(RentNotFoundException.class); this.mockMvc.perform(get("/rents/" + RENT_ID)) .andExpect(status().isNotFound()) @@ -96,7 +96,7 @@ void shouldNotGetRent() throws Exception { @Test void shouldCreateRent() throws Exception { String request = this.objectMapper.writeValueAsString(new CreateRentRequest(CUSTOMER_ID, VEHICLE_ID)); - when(this.rentVehicleUseCase.createRent(CUSTOMER_ID, VEHICLE_ID)).thenReturn(rentInState(RentState.PENDING)); + when(this.rentVehicle.createRent(CUSTOMER_ID, VEHICLE_ID)).thenReturn(rentInState(RentState.PENDING)); this.mockMvc.perform(post("/rents").content(request).contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isCreated()) @@ -113,7 +113,7 @@ void shouldCreateRent() throws Exception { @ParameterizedTest @ValueSource(strings = {"", "{}"}) void shouldNotCreateRentWhenRequestBodyIsNotValid(String request) throws Exception { - when(this.rentVehicleUseCase.createRent(CUSTOMER_ID, VEHICLE_ID)).thenThrow(RentNotFoundException.class); + when(this.rentVehicle.createRent(CUSTOMER_ID, VEHICLE_ID)).thenThrow(RentNotFoundException.class); this.mockMvc.perform(post("/rents").content(request).contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isBadRequest())