Skip to content

Commit

Permalink
#9 [chore] : 리뷰 반영, 홈 api 연결, 의존성 주입, null처리
Browse files Browse the repository at this point in the history
  • Loading branch information
serioushyeon committed Nov 28, 2024
1 parent ce1a4d6 commit c510d20
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import com.example.market_kurly.domain.repository.WishListRepository
import com.example.market_kurly.domain.repositoryimpl.ReviewRepositoryImpl
import com.example.market_kurly.domain.repositoryimpl.WishListRepositoryImpl
import com.example.market_kurly.domain.repository.ProductsRepository
import com.example.market_kurly.domain.repositoryimpl.GoodsRepositoryImpl
import com.example.market_kurly.domain.repositoryimpl.LikeRepositoryImpl
import com.example.market_kurly.feature.ExampleViewModel
import com.example.market_kurly.feature.goods.viewmodel.GoodsViewModel
import com.example.market_kurly.feature.review.ReviewViewModel
Expand All @@ -21,7 +23,7 @@ class BaseViewModelFactory(
private val exampleRepository: ExampleRepository? = null,
private val goodsRepository: GoodsRepository? = null,
private val likeRepository: LikeRepository? = null,
private val productsRepository: ProductsRepository? = null
private val productsRepository: ProductsRepository? = null,
private val reviewRepository: ReviewRepository? = null,
private val wishListRepository: WishListRepository ?= null
) : ViewModelProvider.Factory {
Expand All @@ -34,14 +36,10 @@ class BaseViewModelFactory(

modelClass.isAssignableFrom(GoodsViewModel::class.java) -> {
@Suppress("UNCHECKED_CAST")
goodsRepository?.let {
likeRepository?.let {
GoodsViewModel(
goodsRepository = goodsRepository,
likeRepository = likeRepository
)
}
} as T
GoodsViewModel(
goodsRepository ?: GoodsRepositoryImpl(ServicePool.goodsService),
likeRepository ?: LikeRepositoryImpl(ServicePool.likeService)
) as T
}
modelClass.isAssignableFrom(HomeViewModel::class.java) -> {
@Suppress("UNCHECKED_CAST")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ object KeyStorage {
const val STAR_MAX_COUNT = 5

// Response null 대체 문자열
const val EMPTY_RESPONSE = "0"
const val EMPTY_RESPONSE = ""

// GoodsDetail Tab 요소 상수화
const val GOODS_DETAIL = "상품설명"
Expand All @@ -39,7 +39,6 @@ object KeyStorage {
const val ALLERGY = "알레르기정보"
const val BRIX = "당도"
const val EXPIRATION = "소비기한(또는 유통기한)정보"
const val LIVESTOCK = "축산물 이력정보"
const val NOTIFICATION = "안내사항"
const val PACKAGING_TYPE = "포장타입"
const val SELLING_UNIT = "판매단위"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.example.market_kurly.data.dto.response
import kotlinx.serialization.Serializable


//TODO: 서버쌤들이 null 반환 고쳐주면 수정 필요
@Serializable
data class ResponseGoodsDetailDto(
val name: String,
Expand All @@ -19,7 +18,7 @@ data class ResponseGoodsDetailDto(
val packagingType: String,
val sellingUnit: String,
val weight: String,
val expiration: String? = null,
val expiration: String,
val brix: Float? = null,
val notification: String,
val category: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.market_kurly.data.mapper

import com.example.market_kurly.core.util.KeyStorage
import com.example.market_kurly.data.dto.response.ResponseGoodsDetailDto
import com.example.market_kurly.domain.model.GoodsInfoData
import com.example.market_kurly.domain.model.GoodsUiData
Expand All @@ -17,7 +18,7 @@ fun ResponseGoodsDetailDto.toGoodsUiData() = GoodsUiData(
isInterest = this.isInterest,
infoData = GoodsInfoData(
allergy = this.allergy,
brix = this.brix,
brix = brix?.toString() ?: KeyStorage.EMPTY_RESPONSE,
expiration = this.expiration,
notification = this.notification,
packagingType = this.packagingType,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.example.market_kurly.domain.model

//TODO: 서버쌤들이 null 반환 고쳐주면 수정 필요
data class GoodsUiData(
val deliverType: String,
val discount: Int,
Expand All @@ -17,8 +16,8 @@ data class GoodsUiData(
)
data class GoodsInfoData(
val allergy: String,
val brix: Float?,
val expiration: String?,
val brix: String,
val expiration: String,
val notification: String,
val packagingType: String,
val sellingUnit: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,15 @@ import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.ui.Modifier
import androidx.navigation.compose.rememberNavController
import com.example.market_kurly.core.base.BaseViewModelFactory
import com.example.market_kurly.data.ServicePool
import com.example.market_kurly.domain.repositoryimpl.ExampleRepositoryImpl
import com.example.market_kurly.domain.repositoryimpl.GoodsRepositoryImpl
import com.example.market_kurly.domain.repositoryimpl.LikeRepositoryImpl
import com.example.market_kurly.feature.goods.viewmodel.GoodsViewModel
import com.example.market_kurly.feature.nav.NavGraph
import com.example.market_kurly.ui.theme.MARKETKURLYTheme

class MainActivity : ComponentActivity() {

private val exampleRepository by lazy { ExampleRepositoryImpl(ServicePool.exampleService) }
private val goodsRepository by lazy { GoodsRepositoryImpl(ServicePool.goodsService) }
private val likeRepository by lazy { LikeRepositoryImpl(ServicePool.likeService) }

private val viewModelFactory by lazy {
BaseViewModelFactory(
exampleRepository = exampleRepository,
goodsRepository = goodsRepository,
likeRepository = likeRepository)
}

private val exampleViewModel: ExampleViewModel by viewModels { viewModelFactory }
private val goodsViewModel: GoodsViewModel by viewModels { viewModelFactory }

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
Expand All @@ -45,10 +23,7 @@ class MainActivity : ComponentActivity() {
color = MaterialTheme.colorScheme.background,
) {
val navController = rememberNavController()
NavGraph(
navController = navController,
goodsViewModel = goodsViewModel,
)
NavGraph(navController = navController)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavHostController
import coil.compose.AsyncImage
import coil.request.ImageRequest
import com.example.market_kurly.R
import com.example.market_kurly.core.base.BaseViewModelFactory
import com.example.market_kurly.core.designsystem.component.KurlyGoodsDetailBottomBar
import com.example.market_kurly.core.designsystem.component.KurlyGoodsDetailTopBar
import com.example.market_kurly.core.util.KeyStorage.EMPTY_RESPONSE
Expand All @@ -64,18 +66,20 @@ import kotlinx.coroutines.launch
@Composable
fun GoodsScreen(
navController: NavHostController,
viewModel: GoodsViewModel
productId: Int,
) {
val context = LocalContext.current

val viewModel: GoodsViewModel = viewModel(factory = BaseViewModelFactory())

val uiState by viewModel.uiState.collectAsStateWithLifecycle()

val snackbarHostState = remember { SnackbarHostState() }

//TODO: 홈에서 productId 넘겨받아야함
val memberId = 1

LaunchedEffect(true) {
viewModel.getGoodsDetailData(5, 1)
viewModel.getGoodsDetailData(productId, memberId)
}
LaunchedEffect(Unit) {
launch {
Expand Down Expand Up @@ -120,12 +124,11 @@ fun GoodsScreen(
},
)
},
//TODO: 홈에서 productId 넘겨받아야함
bottomBar = {
KurlyGoodsDetailBottomBar(
modifier = Modifier.background(White),
isFavorite = uiState.isFavorite,
onFavoriteClick = { viewModel.toggleFavorite(5, 1) },
onFavoriteClick = { viewModel.toggleFavorite(productId, memberId) },
)
},
) { innerPadding ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ class GoodsViewModel(
SELLING_UNIT to info.sellingUnit,
WEIGHT to info.weight,
ALLERGY to info.allergy,
EXPIRATION to info.expiration.toString(),
BRIX to info.brix.toString(),
EXPIRATION to info.expiration,
BRIX to info.brix,
NOTIFICATION to info.notification,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,19 @@ import com.example.market_kurly.core.util.KeyStorage.HOME
import com.example.market_kurly.core.util.KeyStorage.REVIEW
import com.example.market_kurly.core.util.KeyStorage.WISHLIST
import com.example.market_kurly.feature.goods.GoodsScreen
import com.example.market_kurly.feature.goods.viewmodel.GoodsViewModel
import com.example.market_kurly.feature.home.HomeScreen
import com.example.market_kurly.feature.review.ReviewScreen
import com.example.market_kurly.feature.wishlist.WishListScreen

@Composable
fun NavGraph(
navController: NavHostController,
goodsViewModel: GoodsViewModel,
) {
fun NavGraph(navController: NavHostController) {
NavHost(navController = navController, startDestination = HOME) {
composable(HOME) {
HomeScreen(navController)
}
composable("$GOODS/{productId}") {
GoodsScreen(
navController,
goodsViewModel,
productId = it.arguments?.getString("productId")?.toInt() ?: 0,)
}
composable(REVIEW) {
Expand Down

0 comments on commit c510d20

Please sign in to comment.