Skip to content
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.terning.data.dto.response

import com.terning.domain.entity.response.HomeFilteringInfoModel
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

Expand All @@ -14,12 +13,4 @@ data class HomeFilteringInfoResponseDto(
val startYear: Int?,
@SerialName("startMonth")
val startMonth: Int?,
) {
fun toHomeFilteringInfoModel(): HomeFilteringInfoModel =
HomeFilteringInfoModel(
grade = this.grade,
workingPeriod = this.workingPeriod,
startYear = this.startYear,
startMonth = this.startMonth,
)
}
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.terning.data.dto.response

import com.terning.domain.entity.response.HomeRecommendInternModel
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

Expand All @@ -24,17 +23,4 @@ data class HomeRecommendInternResponseDto(
val companyImage: String,
@SerialName("isScrapped")
val isScrapped: Boolean,
) {
fun toRecommendInternEntity(): HomeRecommendInternModel =
HomeRecommendInternModel(
scrapId = this.scrapId,
internshipAnnouncementId = this.internshipAnnouncementId,
title = this.title,
dDay = this.dDay,
deadline = deadline,
workingPeriod = this.workingPeriod,
startYearMonth = this.startYearMonth,
companyImage = this.companyImage,
isScrapped = this.isScrapped,
)
}
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.terning.data.dto.response

import com.terning.domain.entity.response.HomeTodayInternModel
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

Expand All @@ -25,17 +24,4 @@ data class HomeTodayInternResponseDto(
@SerialName("startYearMonth")
val startYearMonth: String,

) {
fun toHomeTodayInternList(): HomeTodayInternModel =
HomeTodayInternModel(
scrapId = this.scrapId,
internshipAnnouncementId = this.internshipAnnouncementId,
companyImage = this.companyImage,
title = this.title,
dDay = this.dDay,
deadline = this.deadline,
workingPeriod = this.workingPeriod,
startYearMonth = this.startYearMonth,
color = this.color,
)
}
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.terning.data.mapper.home

import com.terning.data.dto.response.HomeFilteringInfoResponseDto
import com.terning.domain.entity.home.HomeFilteringInfo

