From 49cf68487de1228fb3c2a1edf539eeefb32d329d Mon Sep 17 00:00:00 2001 From: swit-jim Date: Sun, 17 Mar 2024 00:33:31 +0900 Subject: [PATCH] =?UTF-8?q?[fix/restaurant=5Frelated=5Faction]:=20?= =?UTF-8?q?=ED=99=88=20=EC=B6=94=EC=B2=9C=20=EC=8B=9D=EB=8B=B9=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/datasource/RestaurantDataSource.kt | 2 + .../datasource/RestaurantDataSourceImpl.kt | 14 +++++++ .../repository/RestaurantRepositoryImpl.kt | 27 ++++++++++++ .../domain/repository/RestaurantRepository.kt | 4 ++ .../GetRestaurantMapWithLimitCountUseCase.kt | 19 +++++++++ .../presentation/view/home/HomeFragment.kt | 42 ++++++++----------- .../presentation/view/home/HomeViewModel.kt | 6 +++ .../item_recommend_popular_restaurant.xml | 2 +- 8 files changed, 91 insertions(+), 25 deletions(-) create mode 100644 domain/src/main/java/org/gdsc/domain/usecase/GetRestaurantMapWithLimitCountUseCase.kt diff --git a/data/src/main/java/org/gdsc/data/datasource/RestaurantDataSource.kt b/data/src/main/java/org/gdsc/data/datasource/RestaurantDataSource.kt index 597b23df..3a953448 100644 --- a/data/src/main/java/org/gdsc/data/datasource/RestaurantDataSource.kt +++ b/data/src/main/java/org/gdsc/data/datasource/RestaurantDataSource.kt @@ -51,6 +51,8 @@ interface RestaurantDataSource { suspend fun getRegisteredRestaurantsBySearch(keyword: String?, userLocation: Location?): Flow> + suspend fun getRegisteredRestaurantByMapWithLimitCount(sortType: SortType, currentGroup: Group?): List + suspend fun getRegisteredRestaurantsBySearchWithLimitCount(keyword: String?, userLocation: Location?, limit: Int): List suspend fun getRestaurantReviews(restaurantId: Int): ReviewPaging diff --git a/data/src/main/java/org/gdsc/data/datasource/RestaurantDataSourceImpl.kt b/data/src/main/java/org/gdsc/data/datasource/RestaurantDataSourceImpl.kt index acac844c..14c48b39 100644 --- a/data/src/main/java/org/gdsc/data/datasource/RestaurantDataSourceImpl.kt +++ b/data/src/main/java/org/gdsc/data/datasource/RestaurantDataSourceImpl.kt @@ -261,6 +261,20 @@ class RestaurantDataSourceImpl @Inject constructor( }.flow.cachedIn(coroutineScope) } + override suspend fun getRegisteredRestaurantByMapWithLimitCount( + sortType: SortType, + currentGroup: Group? + ): List { + return restaurantAPI.getRestaurantLocationInfoByMap( + page = 1, + size = 3, + sort = sortType.key, + RestaurantSearchRequest( + groupId = currentGroup?.groupId + ) + ).data.restaurants + } + override suspend fun getRegisteredRestaurantsBySearchWithLimitCount( keyword: String?, userLocation: Location?, diff --git a/data/src/main/java/org/gdsc/data/repository/RestaurantRepositoryImpl.kt b/data/src/main/java/org/gdsc/data/repository/RestaurantRepositoryImpl.kt index 24616acd..86ebf3fd 100644 --- a/data/src/main/java/org/gdsc/data/repository/RestaurantRepositoryImpl.kt +++ b/data/src/main/java/org/gdsc/data/repository/RestaurantRepositoryImpl.kt @@ -171,6 +171,33 @@ class RestaurantRepositoryImpl @Inject constructor( } } + override suspend fun getRegisteredRestaurantByMapWithLimitCount( + sortType: SortType, + currentGroup: Group? + ): List { + return restaurantDataSource.getRegisteredRestaurantByMapWithLimitCount(sortType, currentGroup) + .map { restaurant -> + RegisteredRestaurant( + id = restaurant.id, + name = restaurant.name, + placeUrl = restaurant.placeUrl, + phone = restaurant.phone, + address = restaurant.address, + roadAddress = restaurant.roadAddress, + x = restaurant.x, + y = restaurant.y, + restaurantImageUrl = restaurant.restaurantImageUrl, + introduce = restaurant.introduce, + category = restaurant.category, + userId = restaurant.id, + userNickName = restaurant.userNickName, + userProfileImageUrl = restaurant.userProfileImageUrl, + canDrinkLiquor = restaurant.canDrinkLiquor, + differenceInDistance = restaurant.differenceInDistance, + ) + } + } + override suspend fun getRestaurantReviews(restaurantId: Int): List { return restaurantDataSource.getRestaurantReviews(restaurantId).reviewList diff --git a/domain/src/main/java/org/gdsc/domain/repository/RestaurantRepository.kt b/domain/src/main/java/org/gdsc/domain/repository/RestaurantRepository.kt index 4288c294..ee95ac9e 100644 --- a/domain/src/main/java/org/gdsc/domain/repository/RestaurantRepository.kt +++ b/domain/src/main/java/org/gdsc/domain/repository/RestaurantRepository.kt @@ -50,6 +50,10 @@ interface RestaurantRepository { suspend fun getRegisteredRestaurantsBySearch(keyword: String?, userLocation: Location?): Flow> + suspend fun getRegisteredRestaurantByMapWithLimitCount( + sortType: SortType,currentGroup: Group? + ): List + suspend fun getRestaurantReviews(restaurantId: Int): List suspend fun getRegisteredRestaurantsBySearchWithLimitCount(keyword: String?, userLocation: Location?, limit: Int): List diff --git a/domain/src/main/java/org/gdsc/domain/usecase/GetRestaurantMapWithLimitCountUseCase.kt b/domain/src/main/java/org/gdsc/domain/usecase/GetRestaurantMapWithLimitCountUseCase.kt new file mode 100644 index 00000000..a25698e3 --- /dev/null +++ b/domain/src/main/java/org/gdsc/domain/usecase/GetRestaurantMapWithLimitCountUseCase.kt @@ -0,0 +1,19 @@ +package org.gdsc.domain.usecase + +import org.gdsc.domain.SortType +import org.gdsc.domain.model.RegisteredRestaurant +import org.gdsc.domain.model.request.RestaurantSearchRequest +import org.gdsc.domain.model.response.Group +import org.gdsc.domain.repository.RestaurantRepository +import javax.inject.Inject + +class GetRestaurantMapWithLimitCountUseCase @Inject constructor( + private val restaurantRepository: RestaurantRepository +) { + suspend operator fun invoke( + sortType: SortType, + group: Group?, + ): List { + return restaurantRepository.getRegisteredRestaurantByMapWithLimitCount(sortType, group) + } +} \ No newline at end of file diff --git a/presentation/src/main/java/org/gdsc/presentation/view/home/HomeFragment.kt b/presentation/src/main/java/org/gdsc/presentation/view/home/HomeFragment.kt index b1d283b4..dcb0bc04 100644 --- a/presentation/src/main/java/org/gdsc/presentation/view/home/HomeFragment.kt +++ b/presentation/src/main/java/org/gdsc/presentation/view/home/HomeFragment.kt @@ -82,17 +82,6 @@ class HomeFragment : Fragment(), ViewHolderBindListener { } } - // TODO : titleAdapter 문구 정리 필요 - private val recommendPopularRestaurantTitleAdapter by lazy { - RecommendPopularRestaurantTitleAdapter( - "그룹에서 인기가 많아요" - ) - } - private val recommendPopularRestaurantWrapperAdapter by lazy { - RecommendPopularRestaurantWrapperAdapter( - recommendPopularRestaurantList - ) - } private val restaurantFilterAdapter by lazy { RestaurantFilterAdapter(this) } private val restaurantListAdapter by lazy { MapMarkerWithRestaurantsAdatper(this) } private val mapMarkerAdapter by lazy { MapMarkerWithRestaurantsAdatper(this) } @@ -120,19 +109,10 @@ class HomeFragment : Fragment(), ViewHolderBindListener { setMap(savedInstanceState) observeState() - concatAdapter = if (recommendPopularRestaurantList.isNotEmpty()) { - ConcatAdapter( - recommendPopularRestaurantTitleAdapter, - recommendPopularRestaurantWrapperAdapter, - restaurantFilterAdapter, - restaurantListAdapter - ) - } else { - ConcatAdapter( - restaurantFilterAdapter, - restaurantListAdapter - ) - } + concatAdapter = ConcatAdapter( + restaurantFilterAdapter, + restaurantListAdapter + ) setRestaurantListBottomSheet() setGroup() @@ -438,6 +418,20 @@ class HomeFragment : Fragment(), ViewHolderBindListener { } } + lifecycleScope.launch { + val data = viewModel.getRestaurantMapWithLimitCount(SortType.DISTANCE, viewModel.currentGroup.value) + + if (data.isNullOrEmpty().not()) { + + // TODO : titleAdapter 문구 정리 필요 + val recommendPopularRestaurantTitleAdapter = RecommendPopularRestaurantTitleAdapter("그룹에서 인기가 많아요") + val recommendPopularRestaurantWrapperAdapter = RecommendPopularRestaurantWrapperAdapter(data) + + concatAdapter.addAdapter(0, recommendPopularRestaurantTitleAdapter) + concatAdapter.addAdapter(1, recommendPopularRestaurantWrapperAdapter) + } + } + repeatWhenUiStarted { viewModel.setSortType(SortType.DISTANCE) } diff --git a/presentation/src/main/java/org/gdsc/presentation/view/home/HomeViewModel.kt b/presentation/src/main/java/org/gdsc/presentation/view/home/HomeViewModel.kt index 0c9bcda7..21819f81 100644 --- a/presentation/src/main/java/org/gdsc/presentation/view/home/HomeViewModel.kt +++ b/presentation/src/main/java/org/gdsc/presentation/view/home/HomeViewModel.kt @@ -23,6 +23,7 @@ import org.gdsc.domain.model.RegisteredRestaurant import org.gdsc.domain.model.ScreenLocation import org.gdsc.domain.model.response.Group import org.gdsc.domain.usecase.GetMyGroupUseCase +import org.gdsc.domain.usecase.GetRestaurantMapWithLimitCountUseCase import org.gdsc.domain.usecase.GetRestaurantsByMapUseCase import org.gdsc.domain.usecase.PostSelectGroupUseCase import org.gdsc.presentation.JmtLocationManager @@ -35,6 +36,7 @@ class HomeViewModel @Inject constructor( private val getRestaurantsByMapUseCase: GetRestaurantsByMapUseCase, private val getMyGroupUseCase: GetMyGroupUseCase, private val postSelectGroupUserCase: PostSelectGroupUseCase, + private val getRestaurantMapWithLimitCountUseCase: GetRestaurantMapWithLimitCountUseCase, ) : ViewModel() { suspend fun getCurrentLocation() = locationManager.getCurrentLocation() @@ -157,6 +159,10 @@ class HomeViewModel @Inject constructor( }.cachedIn(viewModelScope) } + suspend fun getRestaurantMapWithLimitCount(sortType: SortType, group: Group?): List { + return getRestaurantMapWithLimitCountUseCase(sortType, group) + } + suspend fun getMyGroup(): List { return getMyGroupUseCase() } diff --git a/presentation/src/main/res/layout/item_recommend_popular_restaurant.xml b/presentation/src/main/res/layout/item_recommend_popular_restaurant.xml index afdac7ca..4a3620bd 100644 --- a/presentation/src/main/res/layout/item_recommend_popular_restaurant.xml +++ b/presentation/src/main/res/layout/item_recommend_popular_restaurant.xml @@ -10,7 +10,7 @@ android:layout_width="250dp" android:layout_height="225dp" android:clipToOutline="true" - android:elevation="6dp" + android:elevation="2dp" android:layout_marginStart="@dimen/half_spacing" android:layout_marginEnd="30dp" android:layout_marginTop="@dimen/layout_margin_spacing"