Skip to content

Commit

Permalink
[fix/restaurant_related_action]: 홈 추천 식당 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
dogdduddy authored and Jim-swit committed Mar 16, 2024
1 parent 2ced50c commit 49cf684
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ interface RestaurantDataSource {

suspend fun getRegisteredRestaurantsBySearch(keyword: String?, userLocation: Location?): Flow<PagingData<RegisteredRestaurantResponse>>

suspend fun getRegisteredRestaurantByMapWithLimitCount(sortType: SortType, currentGroup: Group?): List<RegisteredRestaurantResponse>

suspend fun getRegisteredRestaurantsBySearchWithLimitCount(keyword: String?, userLocation: Location?, limit: Int): List<RegisteredRestaurantResponse>

suspend fun getRestaurantReviews(restaurantId: Int): ReviewPaging
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,20 @@ class RestaurantDataSourceImpl @Inject constructor(
}.flow.cachedIn(coroutineScope)
}

override suspend fun getRegisteredRestaurantByMapWithLimitCount(
sortType: SortType,
currentGroup: Group?
): List<RegisteredRestaurantResponse> {
return restaurantAPI.getRestaurantLocationInfoByMap(
page = 1,
size = 3,
sort = sortType.key,
RestaurantSearchRequest(
groupId = currentGroup?.groupId
)
).data.restaurants
}

override suspend fun getRegisteredRestaurantsBySearchWithLimitCount(
keyword: String?,
userLocation: Location?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,33 @@ class RestaurantRepositoryImpl @Inject constructor(
}
}

override suspend fun getRegisteredRestaurantByMapWithLimitCount(
sortType: SortType,
currentGroup: Group?
): List<RegisteredRestaurant> {
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<Review> {
return restaurantDataSource.getRestaurantReviews(restaurantId).reviewList

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ interface RestaurantRepository {

suspend fun getRegisteredRestaurantsBySearch(keyword: String?, userLocation: Location?): Flow<PagingData<RegisteredRestaurant>>

suspend fun getRegisteredRestaurantByMapWithLimitCount(
sortType: SortType,currentGroup: Group?
): List<RegisteredRestaurant>

suspend fun getRestaurantReviews(restaurantId: Int): List<Review>

suspend fun getRegisteredRestaurantsBySearchWithLimitCount(keyword: String?, userLocation: Location?, limit: Int): List<RegisteredRestaurant>
Expand Down
Original file line number Diff line number Diff line change
@@ -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<RegisteredRestaurant> {
return restaurantRepository.getRegisteredRestaurantByMapWithLimitCount(sortType, group)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -157,6 +159,10 @@ class HomeViewModel @Inject constructor(
}.cachedIn(viewModelScope)
}

suspend fun getRestaurantMapWithLimitCount(sortType: SortType, group: Group?): List<RegisteredRestaurant> {
return getRestaurantMapWithLimitCountUseCase(sortType, group)
}

suspend fun getMyGroup(): List<Group> {
return getMyGroupUseCase()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 49cf684

Please sign in to comment.