Skip to content

Commit

Permalink
Merge pull request #92 from everymeals/feature/get_detail_restaurant
Browse files Browse the repository at this point in the history
[feature/get_detail_restaurant] 식당 상세화면 api 연결
  • Loading branch information
SsongSik authored Jan 28, 2024
2 parents 5a05a02 + 9518059 commit b7fbbb7
Show file tree
Hide file tree
Showing 14 changed files with 296 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ interface RestaurantDataSource {
group: String? = null,
grade: String? = null,
): Flow<PagingData<RestaurantResponse>>

suspend fun getRestaurantDetail(index: Int): Result<RestaurantResponse>
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.PagingData
import com.everymeal.data.model.restaruant.RestaurantResponse
import com.everymeal.data.model.unwrapData
import com.everymeal.data.service.restaurant.RestaurantApi
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject
Expand All @@ -30,4 +31,8 @@ class RestaurantDataSourceImpl @Inject constructor(
pagingSourceFactory = pagingSourceFactory
).flow
}

override suspend fun getRestaurantDetail(index: Int): Result<RestaurantResponse> {
return runCatching { restaurantApi.getRestaurantDetail(index) }.unwrapData()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ class RestaurantRepositoryImpl @Inject constructor(
pagingData.map { it.toEntity() }
}
}

