I am trying to understand which of the following two options is the right approach and why.
Say we have GetHotelInfo(hotel_id)
API that is being invoked from the Web till the Controller.
The logic of the GetHotelInfo is:
- Invoke
GetHotelPropertyData()
(Location, facilities…) - Invoke
GetHotelPrice(hotel_id, dates…)
- Invoke
GetHotelReviews(hotel_id)
Once all results come back, process and merge the data and return 1 object that contains all relevant data of the hotel.
Option 1:
Create 3 different repositories (HotelPropertyRepo, HotelPriceRepo, HotelReviewsRepo)
Create GetHotelInfo usecase that will use these 3 repositories and return the final result.
Option 2:
Create 3 different repositories (HotelPropertyRepo, HotelPriceRepo, HotelReviewsRepo)
Create 3 different usecases (GetHotelPropertyDataUseCase, GetHotelPriceUseCase, GetHotelReviewsUseCase)
Create GetHotelInfoUseCase that will orchestrate the previous 3 usecases. (It can also be a controller, but that’s a different topic)
Let’s say that right now only GetHotelInfo
is being exposed to the Web but maybe in the future, I will expose some of the inner requests as well.
And would the answer be different if the actual logic of GetHotelInfo is not a combination of 3 endpoints but rather 10?