fun HomeFilteringInfoResponseDto.toHomeFilteringInfo(): HomeFilteringInfo =
HomeFilteringInfo(
grade = this.grade,
workingPeriod = this.workingPeriod,
startYear = this.startYear,
startMonth = this.startMonth,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.terning.data.mapper.home

import com.terning.data.dto.response.HomeRecommendInternResponseDto
import com.terning.domain.entity.home.HomeRecommendIntern

fun HomeRecommendInternResponseDto.toHomeRecommendInternList(): HomeRecommendIntern =
HomeRecommendIntern(
scrapId = this.scrapId,
internshipAnnouncementId = this.internshipAnnouncementId,
title = this.title,
dDay = this.dDay,
deadline = deadline,
workingPeriod = this.workingPeriod,
startYearMonth = this.startYearMonth,
companyImage = this.companyImage,
isScrapped = this.isScrapped,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.terning.data.mapper.home

import com.terning.data.dto.response.HomeTodayInternResponseDto
import com.terning.domain.entity.home.HomeTodayIntern

fun HomeTodayInternResponseDto.toHomeTodayInternList(): HomeTodayIntern =
HomeTodayIntern(
scrapId = this.scrapId,
internshipAnnouncementId = this.internshipAnnouncementId,
companyImage = this.companyImage,
title = this.title,
dDay = this.dDay,
deadline = this.deadline,
workingPeriod = this.workingPeriod,
startYearMonth = this.startYearMonth,
color = this.color,
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,44 @@ package com.terning.data.repositoryimpl

import com.terning.data.datasource.HomeDataSource
import com.terning.data.dto.request.toChangeFilterRequestDto
import com.terning.data.mapper.home.toHomeFilteringInfo
import com.terning.data.mapper.home.toHomeRecommendInternList
import com.terning.data.mapper.home.toHomeTodayInternList
import com.terning.domain.entity.home.HomeFilteringInfo
import com.terning.domain.entity.home.HomeRecommendIntern
import com.terning.domain.entity.home.HomeTodayIntern
import com.terning.domain.entity.request.ChangeFilteringRequestModel
import com.terning.domain.entity.response.HomeFilteringInfoModel
import com.terning.domain.entity.response.HomeRecommendInternModel
import com.terning.domain.entity.response.HomeTodayInternModel
import com.terning.domain.repository.HomeRepository
import javax.inject.Inject

class HomeRepositoryImpl @Inject constructor(
private val homeDataSource: HomeDataSource,
) : HomeRepository {
override suspend fun getHomeTodayInternList(): Result<List<HomeTodayInternModel>> =
override suspend fun getHomeTodayInternList(): Result<List<HomeTodayIntern>> =
runCatching {
homeDataSource.getTodayIntern().result.map {
it.toHomeTodayInternList()
homeDataSource.getTodayIntern().result.map { homeTodayInternResponseDto ->
homeTodayInternResponseDto.toHomeTodayInternList()
}
}

override suspend fun getRecommendIntern(
sortBy: String,
startYear: Int,
startMonth: Int
): Result<List<HomeRecommendInternModel>> =
): Result<List<HomeRecommendIntern>> =
runCatching {
homeDataSource.getRecommendIntern(
sortBy = sortBy,
startYear = startYear,
startMonth = startMonth
).result.map {
it.toRecommendInternEntity()
).result.map { homeRecommendInternResponseDto ->
homeRecommendInternResponseDto.toHomeRecommendInternList()
}
}

override suspend fun getFilteringInfo(): Result<HomeFilteringInfoModel> =
override suspend fun getFilteringInfo(): Result<HomeFilteringInfo> =
runCatching {
homeDataSource.getFilteringInfo().result.toHomeFilteringInfoModel()
homeDataSource.getFilteringInfo().result.toHomeFilteringInfo()
}

override suspend fun putFilteringInfo(putFilteringRequest: ChangeFilteringRequestModel): Result<Unit> =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.terning.domain.entity.response
package com.terning.domain.entity.home

data class HomeFilteringInfoModel(
data class HomeFilteringInfo(
val grade: Int?,
val workingPeriod: Int?,
val startYear: Int?,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.terning.domain.entity.response
package com.terning.domain.entity.home

data class HomeRecommendInternModel(
data class HomeRecommendIntern(
val scrapId: Long?,
val internshipAnnouncementId: Long,
val title: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.terning.domain.entity.response
package com.terning.domain.entity.home

data class HomeTodayInternModel(
data class HomeTodayIntern(
val scrapId: Long,
val internshipAnnouncementId: Long,
val companyImage: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package com.terning.domain.repository

import com.terning.domain.entity.home.HomeFilteringInfo
import com.terning.domain.entity.home.HomeRecommendIntern
import com.terning.domain.entity.home.HomeTodayIntern
import com.terning.domain.entity.request.ChangeFilteringRequestModel
import com.terning.domain.entity.response.HomeFilteringInfoModel
import com.terning.domain.entity.response.HomeRecommendInternModel
import com.terning.domain.entity.response.HomeTodayInternModel

interface HomeRepository {
suspend fun getHomeTodayInternList(): Result<List<HomeTodayInternModel>>
suspend fun getHomeTodayInternList(): Result<List<HomeTodayIntern>>

suspend fun getRecommendIntern(
sortBy: String,
startYear: Int,
startMonth: Int
): Result<List<HomeRecommendInternModel>>
): Result<List<HomeRecommendIntern>>

suspend fun getFilteringInfo(): Result<HomeFilteringInfoModel>
suspend fun getFilteringInfo(): Result<HomeFilteringInfo>

suspend fun putFilteringInfo(
putFilteringRequest: ChangeFilteringRequestModel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,15 @@ import com.terning.core.designsystem.component.topappbar.BackButtonTopAppBar
import com.terning.core.designsystem.theme.TerningTheme
import com.terning.core.extension.toast
import com.terning.core.state.UiState
import com.terning.domain.entity.home.HomeFilteringInfo
import com.terning.domain.entity.request.ChangeFilteringRequestModel
import com.terning.domain.entity.response.HomeFilteringInfoModel
import com.terning.feature.R
import com.terning.feature.home.changefilter.component.ChangeFilteringRadioGroup
import com.terning.feature.home.changefilter.component.FilteringMainTitleText
import com.terning.feature.home.changefilter.component.FilteringSubTitleText
import com.terning.feature.home.changefilter.navigation.navigateChangeFilter
import com.terning.feature.home.home.HomeSideEffect
import com.terning.feature.home.home.HomeViewModel
import com.terning.feature.home.home.navigation.navigateHome

const val MIN_INDEX = 0
const val MAX_WORKING_INDEX = 2
Expand All @@ -53,7 +52,7 @@ fun ChangeFilterRoute(

when (filteringState) {
is UiState.Success -> ChangeFilterScreen(
(filteringState as UiState.Success<HomeFilteringInfoModel>).data,
(filteringState as UiState.Success<HomeFilteringInfo>).data,
navController,
viewModel,
Comment on lines 56 to 57
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

뷰모델이나 네비게이션 객체를 인자로 넘겨주는 것보단 고차함수로 넘기는 게 좋을 것 같아요!!
유빈이가 깔끔하게 해놨던데 참고해봐요~~!

)
Expand All @@ -75,7 +74,7 @@ fun ChangeFilterRoute(

@Composable
fun ChangeFilterScreen(
filterData: HomeFilteringInfoModel,
filterData: HomeFilteringInfo,
navController: NavController,
viewModel: HomeViewModel,
) {
Comment on lines 78 to 80
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

바로 밑에 코드에 코멘트가 달리지 않아 여기에 답니다ㅎㅎ

지금 보니까 뷰모델의 상태값을 인자로 받아온 상태에서 밑에 remember를 사용해서 변수를 선언했는데 왜 이렇게 구현한건가요??
처음 봤을 땐 뭔가 의아했는데 보면 볼수록 의미있는거 같고 그렇네요ㅋㅋ

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

일단 navController는 함수로 넘기는 방식으로 변경했고, viewModel같은 경우는 현재 년/월과 필터링 재설정 API 함수때문에 viewModel을 그대로 같이 넘겼던 것으로 기억하는데 다른 더 좋은 방법이 있을 것 같아서 계속 고민중입니다!!

Expand Down
32 changes: 16 additions & 16 deletions feature/src/main/java/com/terning/feature/home/home/HomeRoute.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ import com.terning.core.designsystem.theme.White
import com.terning.core.extension.noRippleClickable
import com.terning.core.extension.toast
import com.terning.core.state.UiState
import com.terning.domain.entity.response.HomeFilteringInfoModel
import com.terning.domain.entity.response.HomeRecommendInternModel
import com.terning.domain.entity.response.HomeTodayInternModel
import com.terning.domain.entity.home.HomeFilteringInfo
import com.terning.domain.entity.home.HomeRecommendIntern
import com.terning.domain.entity.home.HomeTodayIntern
import com.terning.feature.R
import com.terning.feature.home.changefilter.navigation.navigateChangeFilter
import com.terning.feature.home.home.component.HomeFilteringEmptyIntern
Expand Down Expand Up @@ -102,7 +102,7 @@ fun HomeRoute(
val homeUserState by viewModel.homeUserState.collectAsStateWithLifecycle()
val homeDialogState by viewModel.homeDialogState.collectAsStateWithLifecycle()

val homeTodayInternList: MutableState<List<HomeTodayInternModel>> = remember {
val homeTodayInternList: MutableState<List<HomeTodayIntern>> = remember {
mutableStateOf(emptyList())
}

Expand All @@ -120,7 +120,7 @@ fun HomeRoute(
LaunchedEffect(homeFilteringState, currentSortBy.value) {
when (homeFilteringState) {
is UiState.Success ->
with((homeFilteringState as UiState.Success<HomeFilteringInfoModel>).data) {
with((homeFilteringState as UiState.Success<HomeFilteringInfo>).data) {
viewModel.getRecommendInternsData(
currentSortBy.value,
startYear ?: viewModel.currentYear,
Expand All @@ -143,7 +143,7 @@ fun HomeRoute(
when (homeTodayState) {
is UiState.Success -> {
homeTodayInternList.value =
(homeTodayState as UiState.Success<List<HomeTodayInternModel>>).data
(homeTodayState as UiState.Success<List<HomeTodayIntern>>).data
}

is UiState.Loading -> {}
Expand All @@ -154,15 +154,15 @@ fun HomeRoute(

val homeRecommendInternList = when (homeRecommendInternState) {
is UiState.Success -> {
(homeRecommendInternState as UiState.Success<List<HomeRecommendInternModel>>).data
(homeRecommendInternState as UiState.Success<List<HomeRecommendIntern>>).data
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

홈화면에서 목록을 밑으로 스크롤한 상태에서 스크랩을 하면 화면이 다시 로드되면서 위로 되돌아가는 문제가 고쳐졌는지 모르겠지만,
만약 아직도 문제가 된다면 제가 예상하는 원인은 다음과 같아요:

  • 뷰모델의 코드, LaunchedEffect 그리고 상태 확인 코드들간의 의존성이 엮여서 복잡하고 불필요한 호출이 많이 일어나는 것 같음
  • 각 부분의 데이터가 바뀌면 관련 컴포저블들만 리컴포지션되는 것이 아니라 HomeRoute 전체에 대한 리컴포지션되고 하위 데이터들이 바뀌는 것 같음

지금 이렇게 최상위 컴포저블에서 모든 상태를 관리하는 방법에서 상태값이 바뀌면 관련된 컴포저블을 업데이트하는 방식으로 바꿔보는 건 어떨까 싶어요!!

즉, When문을 사용해 homeRecommendInternList와 같은 변수를 선언/초기화하여 HomeScreen의 인자로 넘기는 것이 아니라, When문을 사용해 Success 상태일 때 HomeScreen/LazyColumn/items/RecommendInternItem 컴포저블을 보여주는 방향으로 바꿔 보세요!!

이게 해결방법이 아닐 수는 있지만, when문에서 뷰를 업데이트하는게 더 옳은 방법이라고 생각합니다!!
ChangeFilterRoute에서 하신 것처럼 해주시면 됩니다!!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

우왕 정말 감사합니다!!! 정말 확인해보니 HomeRoute 전체가 리컴포지션되더라구요😭 말씀해주신 방식으로 수정해보겠습니당 진짜 최고최고💚

}

else -> emptyList()
}

val homeFilteringInfo = when (homeFilteringState) {
is UiState.Success -> (homeFilteringState as UiState.Success<HomeFilteringInfoModel>).data
else -> HomeFilteringInfoModel(null, null, viewModel.currentYear, viewModel.currentMonth)
is UiState.Success -> (homeFilteringState as UiState.Success<HomeFilteringInfo>).data
else -> HomeFilteringInfo(null, null, viewModel.currentYear, viewModel.currentMonth)
}

val homeUserName = when (homeUserState) {
Expand All @@ -187,9 +187,9 @@ fun HomeRoute(
fun HomeScreen(
currentSortBy: MutableState<Int>,
homeUserName: String,
homeFilteringInfo: HomeFilteringInfoModel,
homeTodayInternList: List<HomeTodayInternModel>,
recommendInternList: List<HomeRecommendInternModel>,
homeFilteringInfo: HomeFilteringInfo,
homeTodayInternList: List<HomeTodayIntern>,
recommendInternList: List<HomeRecommendIntern>,
homeDialogState: HomeDialogState,
onChangeFilterClick: () -> Unit,
viewModel: HomeViewModel = hiltViewModel(),
Expand Down Expand Up @@ -372,7 +372,7 @@ fun HomeScreen(
viewModel.updateScrapped(false)
}
},
homeRecommendInternModel = this,
homeRecommendIntern = this,
)
}
}
Expand All @@ -385,7 +385,7 @@ fun HomeScreen(
@Composable
private fun RecommendInternItem(
navController: NavHostController,
intern: HomeRecommendInternModel,
intern: HomeRecommendIntern,
onScrapButtonClicked: (Long) -> Unit,
) {
InternItemWithShadow(
Expand Down Expand Up @@ -425,7 +425,7 @@ private fun ShowMainTitleWithName(userName: String) {

@Composable
private fun ShowTodayIntern(
homeTodayInternList: List<HomeTodayInternModel>,
homeTodayInternList: List<HomeTodayIntern>,
homeDialogState: HomeDialogState,
navigateToDetail: (Long) -> Unit,
) {
Expand Down Expand Up @@ -463,7 +463,7 @@ private fun ShowRecommendTitle() {

@Composable
private fun ShowInternFilter(
homeFilteringInfo: HomeFilteringInfoModel,
homeFilteringInfo: HomeFilteringInfo,
onChangeFilterClick: () -> Unit,
) {
if (homeFilteringInfo.grade == null) {
Expand Down
Loading