override suspend fun getRestaurantDetail(index: Int): Result<RestaurantDataEntity> {
return restaurantDataSource.getRestaurantDetail(index).map { it.toEntity() }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.everymeal.data.service.restaurant

import com.everymeal.data.model.BaseResponse
import com.everymeal.data.model.restaruant.GetUnivRestaurantResponse
import com.everymeal.data.model.restaruant.RestaurantResponse
import retrofit2.http.GET
import retrofit2.http.Path
import retrofit2.http.Query
Expand All @@ -17,4 +18,9 @@ interface RestaurantApi {
@Query("group") group: String? = null,
@Query("grade") grade: String? = null,
): BaseResponse<GetUnivRestaurantResponse>

@GET("/api/v1/stores/{index}")
suspend fun getRestaurantDetail(
@Path("index") index: Int
): BaseResponse<RestaurantResponse>
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ interface RestaurantRepository {
group: String? = null,
grade: String? = null,
) : Flow<PagingData<RestaurantDataEntity>>

suspend fun getRestaurantDetail(
index: Int
) : Result<RestaurantDataEntity>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.everymeal.domain.usecase.restaurant

import com.everymeal.domain.model.restaurant.RestaurantDataEntity
import com.everymeal.domain.repository.restaurant.RestaurantRepository
import javax.inject.Inject

class GetDetailRestaurantUseCase @Inject constructor(
private val restaurantRepository: RestaurantRepository
) {
suspend operator fun invoke(
restaurantIdx: Int,
) : Result<RestaurantDataEntity> {
return restaurantRepository.getRestaurantDetail(restaurantIdx)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import com.everymeal.presentation.ui.theme.Gray700
fun EveryMealRestaurantItem(
restaurant: RestaurantDataEntity,
onLoveClick: () -> Unit = {},
onDetailClick: () -> Unit = {},
onDetailClick: (Int) -> Unit = {},
) {
Column(
modifier = Modifier
Expand All @@ -52,7 +52,7 @@ fun EveryMealRestaurantItem(
indication = null,
interactionSource = remember { MutableInteractionSource() }
) {
onDetailClick()
onDetailClick(restaurant.idx)
}
.padding(horizontal = 20.dp)
.background(color = Color.White)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ class DetailContract {
data class OnClickRating(val rating: Int) : DetailEvent()
object OnDeleteClickRestaurantCategoryType : DetailEvent()
object OnDeleteClickRating : DetailEvent()
data class OnRestaurantDetailClick(val restaurantId: Int) : DetailEvent()
}

sealed class DetailEffect : ViewSideEffect {

data class OnRestaurantClickEffect(val restaurantId: Int) : DetailEffect()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import com.everymeal.presentation.components.EveryMealReportBottomSheetDialog
import com.everymeal.presentation.components.EveryMealRestaurantItem
import com.everymeal.presentation.components.EveryMealSortCategoryBottomSheetDialog
import com.everymeal.presentation.ui.save.SaveTopBar
import com.everymeal.presentation.ui.signup.UnivSelectContract
import com.everymeal.presentation.ui.theme.Grey2
import com.everymeal.presentation.ui.theme.Grey7
import com.everymeal.presentation.ui.theme.Main100
Expand All @@ -52,6 +53,7 @@ fun DetailListScreen(
detailListViewModel: DetailListViewModel = hiltViewModel(),
title: String,
navigateToPreviousScreen: () -> Unit,
onDetailRestaurantClick: (Int) -> Unit = {}
) {
val detailListViewState by detailListViewModel.viewState.collectAsState()

Expand All @@ -61,6 +63,16 @@ fun DetailListScreen(
detailListViewModel.setEvent(DetailContract.DetailEvent.InitDetailScreen)
}

LaunchedEffect(key1 = detailListViewModel.effect) {
detailListViewModel.effect.collect { effect ->
when(effect) {
is DetailContract.DetailEffect.OnRestaurantClickEffect -> {
onDetailRestaurantClick(effect.restaurantId)
}
}
}
}

if(detailListViewState.sortBottomSheetState) {
EveryMealSortCategoryBottomSheetDialog(
detailListViewState.detailSortCategoryType.title(),
Expand Down Expand Up @@ -190,6 +202,9 @@ fun DetailListScreen(
item?.let {
EveryMealRestaurantItem(
restaurant = it,
onDetailClick = { restaurantIdx ->
detailListViewModel.setEvent(DetailContract.DetailEvent.OnRestaurantDetailClick(restaurantIdx))
}
)
Spacer(modifier = Modifier.padding(16.dp))
}
Expand Down Expand Up @@ -275,7 +290,12 @@ fun DetailScreenChip(
@Preview
@Composable
fun PreviewDetailListScreen() {
DetailListScreen(title = "맛집") {
DetailListScreen(
title = "맛집",
navigateToPreviousScreen = {

},
) {

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.everymeal.presentation.base.BaseViewModel
import com.everymeal.presentation.ui.detail.DetailContract.DetailEvent
import com.everymeal.presentation.ui.detail.DetailContract.DetailState
import com.everymeal.presentation.ui.detail.DetailContract.DetailEffect
import com.everymeal.presentation.ui.signup.UnivSelectContract
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
Expand Down Expand Up @@ -87,6 +88,9 @@ class DetailListViewModel @Inject constructor(
)
getRestaurantList()
}
is DetailEvent.OnRestaurantDetailClick -> {
sendEffect({ DetailEffect.OnRestaurantClickEffect(event.restaurantId) })
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.everymeal.presentation.ui.univfood.UnivFoodScreen
import com.everymeal.presentation.ui.whatfood.WhatFoodScreen

const val DETAIL_SCREEN_TYPE = "detailScreenType"
const val DETAIL_RESTAURANT_IDX = "detailRestaurantIdx"

@Composable
fun MainScreen(
Expand Down Expand Up @@ -78,11 +79,17 @@ fun MainScreen(
val detailScreenType = it.arguments?.getString(DETAIL_SCREEN_TYPE) ?: ""
DetailListScreen(
title = detailScreenType,
navigateToPreviousScreen = { navController.popBackStack() }
navigateToPreviousScreen = { navController.popBackStack() },
onDetailRestaurantClick = { detailRestaurantIdx ->
navController.navigate(EveryMealRoute.DETAIL_RESTAURANT.route.plus("/$detailRestaurantIdx"))
}
)
}
composable(route = EveryMealRoute.DETAIL_RESTAURANT.route) {
DetailRestaurantScreen()
composable(route = EveryMealRoute.DETAIL_RESTAURANT.route.plus("/{$DETAIL_RESTAURANT_IDX}")) {
val detailRestaurantIdx = it.arguments?.getString(DETAIL_RESTAURANT_IDX) ?: ""
DetailRestaurantScreen(detailRestaurantIdx.toInt()) {
navController.popBackStack()
}
}
composable(route = EveryMealRoute.SCHOOL_AUTH.route) {
SchoolAuthScreen(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,39 @@
package com.everymeal.presentation.ui.restaurant

import com.everymeal.domain.model.restaurant.RestaurantDataEntity
import com.everymeal.presentation.base.LoadState
import com.everymeal.presentation.base.ViewEvent
import com.everymeal.presentation.base.ViewSideEffect
import com.everymeal.presentation.base.ViewState
import com.everymeal.presentation.ui.signup.UnivSelectContract


data class DetailRestaurantState(
val uiState: LoadState = LoadState.SUCCESS,
val selectedTabIndex: Int = 0,
val isFabClicked: Boolean = false,
val getDetailRestaurantState: LoadState = LoadState.LOADING,
val restaurantInfo: RestaurantDataEntity = RestaurantDataEntity(
idx = 0,
name = "",
address = "",
phoneNumber = "",
categoryDetail = "",
distance = 0,
grade = 0f,
reviewCount = 0,
recommendedCount = 0,
images = null,
isLiked = false
),
val networkErrorDialog: Boolean = true,
) : ViewState

sealed class DetailRestaurantEvent : ViewEvent {
data class OnTabSelectedChanged(val selectedTabIndex: Int) : DetailRestaurantEvent()
data class OnFloatingButtonClick(val isFabClicked: Boolean) : DetailRestaurantEvent()
data class InitDetailRestaurantScreen(val restaurantId: Int) : DetailRestaurantEvent()
data class NetworkErrorDialogClicked(val dialogStateChange: Boolean) : DetailRestaurantEvent()
}

sealed class DetailRestaurantEffect : ViewSideEffect {
Expand Down
Loading

0 comments on commit b7fbbb7

Please sign in to comment.