From 0a582b542de67c3ec160e957c65c76c0f46be195 Mon Sep 17 00:00:00 2001 From: Hyobeen-Park Date: Mon, 15 Jul 2024 18:51:52 +0900 Subject: [PATCH 01/14] =?UTF-8?q?[CHORE/#77]=20=EB=8D=B0=EC=9D=B4=ED=84=B0?= =?UTF-8?q?=20=ED=98=95=EC=8B=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../terning/feature/home/home/HomeRoute.kt | 4 +- .../feature/home/home/HomeViewModel.kt | 44 +++++++++---------- .../home/home/model/RecommendInternData.kt | 4 +- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/feature/src/main/java/com/terning/feature/home/home/HomeRoute.kt b/feature/src/main/java/com/terning/feature/home/home/HomeRoute.kt index 4c03dd063..bfc520ff5 100644 --- a/feature/src/main/java/com/terning/feature/home/home/HomeRoute.kt +++ b/feature/src/main/java/com/terning/feature/home/home/HomeRoute.kt @@ -247,8 +247,8 @@ private fun ShowRecommendIntern(recommendInternData: RecommendInternData) { InternItem( imageUrl = recommendInternData.imgUrl, title = recommendInternData.title, - dateDeadline = recommendInternData.dDay.toString(), - workingPeriod = recommendInternData.workingPeriod.toString(), + dateDeadline = recommendInternData.dDay, + workingPeriod = recommendInternData.workingPeriod, isScraped = recommendInternData.isScrapped, ) } diff --git a/feature/src/main/java/com/terning/feature/home/home/HomeViewModel.kt b/feature/src/main/java/com/terning/feature/home/home/HomeViewModel.kt index 68fd0d2f1..7bbde1d7f 100644 --- a/feature/src/main/java/com/terning/feature/home/home/HomeViewModel.kt +++ b/feature/src/main/java/com/terning/feature/home/home/HomeViewModel.kt @@ -46,8 +46,8 @@ class HomeViewModel @Inject constructor( val scrapData get() = _scrapState.asStateFlow() private val _recommendInternState = MutableStateFlow>( -// getRecommendData() - listOf() + getRecommendData() +// listOf() ) val recommendInternData get() = _recommendInternState.asStateFlow() } @@ -107,71 +107,71 @@ private fun getRecommendData(): List = listOf( RecommendInternData( imgUrl = "https://reqres.in/img/faces/7-image.jpg", title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", - dDay = 22, - workingPeriod = 2, + dDay = "D-2", + workingPeriod = "4개월", isScrapped = true, ), RecommendInternData( imgUrl = "https://reqres.in/img/faces/7-image.jpg", title = "ㅇㄻㅇㅁㄻㄹㅇㅁㅇㄹ", - dDay = 9, - workingPeriod = 6, + dDay = "D-2", + workingPeriod = "4개월", isScrapped = false, ), RecommendInternData( imgUrl = "https://reqres.in/img/faces/7-image.jpg", title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", - dDay = 2, - workingPeriod = 4, + dDay = "D-2", + workingPeriod = "4개월", isScrapped = true, ), RecommendInternData( imgUrl = "https://reqres.in/img/faces/7-image.jpg", title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", - dDay = 2, - workingPeriod = 4, + dDay = "D-2", + workingPeriod = "4개월", isScrapped = false, ), RecommendInternData( imgUrl = "https://reqres.in/img/faces/7-image.jpg", title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", - dDay = 2, - workingPeriod = 4, + dDay = "D-2", + workingPeriod = "4개월", isScrapped = true, ), RecommendInternData( imgUrl = "https://reqres.in/img/faces/7-image.jpg", title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", - dDay = 2, - workingPeriod = 4, + dDay = "D-2", + workingPeriod = "4개월", isScrapped = true, ), RecommendInternData( imgUrl = "https://reqres.in/img/faces/7-image.jpg", title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", - dDay = 2, - workingPeriod = 4, + dDay = "D-2", + workingPeriod = "4개월", isScrapped = false, ), RecommendInternData( imgUrl = "https://reqres.in/img/faces/7-image.jpg", title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", - dDay = 2, - workingPeriod = 4, + dDay ="D-2", + workingPeriod = "4개월", isScrapped = true, ), RecommendInternData( imgUrl = "https://reqres.in/img/faces/7-image.jpg", title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", - dDay = 2, - workingPeriod = 4, + dDay = "D-2", + workingPeriod = "4개월", isScrapped = false, ), RecommendInternData( imgUrl = "https://reqres.in/img/faces/7-image.jpg", title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", - dDay = 2, - workingPeriod = 4, + dDay = "D-2", + workingPeriod = "4개월", isScrapped = true, ), ) \ No newline at end of file diff --git a/feature/src/main/java/com/terning/feature/home/home/model/RecommendInternData.kt b/feature/src/main/java/com/terning/feature/home/home/model/RecommendInternData.kt index 5b84c180a..8e4891c92 100644 --- a/feature/src/main/java/com/terning/feature/home/home/model/RecommendInternData.kt +++ b/feature/src/main/java/com/terning/feature/home/home/model/RecommendInternData.kt @@ -3,7 +3,7 @@ package com.terning.feature.home.home.model data class RecommendInternData( val imgUrl: String, val title: String, - val dDay: Int, - val workingPeriod: Int, + val dDay: String, + val workingPeriod: String, val isScrapped: Boolean, ) From 8ccdc92eb31e270e62054771273ba18a1934e66a Mon Sep 17 00:00:00 2001 From: Hyobeen-Park Date: Tue, 16 Jul 2024 00:38:08 +0900 Subject: [PATCH 02/14] =?UTF-8?q?[FEAT/#77]=20=EC=84=9C=EB=B2=84=ED=86=B5?= =?UTF-8?q?=EC=8B=A0=20=ED=8B=80=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/terning/point/di/DataSourceModule.kt | 6 + .../com/terning/point/di/RepositoryModule.kt | 6 + .../com/terning/point/di/ServiceModule.kt | 5 + .../data/datasource/InternDataSource.kt | 8 ++ .../datasourceimpl/InternDataSourceImpl.kt | 14 +++ .../response/RecommendInternResponseDto.kt | 116 ++++++++++++++++++ .../repositoryimpl/InternRepositoryImpl.kt | 15 +++ .../com/terning/data/service/InternService.kt | 14 +++ .../entity/response/RecommendInternModel.kt | 10 ++ .../domain/repository/InternRepository.kt | 7 ++ 10 files changed, 201 insertions(+) create mode 100644 data/src/main/java/com/terning/data/datasource/InternDataSource.kt create mode 100644 data/src/main/java/com/terning/data/datasourceimpl/InternDataSourceImpl.kt create mode 100644 data/src/main/java/com/terning/data/dto/response/RecommendInternResponseDto.kt create mode 100644 data/src/main/java/com/terning/data/repositoryimpl/InternRepositoryImpl.kt create mode 100644 data/src/main/java/com/terning/data/service/InternService.kt create mode 100644 domain/src/main/java/com/terning/domain/entity/response/RecommendInternModel.kt create mode 100644 domain/src/main/java/com/terning/domain/repository/InternRepository.kt diff --git a/app/src/main/java/com/terning/point/di/DataSourceModule.kt b/app/src/main/java/com/terning/point/di/DataSourceModule.kt index c1541df6a..d802776c7 100644 --- a/app/src/main/java/com/terning/point/di/DataSourceModule.kt +++ b/app/src/main/java/com/terning/point/di/DataSourceModule.kt @@ -1,6 +1,8 @@ package com.terning.point.di +import com.terning.data.datasource.InternDataSource import com.terning.data.datasource.MockDataSource +import com.terning.data.datasourceimpl.InternDataSourceImpl import com.terning.data.datasourceimpl.MockDataSourceImpl import dagger.Binds import dagger.Module @@ -15,4 +17,8 @@ abstract class DataSourceModule { @Binds @Singleton abstract fun bindMockDataSource(mockDataSourceImpl: MockDataSourceImpl): MockDataSource + + @Binds + @Singleton + abstract fun bindRecommendInternDataSource(internDataSourceImpl: InternDataSourceImpl): InternDataSource } \ No newline at end of file diff --git a/app/src/main/java/com/terning/point/di/RepositoryModule.kt b/app/src/main/java/com/terning/point/di/RepositoryModule.kt index 9de02a07a..5c1d4cdd1 100644 --- a/app/src/main/java/com/terning/point/di/RepositoryModule.kt +++ b/app/src/main/java/com/terning/point/di/RepositoryModule.kt @@ -1,6 +1,8 @@ package com.terning.point.di +import com.terning.data.repositoryimpl.InternRepositoryImpl import com.terning.data.repositoryimpl.MockRepositoryImpl +import com.terning.domain.repository.InternRepository import com.terning.domain.repository.MockRepository import dagger.Binds import dagger.Module @@ -15,4 +17,8 @@ abstract class RepositoryModule { @Binds @Singleton abstract fun bindMockRepository(mockRepositoryImpl: MockRepositoryImpl): MockRepository + + @Binds + @Singleton + abstract fun bindInternRepository(internRepositoryImpl: InternRepositoryImpl): InternRepository } \ No newline at end of file diff --git a/app/src/main/java/com/terning/point/di/ServiceModule.kt b/app/src/main/java/com/terning/point/di/ServiceModule.kt index 317c02f92..81241aa34 100644 --- a/app/src/main/java/com/terning/point/di/ServiceModule.kt +++ b/app/src/main/java/com/terning/point/di/ServiceModule.kt @@ -1,5 +1,6 @@ package com.terning.point.di +import com.terning.data.service.InternService import com.terning.data.service.MockService import com.terning.point.di.qualifier.OPEN import dagger.Module @@ -18,4 +19,8 @@ object ServiceModule { fun provideMockService(@OPEN retrofit: Retrofit): MockService = retrofit.create(MockService::class.java) + @Provides + @Singleton + fun provideInternService(@OPEN retrofit: Retrofit): InternService = + retrofit.create(InternService::class.java) } \ No newline at end of file diff --git a/data/src/main/java/com/terning/data/datasource/InternDataSource.kt b/data/src/main/java/com/terning/data/datasource/InternDataSource.kt new file mode 100644 index 000000000..d606d1176 --- /dev/null +++ b/data/src/main/java/com/terning/data/datasource/InternDataSource.kt @@ -0,0 +1,8 @@ +package com.terning.data.datasource + +import com.terning.data.dto.BaseResponse +import com.terning.data.dto.response.RecommendInternResponseDto + +interface InternDataSource { + suspend fun getRecommendIntern(sortBy: String): BaseResponse +} \ No newline at end of file diff --git a/data/src/main/java/com/terning/data/datasourceimpl/InternDataSourceImpl.kt b/data/src/main/java/com/terning/data/datasourceimpl/InternDataSourceImpl.kt new file mode 100644 index 000000000..bdb90ef4b --- /dev/null +++ b/data/src/main/java/com/terning/data/datasourceimpl/InternDataSourceImpl.kt @@ -0,0 +1,14 @@ +package com.terning.data.datasourceimpl + +import com.terning.data.datasource.InternDataSource +import com.terning.data.dto.BaseResponse +import com.terning.data.dto.response.RecommendInternResponseDto +import com.terning.data.service.InternService +import javax.inject.Inject + +class InternDataSourceImpl @Inject constructor( + private val internService: InternService +) : InternDataSource { + override suspend fun getRecommendIntern(sortBy: String): BaseResponse = + internService.getRecommendIntern(sortBy = sortBy) +} \ No newline at end of file diff --git a/data/src/main/java/com/terning/data/dto/response/RecommendInternResponseDto.kt b/data/src/main/java/com/terning/data/dto/response/RecommendInternResponseDto.kt new file mode 100644 index 000000000..74fad16e9 --- /dev/null +++ b/data/src/main/java/com/terning/data/dto/response/RecommendInternResponseDto.kt @@ -0,0 +1,116 @@ +package com.terning.data.dto.response + +import com.terning.domain.entity.response.RecommendInternModel +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class RecommendInternResponseDto( + @SerialName("internshipAnnouncementId") + val internshipAnnouncementId: Long, + @SerialName("title") + val title: String, + @SerialName("dDay") + val dDay: String, + @SerialName("workingPeriod") + val workingPeriod: String, + @SerialName("companyImage") + val companyImage: String, + @SerialName("isScrapped") + val isScrapped: Boolean, +) { +// fun toRecommendInternEntity(): List = listOf( +// RecommendInternResponseModel( +// internshipAnnouncementId = this.internshipAnnouncementId, +// title = this.title, +// dDay = this.dDay, +// workingPeriod = this.workingPeriod, +// companyImage = this.companyImage, +// isScrapped = this.isScrapped, +// ) +// ) + + fun toRecommendInternEntity(): List = + listOf( + RecommendInternModel( + internshipAnnouncementId = 1234123132, + title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", + dDay = "D-2", + workingPeriod = "4개월", + companyImage = "https://reqres.in/img/faces/7-image.jpg", + isScrapped = true, + ), + RecommendInternModel( + internshipAnnouncementId = 1234123132, + title = "ㅇㄻㅇㅁㄻㄹㅇㅁㅇㄹ", + dDay = "D-2", + workingPeriod = "4개월", + companyImage = "https://reqres.in/img/faces/7-image.jpg", + isScrapped = false, + ), + RecommendInternModel( + internshipAnnouncementId = 1234123132, + title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", + dDay = "D-2", + workingPeriod = "4개월", + companyImage = "https://reqres.in/img/faces/7-image.jpg", + isScrapped = true, + ), + RecommendInternModel( + internshipAnnouncementId = 1234123132, + title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", + dDay = "D-2", + workingPeriod = "4개월", + companyImage = "https://reqres.in/img/faces/7-image.jpg", + isScrapped = false, + ), + RecommendInternModel( + internshipAnnouncementId = 1234123132, + title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", + dDay = "D-2", + workingPeriod = "4개월", + companyImage = "https://reqres.in/img/faces/7-image.jpg", + isScrapped = true, + ), + RecommendInternModel( + internshipAnnouncementId = 1234123132, + title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", + dDay = "D-2", + workingPeriod = "4개월", + companyImage = "https://reqres.in/img/faces/7-image.jpg", + isScrapped = true, + ), + RecommendInternModel( + internshipAnnouncementId = 1234123132, + title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", + dDay = "D-2", + workingPeriod = "4개월", + companyImage = "https://reqres.in/img/faces/7-image.jpg", + isScrapped = false, + ), + RecommendInternModel( + internshipAnnouncementId = 1234123132, + title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", + dDay = "D-2", + workingPeriod = "4개월", + companyImage = "https://reqres.in/img/faces/7-image.jpg", + isScrapped = true, + ), + RecommendInternModel( + internshipAnnouncementId = 1234123132, + title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", + dDay = "D-2", + workingPeriod = "4개월", + companyImage = "https://reqres.in/img/faces/7-image.jpg", + isScrapped = false, + ), + RecommendInternModel( + internshipAnnouncementId = 1234123132, + title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", + dDay = "D-2", + workingPeriod = "4개월", + companyImage = "https://reqres.in/img/faces/7-image.jpg", + isScrapped = true, + ), + ) +} diff --git a/data/src/main/java/com/terning/data/repositoryimpl/InternRepositoryImpl.kt b/data/src/main/java/com/terning/data/repositoryimpl/InternRepositoryImpl.kt new file mode 100644 index 000000000..0dd43f93f --- /dev/null +++ b/data/src/main/java/com/terning/data/repositoryimpl/InternRepositoryImpl.kt @@ -0,0 +1,15 @@ +package com.terning.data.repositoryimpl + +import com.terning.data.datasource.InternDataSource +import com.terning.domain.entity.response.RecommendInternModel +import com.terning.domain.repository.InternRepository +import javax.inject.Inject + +class InternRepositoryImpl @Inject constructor( + private val internDataSource: InternDataSource, +) : InternRepository { + override suspend fun getRecommendIntern(sortBy: String): Result> = + runCatching { + internDataSource.getRecommendIntern(sortBy = sortBy).result.toRecommendInternEntity() + } +} \ No newline at end of file diff --git a/data/src/main/java/com/terning/data/service/InternService.kt b/data/src/main/java/com/terning/data/service/InternService.kt new file mode 100644 index 000000000..eecda1393 --- /dev/null +++ b/data/src/main/java/com/terning/data/service/InternService.kt @@ -0,0 +1,14 @@ +package com.terning.data.service + +import com.terning.data.dto.BaseResponse +import com.terning.data.dto.response.RecommendInternResponseDto +import retrofit2.http.GET +import retrofit2.http.Query + +interface InternService { + @GET("api/v1/home") + suspend fun getRecommendIntern( + @Query("sortBy") sortBy: String, + ): BaseResponse + +} \ No newline at end of file diff --git a/domain/src/main/java/com/terning/domain/entity/response/RecommendInternModel.kt b/domain/src/main/java/com/terning/domain/entity/response/RecommendInternModel.kt new file mode 100644 index 000000000..45eb02f64 --- /dev/null +++ b/domain/src/main/java/com/terning/domain/entity/response/RecommendInternModel.kt @@ -0,0 +1,10 @@ +package com.terning.domain.entity.response + +data class RecommendInternModel( + val internshipAnnouncementId: Long, + val title: String, + val dDay: String, + val workingPeriod: String, + val companyImage: String, + val isScrapped: Boolean, +) diff --git a/domain/src/main/java/com/terning/domain/repository/InternRepository.kt b/domain/src/main/java/com/terning/domain/repository/InternRepository.kt new file mode 100644 index 000000000..9cb86544c --- /dev/null +++ b/domain/src/main/java/com/terning/domain/repository/InternRepository.kt @@ -0,0 +1,7 @@ +package com.terning.domain.repository + +import com.terning.domain.entity.response.RecommendInternModel + +interface InternRepository { + suspend fun getRecommendIntern(sortBy: String): Result> +} \ No newline at end of file From 37dfa12dec14a26b09ba863fa2eaaf857844fd82 Mon Sep 17 00:00:00 2001 From: Hyobeen-Park Date: Tue, 16 Jul 2024 01:30:27 +0900 Subject: [PATCH 03/14] =?UTF-8?q?[FEAT/#77]=20=EC=84=9C=EB=B2=84=20?= =?UTF-8?q?=ED=86=B5=EC=8B=A0=20=EB=A1=9C=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../terning/feature/home/home/HomeRoute.kt | 62 +++++++---- .../feature/home/home/HomeViewModel.kt | 105 +++++------------- 2 files changed, 68 insertions(+), 99 deletions(-) diff --git a/feature/src/main/java/com/terning/feature/home/home/HomeRoute.kt b/feature/src/main/java/com/terning/feature/home/home/HomeRoute.kt index ad41bc9eb..f97af299c 100644 --- a/feature/src/main/java/com/terning/feature/home/home/HomeRoute.kt +++ b/feature/src/main/java/com/terning/feature/home/home/HomeRoute.kt @@ -39,6 +39,8 @@ import com.terning.core.designsystem.theme.Grey200 import com.terning.core.designsystem.theme.TerningTheme import com.terning.core.designsystem.theme.White import com.terning.core.extension.customShadow +import com.terning.core.state.UiState +import com.terning.domain.entity.response.RecommendInternModel import com.terning.feature.R import com.terning.feature.home.changefilter.navigation.navigateChangeFilter import com.terning.feature.home.home.component.HomeFilteringEmptyIntern @@ -49,21 +51,43 @@ import com.terning.feature.home.home.component.HomeTodayIntern import com.terning.feature.home.home.model.RecommendInternData import com.terning.feature.home.home.model.UserNameState import com.terning.feature.home.home.model.UserScrapState +import com.terning.feature.home.home.navigation.Home +import timber.log.Timber const val NAME_START_LENGTH = 7 const val NAME_END_LENGTH = 12 @Composable fun HomeRoute( - navController: NavHostController + navController: NavHostController, + viewModel: HomeViewModel = hiltViewModel(), ) { val currentSortBy: MutableState = remember { mutableIntStateOf(0) } - HomeScreen( - currentSortBy, - onChangeFilterClick = { navController.navigateChangeFilter() } - ) + + val recommendInternState by viewModel.recommendInternState.collectAsStateWithLifecycle() + + when (recommendInternState) { + is UiState.Empty -> {} + is UiState.Loading -> {} + is UiState.Failure -> { + HomeScreen( + currentSortBy, + onChangeFilterClick = { navController.navigateChangeFilter() }, + recommendInternList = emptyList() + ) + } + is UiState.Success -> { + val recommendInternList = (recommendInternState as UiState.Success>).data + + HomeScreen( + currentSortBy, + onChangeFilterClick = { navController.navigateChangeFilter() }, + recommendInternList = recommendInternList + ) + } + } } @OptIn(ExperimentalFoundationApi::class) @@ -71,13 +95,13 @@ fun HomeRoute( fun HomeScreen( currentSortBy: MutableState, onChangeFilterClick: () -> Unit, + recommendInternList: List, viewModel: HomeViewModel = hiltViewModel(), ) { val userNameState = viewModel.userName val userScrapState by viewModel.scrapData.collectAsStateWithLifecycle() - val recommendInternData by viewModel.recommendInternData.collectAsStateWithLifecycle() var sheetState by remember { mutableStateOf(false) } - + if (sheetState) { SortingBottomSheet( onDismiss = { @@ -146,9 +170,9 @@ fun HomeScreen( } } - if (userNameState.internFilter != null && recommendInternData.isNotEmpty()) { - items(recommendInternData.size) { index -> - ShowRecommendIntern(recommendInternData[index]) + if(recommendInternList.isNotEmpty()) { + items(recommendInternList.size) { index -> + ShowRecommendIntern(recommendInternModel = recommendInternList[index]) } } } @@ -159,7 +183,7 @@ fun HomeScreen( .padding(horizontal = 24.dp) .fillMaxSize() ) - } else if (recommendInternData.isEmpty()) { + } else if (recommendInternList.isEmpty()) { HomeRecommendEmptyIntern() } } @@ -246,14 +270,14 @@ private fun ShowInternFilter(userNameState: UserNameState, onChangeFilterClick: } @Composable -private fun ShowRecommendIntern(recommendInternData: RecommendInternData) { +private fun ShowRecommendIntern(recommendInternModel: RecommendInternModel) { Box( modifier = Modifier .padding(horizontal = 24.dp) .customShadow( color = Grey200, - shadowRadius = 10.dp, - shadowWidth = 2.dp + shadowRadius = 5.dp, + shadowWidth = 1.dp ) .background( color = White, @@ -261,11 +285,11 @@ private fun ShowRecommendIntern(recommendInternData: RecommendInternData) { ) ) { InternItem( - imageUrl = recommendInternData.imgUrl, - title = recommendInternData.title, - dateDeadline = recommendInternData.dDay, - workingPeriod = recommendInternData.workingPeriod, - isScraped = recommendInternData.isScrapped, + imageUrl = recommendInternModel.companyImage, + title = recommendInternModel.title, + dateDeadline = recommendInternModel.dDay, + workingPeriod = recommendInternModel.workingPeriod, + isScraped = recommendInternModel.isScrapped, ) } } \ No newline at end of file diff --git a/feature/src/main/java/com/terning/feature/home/home/HomeViewModel.kt b/feature/src/main/java/com/terning/feature/home/home/HomeViewModel.kt index dfb4e1f4e..a91669cc4 100644 --- a/feature/src/main/java/com/terning/feature/home/home/HomeViewModel.kt +++ b/feature/src/main/java/com/terning/feature/home/home/HomeViewModel.kt @@ -3,6 +3,7 @@ package com.terning.feature.home.home import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope import com.terning.core.designsystem.theme.CalBlue1 import com.terning.core.designsystem.theme.CalBlue2 import com.terning.core.designsystem.theme.CalGreen1 @@ -10,19 +11,22 @@ import com.terning.core.designsystem.theme.CalGreen2 import com.terning.core.designsystem.theme.CalOrange1 import com.terning.core.designsystem.theme.CalPink import com.terning.core.designsystem.theme.CalYellow +import com.terning.core.state.UiState +import com.terning.domain.entity.response.RecommendInternModel +import com.terning.domain.repository.InternRepository import com.terning.feature.home.home.model.InternFilterData -import com.terning.feature.home.home.model.RecommendInternData import com.terning.feature.home.home.model.ScrapData import com.terning.feature.home.home.model.UserNameState import com.terning.feature.home.home.model.UserScrapState import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.launch import javax.inject.Inject @HiltViewModel class HomeViewModel @Inject constructor( - + private val internRepository: InternRepository ) : ViewModel() { private val _userName by mutableStateOf( UserNameState( @@ -39,16 +43,15 @@ class HomeViewModel @Inject constructor( private val _scrapState = MutableStateFlow( UserScrapState( - isScrapExist = true, + isScrapExist = false, scrapData = getScrapData() ) ) val scrapData get() = _scrapState.asStateFlow() - private val _recommendInternState = MutableStateFlow>( - getRecommendData() - ) - val recommendInternData get() = _recommendInternState.asStateFlow() + private val _recommendInternState = + MutableStateFlow>>(UiState.Empty) + val recommendInternState get() = _recommendInternState.asStateFlow() fun setGrade(grade: Int) { userName.internFilter?.grade = grade @@ -58,6 +61,21 @@ class HomeViewModel @Inject constructor( userName.internFilter?.workingPeriod = workingPeriod } + init { + getRecommendInternsData("deadlineSoon") + } + + + fun getRecommendInternsData(sortBy: String) { + _recommendInternState.value = UiState.Loading + viewModelScope.launch { + internRepository.getRecommendIntern(sortBy).onSuccess { internList -> + _recommendInternState.value = UiState.Success(internList) + }.onFailure { exception: Throwable -> + _recommendInternState.value = UiState.Failure(exception.message ?: " ") + } + } + } } private fun getScrapData(): List = listOf( @@ -110,76 +128,3 @@ private fun getScrapData(): List = listOf( scrapColor = CalPink, ), ) - -private fun getRecommendData(): List = listOf( - RecommendInternData( - imgUrl = "https://reqres.in/img/faces/7-image.jpg", - title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", - dDay = "D-2", - workingPeriod = "4개월", - isScrapped = true, - ), - RecommendInternData( - imgUrl = "https://reqres.in/img/faces/7-image.jpg", - title = "ㅇㄻㅇㅁㄻㄹㅇㅁㅇㄹ", - dDay = "D-2", - workingPeriod = "4개월", - isScrapped = false, - ), - RecommendInternData( - imgUrl = "https://reqres.in/img/faces/7-image.jpg", - title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", - dDay = "D-2", - workingPeriod = "4개월", - isScrapped = true, - ), - RecommendInternData( - imgUrl = "https://reqres.in/img/faces/7-image.jpg", - title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", - dDay = "D-2", - workingPeriod = "4개월", - isScrapped = false, - ), - RecommendInternData( - imgUrl = "https://reqres.in/img/faces/7-image.jpg", - title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", - dDay = "D-2", - workingPeriod = "4개월", - isScrapped = true, - ), - RecommendInternData( - imgUrl = "https://reqres.in/img/faces/7-image.jpg", - title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", - dDay = "D-2", - workingPeriod = "4개월", - isScrapped = true, - ), - RecommendInternData( - imgUrl = "https://reqres.in/img/faces/7-image.jpg", - title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", - dDay = "D-2", - workingPeriod = "4개월", - isScrapped = false, - ), - RecommendInternData( - imgUrl = "https://reqres.in/img/faces/7-image.jpg", - title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", - dDay ="D-2", - workingPeriod = "4개월", - isScrapped = true, - ), - RecommendInternData( - imgUrl = "https://reqres.in/img/faces/7-image.jpg", - title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", - dDay = "D-2", - workingPeriod = "4개월", - isScrapped = false, - ), - RecommendInternData( - imgUrl = "https://reqres.in/img/faces/7-image.jpg", - title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", - dDay = "D-2", - workingPeriod = "4개월", - isScrapped = true, - ), -) \ No newline at end of file From fde43508219952c1c5f7f4f6f5e1d7ad498fa55a Mon Sep 17 00:00:00 2001 From: Hyobeen-Park Date: Tue, 16 Jul 2024 01:39:48 +0900 Subject: [PATCH 04/14] =?UTF-8?q?[FEAT/#77]=20=EB=8D=B0=EC=9D=B4=ED=84=B0?= =?UTF-8?q?=20=EB=B0=9B=EC=95=84=EC=98=A4=EB=8A=94=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../terning/feature/home/home/HomeRoute.kt | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/feature/src/main/java/com/terning/feature/home/home/HomeRoute.kt b/feature/src/main/java/com/terning/feature/home/home/HomeRoute.kt index f97af299c..84669a9a4 100644 --- a/feature/src/main/java/com/terning/feature/home/home/HomeRoute.kt +++ b/feature/src/main/java/com/terning/feature/home/home/HomeRoute.kt @@ -67,27 +67,22 @@ fun HomeRoute( } val recommendInternState by viewModel.recommendInternState.collectAsStateWithLifecycle() + var recommendInternList = emptyList() when (recommendInternState) { is UiState.Empty -> {} is UiState.Loading -> {} - is UiState.Failure -> { - HomeScreen( - currentSortBy, - onChangeFilterClick = { navController.navigateChangeFilter() }, - recommendInternList = emptyList() - ) - } + is UiState.Failure -> { } is UiState.Success -> { - val recommendInternList = (recommendInternState as UiState.Success>).data - - HomeScreen( - currentSortBy, - onChangeFilterClick = { navController.navigateChangeFilter() }, - recommendInternList = recommendInternList - ) + recommendInternList = (recommendInternState as UiState.Success>).data } } + + HomeScreen( + currentSortBy, + onChangeFilterClick = { navController.navigateChangeFilter() }, + recommendInternList = recommendInternList + ) } @OptIn(ExperimentalFoundationApi::class) @@ -101,7 +96,7 @@ fun HomeScreen( val userNameState = viewModel.userName val userScrapState by viewModel.scrapData.collectAsStateWithLifecycle() var sheetState by remember { mutableStateOf(false) } - + if (sheetState) { SortingBottomSheet( onDismiss = { From 3cf879aec295ab3d8c8722b77dd041bbaeec3127 Mon Sep 17 00:00:00 2001 From: Hyobeen-Park Date: Tue, 16 Jul 2024 01:52:20 +0900 Subject: [PATCH 05/14] =?UTF-8?q?[CHORE/#77]=20=EB=8D=94=EB=AF=B8=20?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/response/RecommendInternModel.kt | 83 +++++++++++++++++++ .../feature/home/home/HomeViewModel.kt | 5 +- .../feature/home/home/model/InternData.kt | 4 +- .../com/terning/feature/main/MainNavigator.kt | 4 +- 4 files changed, 90 insertions(+), 6 deletions(-) diff --git a/domain/src/main/java/com/terning/domain/entity/response/RecommendInternModel.kt b/domain/src/main/java/com/terning/domain/entity/response/RecommendInternModel.kt index 45eb02f64..a9836e37d 100644 --- a/domain/src/main/java/com/terning/domain/entity/response/RecommendInternModel.kt +++ b/domain/src/main/java/com/terning/domain/entity/response/RecommendInternModel.kt @@ -8,3 +8,86 @@ data class RecommendInternModel( val companyImage: String, val isScrapped: Boolean, ) +fun toRecommendInternEntity(): List = + listOf( + RecommendInternModel( + internshipAnnouncementId = 1234123132, + title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", + dDay = "D-2", + workingPeriod = "4개월", + companyImage = "https://reqres.in/img/faces/7-image.jpg", + isScrapped = true, + ), + RecommendInternModel( + internshipAnnouncementId = 1234123132, + title = "ㅇㄻㅇㅁㄻㄹㅇㅁㅇㄹ", + dDay = "D-2", + workingPeriod = "4개월", + companyImage = "https://reqres.in/img/faces/7-image.jpg", + isScrapped = false, + ), + RecommendInternModel( + internshipAnnouncementId = 1234123132, + title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", + dDay = "D-2", + workingPeriod = "4개월", + companyImage = "https://reqres.in/img/faces/7-image.jpg", + isScrapped = true, + ), + RecommendInternModel( + internshipAnnouncementId = 1234123132, + title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", + dDay = "D-2", + workingPeriod = "4개월", + companyImage = "https://reqres.in/img/faces/7-image.jpg", + isScrapped = false, + ), + RecommendInternModel( + internshipAnnouncementId = 1234123132, + title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", + dDay = "D-2", + workingPeriod = "4개월", + companyImage = "https://reqres.in/img/faces/7-image.jpg", + isScrapped = true, + ), + RecommendInternModel( + internshipAnnouncementId = 1234123132, + title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", + dDay = "D-2", + workingPeriod = "4개월", + companyImage = "https://reqres.in/img/faces/7-image.jpg", + isScrapped = true, + ), + RecommendInternModel( + internshipAnnouncementId = 1234123132, + title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", + dDay = "D-2", + workingPeriod = "4개월", + companyImage = "https://reqres.in/img/faces/7-image.jpg", + isScrapped = false, + ), + RecommendInternModel( + internshipAnnouncementId = 1234123132, + title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", + dDay = "D-2", + workingPeriod = "4개월", + companyImage = "https://reqres.in/img/faces/7-image.jpg", + isScrapped = true, + ), + RecommendInternModel( + internshipAnnouncementId = 1234123132, + title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", + dDay = "D-2", + workingPeriod = "4개월", + companyImage = "https://reqres.in/img/faces/7-image.jpg", + isScrapped = false, + ), + RecommendInternModel( + internshipAnnouncementId = 1234123132, + title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", + dDay = "D-2", + workingPeriod = "4개월", + companyImage = "https://reqres.in/img/faces/7-image.jpg", + isScrapped = true, + ), + ) diff --git a/feature/src/main/java/com/terning/feature/home/home/HomeViewModel.kt b/feature/src/main/java/com/terning/feature/home/home/HomeViewModel.kt index 48c3749f4..9a612ddcd 100644 --- a/feature/src/main/java/com/terning/feature/home/home/HomeViewModel.kt +++ b/feature/src/main/java/com/terning/feature/home/home/HomeViewModel.kt @@ -13,6 +13,7 @@ import com.terning.core.designsystem.theme.CalPink import com.terning.core.designsystem.theme.CalYellow import com.terning.core.state.UiState import com.terning.domain.entity.response.RecommendInternModel +import com.terning.domain.entity.response.toRecommendInternEntity import com.terning.domain.repository.InternRepository import com.terning.feature.home.home.model.InternFilterData import com.terning.feature.home.home.model.ScrapData @@ -72,8 +73,10 @@ class HomeViewModel @Inject constructor( internRepository.getRecommendIntern(sortBy).onSuccess { internList -> _recommendInternState.value = UiState.Success(internList) }.onFailure { exception: Throwable -> - _recommendInternState.value = UiState.Failure(exception.message ?: " ") +// _recommendInternState.value = UiState.Failure(exception.message ?: " ") + _recommendInternState.value = UiState.Success(toRecommendInternEntity()) } + } } } diff --git a/feature/src/main/java/com/terning/feature/home/home/model/InternData.kt b/feature/src/main/java/com/terning/feature/home/home/model/InternData.kt index 0e6632187..4beafb192 100644 --- a/feature/src/main/java/com/terning/feature/home/home/model/InternData.kt +++ b/feature/src/main/java/com/terning/feature/home/home/model/InternData.kt @@ -3,7 +3,7 @@ package com.terning.feature.home.home.model data class InternData( val imgUrl: String, val title: String, - val dDay: String, - val workingPeriod: String, + val dDay: Int, + val workingPeriod: Int, val isScrapped: Boolean, ) diff --git a/feature/src/main/java/com/terning/feature/main/MainNavigator.kt b/feature/src/main/java/com/terning/feature/main/MainNavigator.kt index 361fb6103..b538c3e58 100644 --- a/feature/src/main/java/com/terning/feature/main/MainNavigator.kt +++ b/feature/src/main/java/com/terning/feature/main/MainNavigator.kt @@ -11,10 +11,8 @@ import androidx.navigation.compose.rememberNavController import androidx.navigation.navOptions import com.terning.feature.calendar.navigation.navigateCalendar import com.terning.feature.home.home.navigation.navigateHome -import com.terning.feature.intern.navigation.Intern import com.terning.feature.mypage.navigation.navigateMyPage import com.terning.feature.onboarding.signin.navigation.SignIn -import com.terning.feature.search.search.navigation.Search import com.terning.feature.search.search.navigation.navigateSearch class MainNavigator( @@ -24,7 +22,7 @@ class MainNavigator( @Composable get() = navController .currentBackStackEntryAsState().value?.destination - val startDestination = Search + val startDestination = SignIn val currentTab: MainTab? @Composable get() = MainTab.find { tab -> From f95c598127cbc2752af836189bd71c0fdcd920d0 Mon Sep 17 00:00:00 2001 From: Hyobeen-Park Date: Tue, 16 Jul 2024 02:01:01 +0900 Subject: [PATCH 06/14] =?UTF-8?q?[CHORE/#77]=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/response/RecommendInternModel.kt | 85 +------------------ .../feature/home/home/HomeViewModel.kt | 4 +- 2 files changed, 2 insertions(+), 87 deletions(-) diff --git a/domain/src/main/java/com/terning/domain/entity/response/RecommendInternModel.kt b/domain/src/main/java/com/terning/domain/entity/response/RecommendInternModel.kt index a9836e37d..d058b4e1d 100644 --- a/domain/src/main/java/com/terning/domain/entity/response/RecommendInternModel.kt +++ b/domain/src/main/java/com/terning/domain/entity/response/RecommendInternModel.kt @@ -7,87 +7,4 @@ data class RecommendInternModel( val workingPeriod: String, val companyImage: String, val isScrapped: Boolean, -) -fun toRecommendInternEntity(): List = - listOf( - RecommendInternModel( - internshipAnnouncementId = 1234123132, - title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", - dDay = "D-2", - workingPeriod = "4개월", - companyImage = "https://reqres.in/img/faces/7-image.jpg", - isScrapped = true, - ), - RecommendInternModel( - internshipAnnouncementId = 1234123132, - title = "ㅇㄻㅇㅁㄻㄹㅇㅁㅇㄹ", - dDay = "D-2", - workingPeriod = "4개월", - companyImage = "https://reqres.in/img/faces/7-image.jpg", - isScrapped = false, - ), - RecommendInternModel( - internshipAnnouncementId = 1234123132, - title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", - dDay = "D-2", - workingPeriod = "4개월", - companyImage = "https://reqres.in/img/faces/7-image.jpg", - isScrapped = true, - ), - RecommendInternModel( - internshipAnnouncementId = 1234123132, - title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", - dDay = "D-2", - workingPeriod = "4개월", - companyImage = "https://reqres.in/img/faces/7-image.jpg", - isScrapped = false, - ), - RecommendInternModel( - internshipAnnouncementId = 1234123132, - title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", - dDay = "D-2", - workingPeriod = "4개월", - companyImage = "https://reqres.in/img/faces/7-image.jpg", - isScrapped = true, - ), - RecommendInternModel( - internshipAnnouncementId = 1234123132, - title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", - dDay = "D-2", - workingPeriod = "4개월", - companyImage = "https://reqres.in/img/faces/7-image.jpg", - isScrapped = true, - ), - RecommendInternModel( - internshipAnnouncementId = 1234123132, - title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", - dDay = "D-2", - workingPeriod = "4개월", - companyImage = "https://reqres.in/img/faces/7-image.jpg", - isScrapped = false, - ), - RecommendInternModel( - internshipAnnouncementId = 1234123132, - title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", - dDay = "D-2", - workingPeriod = "4개월", - companyImage = "https://reqres.in/img/faces/7-image.jpg", - isScrapped = true, - ), - RecommendInternModel( - internshipAnnouncementId = 1234123132, - title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", - dDay = "D-2", - workingPeriod = "4개월", - companyImage = "https://reqres.in/img/faces/7-image.jpg", - isScrapped = false, - ), - RecommendInternModel( - internshipAnnouncementId = 1234123132, - title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", - dDay = "D-2", - workingPeriod = "4개월", - companyImage = "https://reqres.in/img/faces/7-image.jpg", - isScrapped = true, - ), - ) +) \ No newline at end of file diff --git a/feature/src/main/java/com/terning/feature/home/home/HomeViewModel.kt b/feature/src/main/java/com/terning/feature/home/home/HomeViewModel.kt index 9a612ddcd..e3188a146 100644 --- a/feature/src/main/java/com/terning/feature/home/home/HomeViewModel.kt +++ b/feature/src/main/java/com/terning/feature/home/home/HomeViewModel.kt @@ -13,7 +13,6 @@ import com.terning.core.designsystem.theme.CalPink import com.terning.core.designsystem.theme.CalYellow import com.terning.core.state.UiState import com.terning.domain.entity.response.RecommendInternModel -import com.terning.domain.entity.response.toRecommendInternEntity import com.terning.domain.repository.InternRepository import com.terning.feature.home.home.model.InternFilterData import com.terning.feature.home.home.model.ScrapData @@ -73,8 +72,7 @@ class HomeViewModel @Inject constructor( internRepository.getRecommendIntern(sortBy).onSuccess { internList -> _recommendInternState.value = UiState.Success(internList) }.onFailure { exception: Throwable -> -// _recommendInternState.value = UiState.Failure(exception.message ?: " ") - _recommendInternState.value = UiState.Success(toRecommendInternEntity()) + _recommendInternState.value = UiState.Failure(exception.message ?: " ") } } From d5d7ddd1aa1082171d80775af25a1688f5ff4bc8 Mon Sep 17 00:00:00 2001 From: Hyobeen-Park Date: Tue, 16 Jul 2024 08:06:50 +0900 Subject: [PATCH 07/14] =?UTF-8?q?[CHORE/#77]=20=EB=84=A4=EC=9D=B4=EB=B0=8D?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/terning/point/di/DataSourceModule.kt | 6 +- .../com/terning/point/di/RepositoryModule.kt | 6 +- .../com/terning/point/di/ServiceModule.kt | 6 +- ...{InternDataSource.kt => HomeDataSource.kt} | 6 +- .../data/datasourceimpl/HomeDataSourceImpl.kt | 14 +++ .../datasourceimpl/InternDataSourceImpl.kt | 14 --- .../HomeRecommendInternResponseDto.kt | 32 +++++ .../response/RecommendInternResponseDto.kt | 116 ------------------ .../data/repositoryimpl/HomeRepositoryImpl.kt | 15 +++ .../repositoryimpl/InternRepositoryImpl.kt | 15 --- .../{InternService.kt => HomeService.kt} | 6 +- .../domain/repository/HomeRepository.kt | 7 ++ .../domain/repository/InternRepository.kt | 7 -- 13 files changed, 83 insertions(+), 167 deletions(-) rename data/src/main/java/com/terning/data/datasource/{InternDataSource.kt => HomeDataSource.kt} (52%) create mode 100644 data/src/main/java/com/terning/data/datasourceimpl/HomeDataSourceImpl.kt delete mode 100644 data/src/main/java/com/terning/data/datasourceimpl/InternDataSourceImpl.kt create mode 100644 data/src/main/java/com/terning/data/dto/response/HomeRecommendInternResponseDto.kt delete mode 100644 data/src/main/java/com/terning/data/dto/response/RecommendInternResponseDto.kt create mode 100644 data/src/main/java/com/terning/data/repositoryimpl/HomeRepositoryImpl.kt delete mode 100644 data/src/main/java/com/terning/data/repositoryimpl/InternRepositoryImpl.kt rename data/src/main/java/com/terning/data/service/{InternService.kt => HomeService.kt} (61%) create mode 100644 domain/src/main/java/com/terning/domain/repository/HomeRepository.kt delete mode 100644 domain/src/main/java/com/terning/domain/repository/InternRepository.kt diff --git a/app/src/main/java/com/terning/point/di/DataSourceModule.kt b/app/src/main/java/com/terning/point/di/DataSourceModule.kt index d802776c7..56bce5dbb 100644 --- a/app/src/main/java/com/terning/point/di/DataSourceModule.kt +++ b/app/src/main/java/com/terning/point/di/DataSourceModule.kt @@ -1,8 +1,8 @@ package com.terning.point.di -import com.terning.data.datasource.InternDataSource +import com.terning.data.datasource.HomeDataSource import com.terning.data.datasource.MockDataSource -import com.terning.data.datasourceimpl.InternDataSourceImpl +import com.terning.data.datasourceimpl.HomeDataSourceImpl import com.terning.data.datasourceimpl.MockDataSourceImpl import dagger.Binds import dagger.Module @@ -20,5 +20,5 @@ abstract class DataSourceModule { @Binds @Singleton - abstract fun bindRecommendInternDataSource(internDataSourceImpl: InternDataSourceImpl): InternDataSource + abstract fun bindRecommendInternDataSource(internDataSourceImpl: HomeDataSourceImpl): HomeDataSource } \ No newline at end of file diff --git a/app/src/main/java/com/terning/point/di/RepositoryModule.kt b/app/src/main/java/com/terning/point/di/RepositoryModule.kt index 5c1d4cdd1..ecb252296 100644 --- a/app/src/main/java/com/terning/point/di/RepositoryModule.kt +++ b/app/src/main/java/com/terning/point/di/RepositoryModule.kt @@ -1,8 +1,8 @@ package com.terning.point.di -import com.terning.data.repositoryimpl.InternRepositoryImpl +import com.terning.data.repositoryimpl.HomeRepositoryImpl import com.terning.data.repositoryimpl.MockRepositoryImpl -import com.terning.domain.repository.InternRepository +import com.terning.domain.repository.HomeRepository import com.terning.domain.repository.MockRepository import dagger.Binds import dagger.Module @@ -20,5 +20,5 @@ abstract class RepositoryModule { @Binds @Singleton - abstract fun bindInternRepository(internRepositoryImpl: InternRepositoryImpl): InternRepository + abstract fun bindInternRepository(homeRepositoryImpl: HomeRepositoryImpl): HomeRepository } \ No newline at end of file diff --git a/app/src/main/java/com/terning/point/di/ServiceModule.kt b/app/src/main/java/com/terning/point/di/ServiceModule.kt index 81241aa34..ddf711992 100644 --- a/app/src/main/java/com/terning/point/di/ServiceModule.kt +++ b/app/src/main/java/com/terning/point/di/ServiceModule.kt @@ -1,6 +1,6 @@ package com.terning.point.di -import com.terning.data.service.InternService +import com.terning.data.service.HomeService import com.terning.data.service.MockService import com.terning.point.di.qualifier.OPEN import dagger.Module @@ -21,6 +21,6 @@ object ServiceModule { @Provides @Singleton - fun provideInternService(@OPEN retrofit: Retrofit): InternService = - retrofit.create(InternService::class.java) + fun provideInternService(@OPEN retrofit: Retrofit): HomeService = + retrofit.create(HomeService::class.java) } \ No newline at end of file diff --git a/data/src/main/java/com/terning/data/datasource/InternDataSource.kt b/data/src/main/java/com/terning/data/datasource/HomeDataSource.kt similarity index 52% rename from data/src/main/java/com/terning/data/datasource/InternDataSource.kt rename to data/src/main/java/com/terning/data/datasource/HomeDataSource.kt index d606d1176..c168623a2 100644 --- a/data/src/main/java/com/terning/data/datasource/InternDataSource.kt +++ b/data/src/main/java/com/terning/data/datasource/HomeDataSource.kt @@ -1,8 +1,8 @@ package com.terning.data.datasource import com.terning.data.dto.BaseResponse -import com.terning.data.dto.response.RecommendInternResponseDto +import com.terning.data.dto.response.HomeRecommendInternResponseDto -interface InternDataSource { - suspend fun getRecommendIntern(sortBy: String): BaseResponse +interface HomeDataSource { + suspend fun getRecommendIntern(sortBy: String): BaseResponse } \ No newline at end of file diff --git a/data/src/main/java/com/terning/data/datasourceimpl/HomeDataSourceImpl.kt b/data/src/main/java/com/terning/data/datasourceimpl/HomeDataSourceImpl.kt new file mode 100644 index 000000000..dc146339d --- /dev/null +++ b/data/src/main/java/com/terning/data/datasourceimpl/HomeDataSourceImpl.kt @@ -0,0 +1,14 @@ +package com.terning.data.datasourceimpl + +import com.terning.data.datasource.HomeDataSource +import com.terning.data.dto.BaseResponse +import com.terning.data.dto.response.HomeRecommendInternResponseDto +import com.terning.data.service.HomeService +import javax.inject.Inject + +class HomeDataSourceImpl @Inject constructor( + private val homeService: HomeService +) : HomeDataSource { + override suspend fun getRecommendIntern(sortBy: String): BaseResponse = + homeService.getRecommendIntern(sortBy = sortBy) +} \ No newline at end of file diff --git a/data/src/main/java/com/terning/data/datasourceimpl/InternDataSourceImpl.kt b/data/src/main/java/com/terning/data/datasourceimpl/InternDataSourceImpl.kt deleted file mode 100644 index bdb90ef4b..000000000 --- a/data/src/main/java/com/terning/data/datasourceimpl/InternDataSourceImpl.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.terning.data.datasourceimpl - -import com.terning.data.datasource.InternDataSource -import com.terning.data.dto.BaseResponse -import com.terning.data.dto.response.RecommendInternResponseDto -import com.terning.data.service.InternService -import javax.inject.Inject - -class InternDataSourceImpl @Inject constructor( - private val internService: InternService -) : InternDataSource { - override suspend fun getRecommendIntern(sortBy: String): BaseResponse = - internService.getRecommendIntern(sortBy = sortBy) -} \ No newline at end of file diff --git a/data/src/main/java/com/terning/data/dto/response/HomeRecommendInternResponseDto.kt b/data/src/main/java/com/terning/data/dto/response/HomeRecommendInternResponseDto.kt new file mode 100644 index 000000000..0b6cbab0f --- /dev/null +++ b/data/src/main/java/com/terning/data/dto/response/HomeRecommendInternResponseDto.kt @@ -0,0 +1,32 @@ +package com.terning.data.dto.response + +import com.terning.domain.entity.response.HomeRecommendInternModel +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class HomeRecommendInternResponseDto( + @SerialName("internshipAnnouncementId") + val internshipAnnouncementId: Long, + @SerialName("title") + val title: String, + @SerialName("dDay") + val dDay: String, + @SerialName("workingPeriod") + val workingPeriod: String, + @SerialName("companyImage") + val companyImage: String, + @SerialName("isScrapped") + val isScrapped: Boolean, +) { + fun toRecommendInternEntity(): List = listOf( + HomeRecommendInternModel( + internshipAnnouncementId = this.internshipAnnouncementId, + title = this.title, + dDay = this.dDay, + workingPeriod = this.workingPeriod, + companyImage = this.companyImage, + isScrapped = this.isScrapped, + ) + ) +} diff --git a/data/src/main/java/com/terning/data/dto/response/RecommendInternResponseDto.kt b/data/src/main/java/com/terning/data/dto/response/RecommendInternResponseDto.kt deleted file mode 100644 index 74fad16e9..000000000 --- a/data/src/main/java/com/terning/data/dto/response/RecommendInternResponseDto.kt +++ /dev/null @@ -1,116 +0,0 @@ -package com.terning.data.dto.response - -import com.terning.domain.entity.response.RecommendInternModel -import kotlinx.serialization.SerialName -import kotlinx.serialization.Serializable - -@Serializable -data class RecommendInternResponseDto( - @SerialName("internshipAnnouncementId") - val internshipAnnouncementId: Long, - @SerialName("title") - val title: String, - @SerialName("dDay") - val dDay: String, - @SerialName("workingPeriod") - val workingPeriod: String, - @SerialName("companyImage") - val companyImage: String, - @SerialName("isScrapped") - val isScrapped: Boolean, -) { -// fun toRecommendInternEntity(): List = listOf( -// RecommendInternResponseModel( -// internshipAnnouncementId = this.internshipAnnouncementId, -// title = this.title, -// dDay = this.dDay, -// workingPeriod = this.workingPeriod, -// companyImage = this.companyImage, -// isScrapped = this.isScrapped, -// ) -// ) - - fun toRecommendInternEntity(): List = - listOf( - RecommendInternModel( - internshipAnnouncementId = 1234123132, - title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", - dDay = "D-2", - workingPeriod = "4개월", - companyImage = "https://reqres.in/img/faces/7-image.jpg", - isScrapped = true, - ), - RecommendInternModel( - internshipAnnouncementId = 1234123132, - title = "ㅇㄻㅇㅁㄻㄹㅇㅁㅇㄹ", - dDay = "D-2", - workingPeriod = "4개월", - companyImage = "https://reqres.in/img/faces/7-image.jpg", - isScrapped = false, - ), - RecommendInternModel( - internshipAnnouncementId = 1234123132, - title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", - dDay = "D-2", - workingPeriod = "4개월", - companyImage = "https://reqres.in/img/faces/7-image.jpg", - isScrapped = true, - ), - RecommendInternModel( - internshipAnnouncementId = 1234123132, - title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", - dDay = "D-2", - workingPeriod = "4개월", - companyImage = "https://reqres.in/img/faces/7-image.jpg", - isScrapped = false, - ), - RecommendInternModel( - internshipAnnouncementId = 1234123132, - title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", - dDay = "D-2", - workingPeriod = "4개월", - companyImage = "https://reqres.in/img/faces/7-image.jpg", - isScrapped = true, - ), - RecommendInternModel( - internshipAnnouncementId = 1234123132, - title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", - dDay = "D-2", - workingPeriod = "4개월", - companyImage = "https://reqres.in/img/faces/7-image.jpg", - isScrapped = true, - ), - RecommendInternModel( - internshipAnnouncementId = 1234123132, - title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", - dDay = "D-2", - workingPeriod = "4개월", - companyImage = "https://reqres.in/img/faces/7-image.jpg", - isScrapped = false, - ), - RecommendInternModel( - internshipAnnouncementId = 1234123132, - title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", - dDay = "D-2", - workingPeriod = "4개월", - companyImage = "https://reqres.in/img/faces/7-image.jpg", - isScrapped = true, - ), - RecommendInternModel( - internshipAnnouncementId = 1234123132, - title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", - dDay = "D-2", - workingPeriod = "4개월", - companyImage = "https://reqres.in/img/faces/7-image.jpg", - isScrapped = false, - ), - RecommendInternModel( - internshipAnnouncementId = 1234123132, - title = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", - dDay = "D-2", - workingPeriod = "4개월", - companyImage = "https://reqres.in/img/faces/7-image.jpg", - isScrapped = true, - ), - ) -} diff --git a/data/src/main/java/com/terning/data/repositoryimpl/HomeRepositoryImpl.kt b/data/src/main/java/com/terning/data/repositoryimpl/HomeRepositoryImpl.kt new file mode 100644 index 000000000..a6b881fce --- /dev/null +++ b/data/src/main/java/com/terning/data/repositoryimpl/HomeRepositoryImpl.kt @@ -0,0 +1,15 @@ +package com.terning.data.repositoryimpl + +import com.terning.data.datasource.HomeDataSource +import com.terning.domain.entity.response.HomeRecommendInternModel +import com.terning.domain.repository.HomeRepository +import javax.inject.Inject + +class HomeRepositoryImpl @Inject constructor( + private val homeDataSource: HomeDataSource, +) : HomeRepository { + override suspend fun getRecommendIntern(sortBy: String): Result> = + runCatching { + homeDataSource.getRecommendIntern(sortBy = sortBy).result.toRecommendInternEntity() + } +} \ No newline at end of file diff --git a/data/src/main/java/com/terning/data/repositoryimpl/InternRepositoryImpl.kt b/data/src/main/java/com/terning/data/repositoryimpl/InternRepositoryImpl.kt deleted file mode 100644 index 0dd43f93f..000000000 --- a/data/src/main/java/com/terning/data/repositoryimpl/InternRepositoryImpl.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.terning.data.repositoryimpl - -import com.terning.data.datasource.InternDataSource -import com.terning.domain.entity.response.RecommendInternModel -import com.terning.domain.repository.InternRepository -import javax.inject.Inject - -class InternRepositoryImpl @Inject constructor( - private val internDataSource: InternDataSource, -) : InternRepository { - override suspend fun getRecommendIntern(sortBy: String): Result> = - runCatching { - internDataSource.getRecommendIntern(sortBy = sortBy).result.toRecommendInternEntity() - } -} \ No newline at end of file diff --git a/data/src/main/java/com/terning/data/service/InternService.kt b/data/src/main/java/com/terning/data/service/HomeService.kt similarity index 61% rename from data/src/main/java/com/terning/data/service/InternService.kt rename to data/src/main/java/com/terning/data/service/HomeService.kt index eecda1393..ddbbddf57 100644 --- a/data/src/main/java/com/terning/data/service/InternService.kt +++ b/data/src/main/java/com/terning/data/service/HomeService.kt @@ -1,14 +1,14 @@ package com.terning.data.service import com.terning.data.dto.BaseResponse -import com.terning.data.dto.response.RecommendInternResponseDto +import com.terning.data.dto.response.HomeRecommendInternResponseDto import retrofit2.http.GET import retrofit2.http.Query -interface InternService { +interface HomeService { @GET("api/v1/home") suspend fun getRecommendIntern( @Query("sortBy") sortBy: String, - ): BaseResponse + ): BaseResponse } \ No newline at end of file diff --git a/domain/src/main/java/com/terning/domain/repository/HomeRepository.kt b/domain/src/main/java/com/terning/domain/repository/HomeRepository.kt new file mode 100644 index 000000000..294f00403 --- /dev/null +++ b/domain/src/main/java/com/terning/domain/repository/HomeRepository.kt @@ -0,0 +1,7 @@ +package com.terning.domain.repository + +import com.terning.domain.entity.response.HomeRecommendInternModel + +interface HomeRepository { + suspend fun getRecommendIntern(sortBy: String): Result> +} \ No newline at end of file diff --git a/domain/src/main/java/com/terning/domain/repository/InternRepository.kt b/domain/src/main/java/com/terning/domain/repository/InternRepository.kt deleted file mode 100644 index 9cb86544c..000000000 --- a/domain/src/main/java/com/terning/domain/repository/InternRepository.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.terning.domain.repository - -import com.terning.domain.entity.response.RecommendInternModel - -interface InternRepository { - suspend fun getRecommendIntern(sortBy: String): Result> -} \ No newline at end of file From 583faee7c6ff12e958b57531d0f165a0b0d0677e Mon Sep 17 00:00:00 2001 From: Hyobeen-Park Date: Tue, 16 Jul 2024 08:08:19 +0900 Subject: [PATCH 08/14] =?UTF-8?q?[FEAT/#77]=20sideEffect=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...rnModel.kt => HomeRecommendInternModel.kt} | 4 +- .../terning/feature/home/home/HomeRoute.kt | 50 +++++++++++++------ .../feature/home/home/HomeSideEffect.kt | 8 +++ .../feature/home/home/HomeViewModel.kt | 21 +++++--- 4 files changed, 60 insertions(+), 23 deletions(-) rename domain/src/main/java/com/terning/domain/entity/response/{RecommendInternModel.kt => HomeRecommendInternModel.kt} (84%) create mode 100644 feature/src/main/java/com/terning/feature/home/home/HomeSideEffect.kt diff --git a/domain/src/main/java/com/terning/domain/entity/response/RecommendInternModel.kt b/domain/src/main/java/com/terning/domain/entity/response/HomeRecommendInternModel.kt similarity index 84% rename from domain/src/main/java/com/terning/domain/entity/response/RecommendInternModel.kt rename to domain/src/main/java/com/terning/domain/entity/response/HomeRecommendInternModel.kt index d058b4e1d..18772bc92 100644 --- a/domain/src/main/java/com/terning/domain/entity/response/RecommendInternModel.kt +++ b/domain/src/main/java/com/terning/domain/entity/response/HomeRecommendInternModel.kt @@ -1,10 +1,10 @@ package com.terning.domain.entity.response -data class RecommendInternModel( +data class HomeRecommendInternModel( val internshipAnnouncementId: Long, val title: String, val dDay: String, val workingPeriod: String, val companyImage: String, val isScrapped: Boolean, -) \ No newline at end of file +) diff --git a/feature/src/main/java/com/terning/feature/home/home/HomeRoute.kt b/feature/src/main/java/com/terning/feature/home/home/HomeRoute.kt index ee1f465a1..9c55cbbfd 100644 --- a/feature/src/main/java/com/terning/feature/home/home/HomeRoute.kt +++ b/feature/src/main/java/com/terning/feature/home/home/HomeRoute.kt @@ -17,6 +17,7 @@ import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.Scaffold import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.MutableState import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableIntStateOf @@ -24,10 +25,13 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import androidx.hilt.navigation.compose.hiltViewModel +import androidx.lifecycle.compose.LocalLifecycleOwner import androidx.lifecycle.compose.collectAsStateWithLifecycle +import androidx.lifecycle.flowWithLifecycle import androidx.navigation.NavHostController import com.terning.core.designsystem.component.bottomsheet.SortingBottomSheet import com.terning.core.designsystem.component.button.SortingButton @@ -39,8 +43,9 @@ import com.terning.core.designsystem.theme.Grey200 import com.terning.core.designsystem.theme.TerningTheme import com.terning.core.designsystem.theme.White import com.terning.core.extension.customShadow +import com.terning.core.extension.toast import com.terning.core.state.UiState -import com.terning.domain.entity.response.RecommendInternModel +import com.terning.domain.entity.response.HomeRecommendInternModel import com.terning.feature.R import com.terning.feature.home.changefilter.navigation.navigateChangeFilter import com.terning.feature.home.home.component.HomeFilteringEmptyIntern @@ -63,15 +68,32 @@ fun HomeRoute( mutableIntStateOf(0) } - val recommendInternState by viewModel.recommendInternState.collectAsStateWithLifecycle() - var recommendInternList = emptyList() + val context = LocalContext.current + val lifecycleOwner = LocalLifecycleOwner.current + + val recommendInternState by viewModel.recommendInternState.collectAsStateWithLifecycle( + lifecycleOwner = lifecycleOwner + ) + LaunchedEffect(viewModel.homeSideEffect, lifecycleOwner) { + viewModel.homeSideEffect.flowWithLifecycle(lifecycle = lifecycleOwner.lifecycle) + .collect { sideEffect -> + when (sideEffect) { + is HomeSideEffect.ShowToast -> context.toast(sideEffect.message) + is HomeSideEffect.NavigateToChangeFilter -> navController.navigateChangeFilter() + } + + } + } + + var recommendInternList = emptyList() when (recommendInternState) { is UiState.Empty -> {} is UiState.Loading -> {} - is UiState.Failure -> { } + is UiState.Failure -> {} is UiState.Success -> { - recommendInternList = (recommendInternState as UiState.Success>).data + recommendInternList = + (recommendInternState as UiState.Success>).data } } @@ -87,7 +109,7 @@ fun HomeRoute( fun HomeScreen( currentSortBy: MutableState, onChangeFilterClick: () -> Unit, - recommendInternList: List, + recommendInternList: List, viewModel: HomeViewModel = hiltViewModel(), ) { val userNameState = viewModel.userName @@ -162,9 +184,9 @@ fun HomeScreen( } } - if(recommendInternList.isNotEmpty()) { + if (recommendInternList.isNotEmpty()) { items(recommendInternList.size) { index -> - ShowRecommendIntern(recommendInternModel = recommendInternList[index]) + ShowRecommendIntern(homeRecommendInternModel = recommendInternList[index]) } } } @@ -262,7 +284,7 @@ private fun ShowInternFilter(userNameState: UserNameState, onChangeFilterClick: } @Composable -private fun ShowRecommendIntern(recommendInternModel: RecommendInternModel) { +private fun ShowRecommendIntern(homeRecommendInternModel: HomeRecommendInternModel) { Box( modifier = Modifier .padding(horizontal = 24.dp) @@ -277,11 +299,11 @@ private fun ShowRecommendIntern(recommendInternModel: RecommendInternModel) { ) ) { InternItem( - imageUrl = recommendInternModel.companyImage, - title = recommendInternModel.title, - dateDeadline = recommendInternModel.dDay, - workingPeriod = recommendInternModel.workingPeriod, - isScraped = recommendInternModel.isScrapped, + imageUrl = homeRecommendInternModel.companyImage, + title = homeRecommendInternModel.title, + dateDeadline = homeRecommendInternModel.dDay, + workingPeriod = homeRecommendInternModel.workingPeriod, + isScraped = homeRecommendInternModel.isScrapped, ) } } \ No newline at end of file diff --git a/feature/src/main/java/com/terning/feature/home/home/HomeSideEffect.kt b/feature/src/main/java/com/terning/feature/home/home/HomeSideEffect.kt new file mode 100644 index 000000000..00f82eeb1 --- /dev/null +++ b/feature/src/main/java/com/terning/feature/home/home/HomeSideEffect.kt @@ -0,0 +1,8 @@ +package com.terning.feature.home.home + +import androidx.annotation.StringRes + +sealed class HomeSideEffect { + data class ShowToast(@StringRes val message: Int) : HomeSideEffect() + data object NavigateToChangeFilter : HomeSideEffect() +} \ No newline at end of file diff --git a/feature/src/main/java/com/terning/feature/home/home/HomeViewModel.kt b/feature/src/main/java/com/terning/feature/home/home/HomeViewModel.kt index e3188a146..2802affde 100644 --- a/feature/src/main/java/com/terning/feature/home/home/HomeViewModel.kt +++ b/feature/src/main/java/com/terning/feature/home/home/HomeViewModel.kt @@ -12,21 +12,24 @@ import com.terning.core.designsystem.theme.CalOrange1 import com.terning.core.designsystem.theme.CalPink import com.terning.core.designsystem.theme.CalYellow import com.terning.core.state.UiState -import com.terning.domain.entity.response.RecommendInternModel -import com.terning.domain.repository.InternRepository +import com.terning.domain.entity.response.HomeRecommendInternModel +import com.terning.domain.repository.HomeRepository +import com.terning.feature.R import com.terning.feature.home.home.model.InternFilterData import com.terning.feature.home.home.model.ScrapData import com.terning.feature.home.home.model.UserNameState import com.terning.feature.home.home.model.UserScrapState import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.asSharedFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.launch import javax.inject.Inject @HiltViewModel class HomeViewModel @Inject constructor( - private val internRepository: InternRepository + private val homeRepository: HomeRepository ) : ViewModel() { private val _userName by mutableStateOf( UserNameState( @@ -50,9 +53,12 @@ class HomeViewModel @Inject constructor( val scrapData get() = _scrapState.asStateFlow() private val _recommendInternState = - MutableStateFlow>>(UiState.Empty) + MutableStateFlow>>(UiState.Empty) val recommendInternState get() = _recommendInternState.asStateFlow() + private val _homeSideEffect = MutableSharedFlow() + val homeSideEffect get() = _homeSideEffect.asSharedFlow() + fun setGrade(grade: Int) { userName.internFilter?.grade = grade } @@ -69,12 +75,13 @@ class HomeViewModel @Inject constructor( fun getRecommendInternsData(sortBy: String) { _recommendInternState.value = UiState.Loading viewModelScope.launch { - internRepository.getRecommendIntern(sortBy).onSuccess { internList -> + homeRepository.getRecommendIntern(sortBy).onSuccess { internList -> _recommendInternState.value = UiState.Success(internList) }.onFailure { exception: Throwable -> - _recommendInternState.value = UiState.Failure(exception.message ?: " ") + _recommendInternState.value = UiState.Failure(exception.message ?: "") +// _recommendInternState.value = UiState.Success(toRecommendInternEntity()) + _homeSideEffect.emit(HomeSideEffect.ShowToast(R.string.server_failure)) } - } } } From e4348f610a7d0ad0de26308eb7171cddeecd9e9d Mon Sep 17 00:00:00 2001 From: Hyobeen-Park Date: Tue, 16 Jul 2024 10:52:17 +0900 Subject: [PATCH 09/14] =?UTF-8?q?[CHORE/#77]=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../terning/feature/home/home/HomeRoute.kt | 6 +++- .../feature/home/home/HomeViewModel.kt | 28 +++++++++++++------ 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/feature/src/main/java/com/terning/feature/home/home/HomeRoute.kt b/feature/src/main/java/com/terning/feature/home/home/HomeRoute.kt index 9c55cbbfd..bf2cc5fe1 100644 --- a/feature/src/main/java/com/terning/feature/home/home/HomeRoute.kt +++ b/feature/src/main/java/com/terning/feature/home/home/HomeRoute.kt @@ -81,10 +81,14 @@ fun HomeRoute( is HomeSideEffect.ShowToast -> context.toast(sideEffect.message) is HomeSideEffect.NavigateToChangeFilter -> navController.navigateChangeFilter() } - } } + LaunchedEffect(key1 = currentSortBy) { + viewModel.getRecommendInternsData(currentSortBy.value) + + } + var recommendInternList = emptyList() when (recommendInternState) { diff --git a/feature/src/main/java/com/terning/feature/home/home/HomeViewModel.kt b/feature/src/main/java/com/terning/feature/home/home/HomeViewModel.kt index 2802affde..298e74715 100644 --- a/feature/src/main/java/com/terning/feature/home/home/HomeViewModel.kt +++ b/feature/src/main/java/com/terning/feature/home/home/HomeViewModel.kt @@ -53,12 +53,16 @@ class HomeViewModel @Inject constructor( val scrapData get() = _scrapState.asStateFlow() private val _recommendInternState = - MutableStateFlow>>(UiState.Empty) + MutableStateFlow>>(UiState.Loading) val recommendInternState get() = _recommendInternState.asStateFlow() private val _homeSideEffect = MutableSharedFlow() val homeSideEffect get() = _homeSideEffect.asSharedFlow() + private val _homeSortByState = MutableStateFlow(0) + val homeSortByState get() = _homeSortByState.asStateFlow() + + fun setGrade(grade: Int) { userName.internFilter?.grade = grade } @@ -68,24 +72,32 @@ class HomeViewModel @Inject constructor( } init { - getRecommendInternsData("deadlineSoon") + getRecommendInternsData(sortBy = 0) } - - fun getRecommendInternsData(sortBy: String) { + fun getRecommendInternsData(sortBy: Int) { _recommendInternState.value = UiState.Loading viewModelScope.launch { - homeRepository.getRecommendIntern(sortBy).onSuccess { internList -> - _recommendInternState.value = UiState.Success(internList) - }.onFailure { exception: Throwable -> + homeRepository.getRecommendIntern(SortBy.entries[sortBy].sortBy) + .onSuccess { internList -> + _recommendInternState.value = UiState.Success(internList) + }.onFailure { exception: Throwable -> _recommendInternState.value = UiState.Failure(exception.message ?: "") -// _recommendInternState.value = UiState.Success(toRecommendInternEntity()) _homeSideEffect.emit(HomeSideEffect.ShowToast(R.string.server_failure)) } } } + + enum class SortBy(val sortBy: String) { + EARLIEST("deadlineSoon"), + SHORTEST("shortestDuration"), + LONGEST("longestDuration"), + SCRAP("mostScrapped"), + VIEW_COUNT("mostViewed"), + } } + private fun getScrapData(): List = listOf( ScrapData( internTitle = "[유한킴벌리] 그린캠프 w.대학생 숲 활동가", From ba35b8008d9f80708a380a42426bb1158a153c8d Mon Sep 17 00:00:00 2001 From: Hyobeen-Park Date: Wed, 17 Jul 2024 15:58:49 +0900 Subject: [PATCH 10/14] =?UTF-8?q?[MOD/#77]=20=EC=88=98=EC=A0=95=EB=90=9C?= =?UTF-8?q?=20API=20=EB=AA=85=EC=84=B8=EC=84=9C=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../terning/data/datasource/HomeDataSource.kt | 6 ++++- .../data/datasourceimpl/HomeDataSourceImpl.kt | 8 ++++-- .../HomeRecommendInternResponseDto.kt | 3 +-- .../data/repositoryimpl/HomeRepositoryImpl.kt | 14 +++++++++-- .../com/terning/data/service/HomeService.kt | 5 ++-- .../domain/repository/HomeRepository.kt | 6 ++++- .../terning/feature/home/home/HomeRoute.kt | 11 ++++++-- .../feature/home/home/HomeViewModel.kt | 25 +++++++++++++------ 8 files changed, 58 insertions(+), 20 deletions(-) diff --git a/data/src/main/java/com/terning/data/datasource/HomeDataSource.kt b/data/src/main/java/com/terning/data/datasource/HomeDataSource.kt index c168623a2..f0a619bf5 100644 --- a/data/src/main/java/com/terning/data/datasource/HomeDataSource.kt +++ b/data/src/main/java/com/terning/data/datasource/HomeDataSource.kt @@ -4,5 +4,9 @@ import com.terning.data.dto.BaseResponse import com.terning.data.dto.response.HomeRecommendInternResponseDto interface HomeDataSource { - suspend fun getRecommendIntern(sortBy: String): BaseResponse + suspend fun getRecommendIntern( + sortBy: String, + year: Int, + month: Int + ): BaseResponse> } \ No newline at end of file diff --git a/data/src/main/java/com/terning/data/datasourceimpl/HomeDataSourceImpl.kt b/data/src/main/java/com/terning/data/datasourceimpl/HomeDataSourceImpl.kt index dc146339d..9405550bf 100644 --- a/data/src/main/java/com/terning/data/datasourceimpl/HomeDataSourceImpl.kt +++ b/data/src/main/java/com/terning/data/datasourceimpl/HomeDataSourceImpl.kt @@ -9,6 +9,10 @@ import javax.inject.Inject class HomeDataSourceImpl @Inject constructor( private val homeService: HomeService ) : HomeDataSource { - override suspend fun getRecommendIntern(sortBy: String): BaseResponse = - homeService.getRecommendIntern(sortBy = sortBy) + override suspend fun getRecommendIntern( + sortBy: String, + year: Int, + month: Int + ): BaseResponse> = + homeService.getRecommendIntern(sortBy = sortBy, year = year, month = month) } \ No newline at end of file diff --git a/data/src/main/java/com/terning/data/dto/response/HomeRecommendInternResponseDto.kt b/data/src/main/java/com/terning/data/dto/response/HomeRecommendInternResponseDto.kt index 0b6cbab0f..ced47547d 100644 --- a/data/src/main/java/com/terning/data/dto/response/HomeRecommendInternResponseDto.kt +++ b/data/src/main/java/com/terning/data/dto/response/HomeRecommendInternResponseDto.kt @@ -19,7 +19,7 @@ data class HomeRecommendInternResponseDto( @SerialName("isScrapped") val isScrapped: Boolean, ) { - fun toRecommendInternEntity(): List = listOf( + fun toRecommendInternEntity(): HomeRecommendInternModel = HomeRecommendInternModel( internshipAnnouncementId = this.internshipAnnouncementId, title = this.title, @@ -28,5 +28,4 @@ data class HomeRecommendInternResponseDto( companyImage = this.companyImage, isScrapped = this.isScrapped, ) - ) } diff --git a/data/src/main/java/com/terning/data/repositoryimpl/HomeRepositoryImpl.kt b/data/src/main/java/com/terning/data/repositoryimpl/HomeRepositoryImpl.kt index a6b881fce..39624e1e4 100644 --- a/data/src/main/java/com/terning/data/repositoryimpl/HomeRepositoryImpl.kt +++ b/data/src/main/java/com/terning/data/repositoryimpl/HomeRepositoryImpl.kt @@ -8,8 +8,18 @@ import javax.inject.Inject class HomeRepositoryImpl @Inject constructor( private val homeDataSource: HomeDataSource, ) : HomeRepository { - override suspend fun getRecommendIntern(sortBy: String): Result> = + override suspend fun getRecommendIntern( + sortBy: String, + year: Int, + month: Int + ): Result> = runCatching { - homeDataSource.getRecommendIntern(sortBy = sortBy).result.toRecommendInternEntity() + homeDataSource.getRecommendIntern( + sortBy = sortBy, + year = year, + month = month + ).result.map { + it.toRecommendInternEntity() + } } } \ No newline at end of file diff --git a/data/src/main/java/com/terning/data/service/HomeService.kt b/data/src/main/java/com/terning/data/service/HomeService.kt index ddbbddf57..dbf4a6366 100644 --- a/data/src/main/java/com/terning/data/service/HomeService.kt +++ b/data/src/main/java/com/terning/data/service/HomeService.kt @@ -9,6 +9,7 @@ interface HomeService { @GET("api/v1/home") suspend fun getRecommendIntern( @Query("sortBy") sortBy: String, - ): BaseResponse - + @Query("year") year: Int, + @Query("month") month: Int, + ): BaseResponse> } \ No newline at end of file diff --git a/domain/src/main/java/com/terning/domain/repository/HomeRepository.kt b/domain/src/main/java/com/terning/domain/repository/HomeRepository.kt index 294f00403..c9544b7d8 100644 --- a/domain/src/main/java/com/terning/domain/repository/HomeRepository.kt +++ b/domain/src/main/java/com/terning/domain/repository/HomeRepository.kt @@ -3,5 +3,9 @@ package com.terning.domain.repository import com.terning.domain.entity.response.HomeRecommendInternModel interface HomeRepository { - suspend fun getRecommendIntern(sortBy: String): Result> + suspend fun getRecommendIntern( + sortBy: String, + year: Int, + month: Int + ): Result> } \ No newline at end of file diff --git a/feature/src/main/java/com/terning/feature/home/home/HomeRoute.kt b/feature/src/main/java/com/terning/feature/home/home/HomeRoute.kt index bf2cc5fe1..a99799ef1 100644 --- a/feature/src/main/java/com/terning/feature/home/home/HomeRoute.kt +++ b/feature/src/main/java/com/terning/feature/home/home/HomeRoute.kt @@ -84,9 +84,16 @@ fun HomeRoute( } } - LaunchedEffect(key1 = currentSortBy) { - viewModel.getRecommendInternsData(currentSortBy.value) + val userNameState = viewModel.userName + LaunchedEffect(key1 = currentSortBy) { + with(userNameState.internFilter) { + viewModel.getRecommendInternsData( + currentSortBy.value, + this?.startYear ?: viewModel.currentYear, + this?.startMonth ?: viewModel.currentMonth + ) + } } var recommendInternList = emptyList() diff --git a/feature/src/main/java/com/terning/feature/home/home/HomeViewModel.kt b/feature/src/main/java/com/terning/feature/home/home/HomeViewModel.kt index 298e74715..a8e993dce 100644 --- a/feature/src/main/java/com/terning/feature/home/home/HomeViewModel.kt +++ b/feature/src/main/java/com/terning/feature/home/home/HomeViewModel.kt @@ -25,12 +25,16 @@ import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.asSharedFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.launch +import java.util.Calendar import javax.inject.Inject @HiltViewModel class HomeViewModel @Inject constructor( private val homeRepository: HomeRepository ) : ViewModel() { + val currentYear = Calendar.getInstance().get(Calendar.YEAR) + val currentMonth = Calendar.getInstance().get(Calendar.MONTH) + private val _userName by mutableStateOf( UserNameState( userName = "남지우자랑스러운티엘이되", @@ -38,7 +42,7 @@ class HomeViewModel @Inject constructor( grade = 1, workingPeriod = 1, startYear = 2024, - startMonth = 7, + startMonth = 8, ) ) ) @@ -62,7 +66,6 @@ class HomeViewModel @Inject constructor( private val _homeSortByState = MutableStateFlow(0) val homeSortByState get() = _homeSortByState.asStateFlow() - fun setGrade(grade: Int) { userName.internFilter?.grade = grade } @@ -72,19 +75,25 @@ class HomeViewModel @Inject constructor( } init { - getRecommendInternsData(sortBy = 0) + with(_userName.internFilter) { + getRecommendInternsData( + sortBy = 0, + this?.startYear ?: currentYear, + this?.startMonth ?: currentMonth + ) + } } - fun getRecommendInternsData(sortBy: Int) { + fun getRecommendInternsData(sortBy: Int, year: Int, month: Int) { _recommendInternState.value = UiState.Loading viewModelScope.launch { - homeRepository.getRecommendIntern(SortBy.entries[sortBy].sortBy) + homeRepository.getRecommendIntern(SortBy.entries[sortBy].sortBy, year, month) .onSuccess { internList -> _recommendInternState.value = UiState.Success(internList) }.onFailure { exception: Throwable -> - _recommendInternState.value = UiState.Failure(exception.message ?: "") - _homeSideEffect.emit(HomeSideEffect.ShowToast(R.string.server_failure)) - } + _recommendInternState.value = UiState.Failure(exception.message ?: "") + _homeSideEffect.emit(HomeSideEffect.ShowToast(R.string.server_failure)) + } } } From 05a686f0d404727ee8a3bc7271b5baf9cf1b7a14 Mon Sep 17 00:00:00 2001 From: Hyobeen-Park Date: Wed, 17 Jul 2024 16:41:18 +0900 Subject: [PATCH 11/14] =?UTF-8?q?[CHORE/#77]=20=EC=96=B4=EB=85=B8=ED=85=8C?= =?UTF-8?q?=EC=9D=B4=EC=85=98=20=EB=B0=8F=20=EB=AA=A8=EB=93=88=20=EB=84=A4?= =?UTF-8?q?=EC=9D=B4=EB=B0=8D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/terning/point/di/DataSourceModule.kt | 2 +- app/src/main/java/com/terning/point/di/RepositoryModule.kt | 2 +- app/src/main/java/com/terning/point/di/ServiceModule.kt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/terning/point/di/DataSourceModule.kt b/app/src/main/java/com/terning/point/di/DataSourceModule.kt index 151226ae8..6f2878f5f 100644 --- a/app/src/main/java/com/terning/point/di/DataSourceModule.kt +++ b/app/src/main/java/com/terning/point/di/DataSourceModule.kt @@ -33,5 +33,5 @@ abstract class DataSourceModule { @Binds @Singleton - abstract fun bindRecommendInternDataSource(internDataSourceImpl: HomeDataSourceImpl): HomeDataSource + abstract fun bindHomeInternDataSource(internDataSourceImpl: HomeDataSourceImpl): HomeDataSource } \ No newline at end of file diff --git a/app/src/main/java/com/terning/point/di/RepositoryModule.kt b/app/src/main/java/com/terning/point/di/RepositoryModule.kt index 869bc3bd1..b472b4229 100644 --- a/app/src/main/java/com/terning/point/di/RepositoryModule.kt +++ b/app/src/main/java/com/terning/point/di/RepositoryModule.kt @@ -38,5 +38,5 @@ abstract class RepositoryModule { @Binds @Singleton - abstract fun bindInternRepository(homeRepositoryImpl: HomeRepositoryImpl): HomeRepository + abstract fun bindHomeRepository(homeRepositoryImpl: HomeRepositoryImpl): HomeRepository } \ No newline at end of file diff --git a/app/src/main/java/com/terning/point/di/ServiceModule.kt b/app/src/main/java/com/terning/point/di/ServiceModule.kt index 368da6c5e..db5707b1f 100644 --- a/app/src/main/java/com/terning/point/di/ServiceModule.kt +++ b/app/src/main/java/com/terning/point/di/ServiceModule.kt @@ -35,6 +35,6 @@ object ServiceModule { @Provides @Singleton - fun provideInternService(@OPEN retrofit: Retrofit): HomeService = + fun provideHomeService(@JWT retrofit: Retrofit): HomeService = retrofit.create(HomeService::class.java) } \ No newline at end of file From c1ccb6225d1245cdaaed976caceca59fde228338 Mon Sep 17 00:00:00 2001 From: Hyobeen-Park Date: Thu, 18 Jul 2024 02:05:04 +0900 Subject: [PATCH 12/14] =?UTF-8?q?[CHORE/#77]=20=EB=AA=85=EC=84=B8=EC=84=9C?= =?UTF-8?q?=EC=97=90=20=EB=A7=9E=EA=B2=8C=20=EB=B3=80=EC=88=98=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20=EB=B0=8F=20conflict=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../terning/data/datasource/HomeDataSource.kt | 4 +- .../data/datasourceimpl/HomeDataSourceImpl.kt | 10 ++- .../data/repositoryimpl/HomeRepositoryImpl.kt | 8 +- .../com/terning/data/service/HomeService.kt | 4 +- .../domain/repository/HomeRepository.kt | 4 +- .../home/changefilter/ChangeFilterRoute.kt | 10 +-- .../terning/feature/home/home/HomeRoute.kt | 51 +++++------- .../feature/home/home/HomeViewModel.kt | 82 +++++++------------ 8 files changed, 72 insertions(+), 101 deletions(-) diff --git a/data/src/main/java/com/terning/data/datasource/HomeDataSource.kt b/data/src/main/java/com/terning/data/datasource/HomeDataSource.kt index 917d6c1d2..3a5f89a54 100644 --- a/data/src/main/java/com/terning/data/datasource/HomeDataSource.kt +++ b/data/src/main/java/com/terning/data/datasource/HomeDataSource.kt @@ -9,7 +9,7 @@ interface HomeDataSource { suspend fun getRecommendIntern( sortBy: String, - year: Int, - month: Int + startYear: Int, + startMonth: Int ): BaseResponse> } \ No newline at end of file diff --git a/data/src/main/java/com/terning/data/datasourceimpl/HomeDataSourceImpl.kt b/data/src/main/java/com/terning/data/datasourceimpl/HomeDataSourceImpl.kt index 211b59cb6..a7c8283db 100644 --- a/data/src/main/java/com/terning/data/datasourceimpl/HomeDataSourceImpl.kt +++ b/data/src/main/java/com/terning/data/datasourceimpl/HomeDataSourceImpl.kt @@ -15,8 +15,12 @@ class HomeDataSourceImpl @Inject constructor( override suspend fun getRecommendIntern( sortBy: String, - year: Int, - month: Int + startYear: Int, + startMonth: Int ): BaseResponse> = - homeService.getRecommendIntern(sortBy = sortBy, year = year, month = month) + homeService.getRecommendIntern( + sortBy = sortBy, + startYear = startYear, + startMonth = startMonth + ) } \ No newline at end of file diff --git a/data/src/main/java/com/terning/data/repositoryimpl/HomeRepositoryImpl.kt b/data/src/main/java/com/terning/data/repositoryimpl/HomeRepositoryImpl.kt index 4942396c0..cad58afc5 100644 --- a/data/src/main/java/com/terning/data/repositoryimpl/HomeRepositoryImpl.kt +++ b/data/src/main/java/com/terning/data/repositoryimpl/HomeRepositoryImpl.kt @@ -18,14 +18,14 @@ class HomeRepositoryImpl @Inject constructor( override suspend fun getRecommendIntern( sortBy: String, - year: Int, - month: Int + startYear: Int, + startMonth: Int ): Result> = runCatching { homeDataSource.getRecommendIntern( sortBy = sortBy, - year = year, - month = month + startYear = startYear, + startMonth = startMonth ).result.map { it.toRecommendInternEntity() } diff --git a/data/src/main/java/com/terning/data/service/HomeService.kt b/data/src/main/java/com/terning/data/service/HomeService.kt index 1bd2f2fe3..91b53e17d 100644 --- a/data/src/main/java/com/terning/data/service/HomeService.kt +++ b/data/src/main/java/com/terning/data/service/HomeService.kt @@ -13,7 +13,7 @@ interface HomeService { @GET("api/v1/home") suspend fun getRecommendIntern( @Query("sortBy") sortBy: String, - @Query("year") year: Int, - @Query("month") month: Int, + @Query("startYear") startYear: Int, + @Query("startMonth") startMonth: Int, ): BaseResponse> } \ No newline at end of file diff --git a/domain/src/main/java/com/terning/domain/repository/HomeRepository.kt b/domain/src/main/java/com/terning/domain/repository/HomeRepository.kt index 9f72da714..9aaed4834 100644 --- a/domain/src/main/java/com/terning/domain/repository/HomeRepository.kt +++ b/domain/src/main/java/com/terning/domain/repository/HomeRepository.kt @@ -8,7 +8,7 @@ interface HomeRepository { suspend fun getRecommendIntern( sortBy: String, - year: Int, - month: Int + startYear: Int, + startMonth: Int ): Result> } \ No newline at end of file diff --git a/feature/src/main/java/com/terning/feature/home/changefilter/ChangeFilterRoute.kt b/feature/src/main/java/com/terning/feature/home/changefilter/ChangeFilterRoute.kt index c9285ddf3..1ca221765 100644 --- a/feature/src/main/java/com/terning/feature/home/changefilter/ChangeFilterRoute.kt +++ b/feature/src/main/java/com/terning/feature/home/changefilter/ChangeFilterRoute.kt @@ -43,11 +43,11 @@ fun ChangeFilterScreen( viewModel: HomeViewModel = hiltViewModel(), ) { val isGradeButtonValid = remember { - mutableStateOf(viewModel.userName.internFilter?.grade != null) + mutableStateOf(viewModel.userName.value.internFilter?.grade != null) } val isWorkingPeriodButtonValid = remember { - mutableStateOf(viewModel.userName.internFilter?.workingPeriod != null) + mutableStateOf(viewModel.userName.value.internFilter?.workingPeriod != null) } Scaffold( @@ -77,9 +77,8 @@ fun ChangeFilterScreen( ) ChangeFilteringRadioGroup( filterType = 0, - internFilterData = viewModel.userName.internFilter, + internFilterData = viewModel.userName.value.internFilter, onButtonClick = { - viewModel.setGrade(it) isGradeButtonValid.value = true } ) @@ -105,9 +104,8 @@ fun ChangeFilterScreen( ) ChangeFilteringRadioGroup( filterType = 1, - internFilterData = viewModel.userName.internFilter, + internFilterData = viewModel.userName.value.internFilter, onButtonClick = { - viewModel.setWorkingPeriod(it) isWorkingPeriodButtonValid.value = true } ) diff --git a/feature/src/main/java/com/terning/feature/home/home/HomeRoute.kt b/feature/src/main/java/com/terning/feature/home/home/HomeRoute.kt index 2eb177bb3..fe79143b1 100644 --- a/feature/src/main/java/com/terning/feature/home/home/HomeRoute.kt +++ b/feature/src/main/java/com/terning/feature/home/home/HomeRoute.kt @@ -3,6 +3,7 @@ package com.terning.feature.home.home import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.background import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.Row @@ -41,17 +42,16 @@ import com.terning.core.designsystem.theme.Grey150 import com.terning.core.designsystem.theme.Grey200 import com.terning.core.designsystem.theme.TerningTheme import com.terning.core.designsystem.theme.White -import com.terning.core.extension.toast -import com.terning.core.state.UiState -import com.terning.domain.entity.response.HomeTodayInternModel import com.terning.core.extension.customShadow import com.terning.core.extension.toast import com.terning.core.state.UiState import com.terning.domain.entity.response.HomeRecommendInternModel +import com.terning.domain.entity.response.HomeTodayInternModel import com.terning.feature.R import com.terning.feature.home.changefilter.navigation.navigateChangeFilter import com.terning.feature.home.home.component.HomeFilteringEmptyIntern import com.terning.feature.home.home.component.HomeFilteringScreen +import com.terning.feature.home.home.component.HomeRecommendEmptyIntern import com.terning.feature.home.home.component.HomeTodayEmptyIntern import com.terning.feature.home.home.component.HomeTodayIntern import com.terning.feature.home.home.model.UserNameState @@ -72,10 +72,7 @@ fun HomeRoute( val context = LocalContext.current val homeTodayState by viewModel.homeTodayState.collectAsStateWithLifecycle() - - val recommendInternState by viewModel.recommendInternState.collectAsStateWithLifecycle( - lifecycleOwner = lifecycleOwner - ) + val homeRecommendInternState by viewModel.homeRecommendInternState.collectAsStateWithLifecycle() LaunchedEffect(viewModel.homeSideEffect, lifecycleOwner) { viewModel.homeSideEffect.flowWithLifecycle(lifecycle = lifecycleOwner.lifecycle) @@ -95,34 +92,30 @@ fun HomeRoute( else -> emptyList() } - val userNameState = viewModel.userName - - LaunchedEffect(key1 = currentSortBy) { - with(userNameState.internFilter) { - viewModel.getRecommendInternsData( - currentSortBy.value, - this?.startYear ?: viewModel.currentYear, - this?.startMonth ?: viewModel.currentMonth - ) + val homeRecommendInternList = when (homeRecommendInternState) { + is UiState.Success -> { + (homeRecommendInternState as UiState.Success>).data } + + else -> emptyList() } - var recommendInternList = emptyList() + val userNameState = viewModel.userName - when (recommendInternState) { - is UiState.Empty -> {} - is UiState.Loading -> {} - is UiState.Failure -> {} - is UiState.Success -> { - recommendInternList = - (recommendInternState as UiState.Success>).data + LaunchedEffect(currentSortBy) { + with(userNameState.value.internFilter) { + viewModel.getRecommendInternsData( + sortBy = currentSortBy.value, + startYear = this?.startYear ?: viewModel.currentYear, + startMonth = this?.startMonth ?: viewModel.currentMonth, + ) } } HomeScreen( currentSortBy, homeTodayInternList = homeTodayInternList, - recommendInternList = recommendInternList, + recommendInternList = homeRecommendInternList, onChangeFilterClick = { navController.navigateChangeFilter() }, ) } @@ -137,8 +130,6 @@ fun HomeScreen( viewModel: HomeViewModel = hiltViewModel(), ) { val userNameState = viewModel.userName - val userScrapState by viewModel.scrapData.collectAsStateWithLifecycle() - val recommendInternData by viewModel.recommendInternData.collectAsStateWithLifecycle() var sheetState by remember { mutableStateOf(false) } if (sheetState) { @@ -174,7 +165,7 @@ fun HomeScreen( modifier = Modifier .padding(bottom = 16.dp) ) { - ShowMainTitleWithName(userNameState) + ShowMainTitleWithName(userNameState.value) ShowTodayIntern(homeTodayInternList = homeTodayInternList) } } @@ -184,7 +175,7 @@ fun HomeScreen( .background(White) ) { ShowRecommendTitle() - ShowInternFilter(userNameState = userNameState, onChangeFilterClick) + ShowInternFilter(userNameState = userNameState.value, onChangeFilterClick) HorizontalDivider( thickness = 4.dp, @@ -216,7 +207,7 @@ fun HomeScreen( } } - if (userNameState.internFilter == null) { + if (userNameState.value.internFilter == null) { HomeFilteringEmptyIntern( modifier = Modifier .padding(horizontal = 24.dp) diff --git a/feature/src/main/java/com/terning/feature/home/home/HomeViewModel.kt b/feature/src/main/java/com/terning/feature/home/home/HomeViewModel.kt index 15fbd10c7..0f2478469 100644 --- a/feature/src/main/java/com/terning/feature/home/home/HomeViewModel.kt +++ b/feature/src/main/java/com/terning/feature/home/home/HomeViewModel.kt @@ -1,6 +1,5 @@ package com.terning.feature.home.home -import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope @@ -34,19 +33,23 @@ class HomeViewModel @Inject constructor( MutableStateFlow>>(UiState.Loading) val homeTodayState get() = _homeTodayState.asStateFlow() + private val _homeRecommendInternState = + MutableStateFlow>>(UiState.Loading) + val homeRecommendInternState get() = _homeRecommendInternState.asStateFlow() + + private val _homeSortByState = MutableStateFlow(0) + val homeSortByState get() = _homeSortByState.asStateFlow() + init { getHomeTodayInternList() - - with(_userName.internFilter) { - getRecommendInternsData( - sortBy = 0, - this?.startYear ?: currentYear, - this?.startMonth ?: currentMonth - ) - } + getRecommendInternsData( + sortBy = 0, + startYear = 2024, + startMonth = 8, + ) } - private val _userName by mutableStateOf( + private val _userName = mutableStateOf( UserNameState( userName = "남지우자랑스러운티엘이되", internFilter = @@ -60,45 +63,31 @@ class HomeViewModel @Inject constructor( ) val userName get() = _userName - private val _scrapState = MutableStateFlow( - UserScrapState( - isScrapExist = true, - scrapData = getScrapData() - ) - ) - val scrapData get() = _scrapState.asStateFlow() - - private val _recommendInternState = - MutableStateFlow>>(UiState.Loading) - val recommendInternState get() = _recommendInternState.asStateFlow() - - private val _homeSideEffect = MutableSharedFlow() - val homeSideEffect get() = _homeSideEffect.asSharedFlow() - - private val _homeSortByState = MutableStateFlow(0) - val homeSortByState get() = _homeSortByState.asStateFlow() - - fun setGrade(grade: Int) { - userName.internFilter?.grade = grade - } - - fun setWorkingPeriod(workingPeriod: Int) { - userName.internFilter?.workingPeriod = workingPeriod - } - - fun getRecommendInternsData(sortBy: Int, year: Int, month: Int) { - _recommendInternState.value = UiState.Loading + fun getRecommendInternsData(sortBy: Int, startYear: Int, startMonth: Int) { + _homeRecommendInternState.value = UiState.Loading viewModelScope.launch { - homeRepository.getRecommendIntern(SortBy.entries[sortBy].sortBy, year, month) + homeRepository.getRecommendIntern(SortBy.entries[sortBy].sortBy, startYear, startMonth) .onSuccess { internList -> - _recommendInternState.value = UiState.Success(internList) + _homeRecommendInternState.value = UiState.Success(internList) }.onFailure { exception: Throwable -> - _recommendInternState.value = UiState.Failure(exception.message ?: "") + _homeRecommendInternState.value = UiState.Failure(exception.message ?: "") _homeSideEffect.emit(HomeSideEffect.ShowToast(R.string.server_failure)) } } } + fun getHomeTodayInternList() { + _homeTodayState.value = UiState.Loading + viewModelScope.launch { + homeRepository.getHomeTodayInternList().onSuccess { internList -> + _homeTodayState.value = UiState.Success(internList) + }.onFailure { exception: Throwable -> + _homeTodayState.value = UiState.Failure(exception.message ?: "") + _homeSideEffect.emit(HomeSideEffect.ShowToast(R.string.server_failure)) + } + } + } + enum class SortBy(val sortBy: String) { EARLIEST("deadlineSoon"), SHORTEST("shortestDuration"), @@ -108,14 +97,3 @@ class HomeViewModel @Inject constructor( } } -fun getHomeTodayInternList() { - _homeTodayState.value = UiState.Loading - viewModelScope.launch { - homeRepository.getHomeTodayInternList().onSuccess { internList -> - _homeTodayState.value = UiState.Success(internList) - }.onFailure { exception: Throwable -> - _homeTodayState.value = UiState.Failure(exception.message ?: "") - _homeSideEffect.emit(HomeSideEffect.ShowToast(R.string.server_failure)) - } - } -} \ No newline at end of file From e6d2228fd7213c274a79dc590928908a77d55771 Mon Sep 17 00:00:00 2001 From: Hyobeen-Park Date: Thu, 18 Jul 2024 02:42:33 +0900 Subject: [PATCH 13/14] =?UTF-8?q?[CHORE/#77]=20dto=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/dto/response/HomeRecommendInternResponseDto.kt | 2 +- .../main/java/com/terning/feature/home/home/HomeViewModel.kt | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/data/src/main/java/com/terning/data/dto/response/HomeRecommendInternResponseDto.kt b/data/src/main/java/com/terning/data/dto/response/HomeRecommendInternResponseDto.kt index ced47547d..7793aa0ee 100644 --- a/data/src/main/java/com/terning/data/dto/response/HomeRecommendInternResponseDto.kt +++ b/data/src/main/java/com/terning/data/dto/response/HomeRecommendInternResponseDto.kt @@ -6,7 +6,7 @@ import kotlinx.serialization.Serializable @Serializable data class HomeRecommendInternResponseDto( - @SerialName("internshipAnnouncementId") + @SerialName("intershipAnnouncementId") val internshipAnnouncementId: Long, @SerialName("title") val title: String, diff --git a/feature/src/main/java/com/terning/feature/home/home/HomeViewModel.kt b/feature/src/main/java/com/terning/feature/home/home/HomeViewModel.kt index 0f2478469..c89828ab1 100644 --- a/feature/src/main/java/com/terning/feature/home/home/HomeViewModel.kt +++ b/feature/src/main/java/com/terning/feature/home/home/HomeViewModel.kt @@ -95,5 +95,4 @@ class HomeViewModel @Inject constructor( SCRAP("mostScrapped"), VIEW_COUNT("mostViewed"), } -} - +} \ No newline at end of file From 65a599fd9dabb28f29b4993db1fdd782836dc756 Mon Sep 17 00:00:00 2001 From: Hyobeen-Park Date: Thu, 18 Jul 2024 02:54:30 +0900 Subject: [PATCH 14/14] =?UTF-8?q?[CHORE/#77]=20enum=20class=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/terning/feature/home/home/HomeViewModel.kt | 9 +-------- .../java/com/terning/feature/home/home/model/SortBy.kt | 9 +++++++++ 2 files changed, 10 insertions(+), 8 deletions(-) create mode 100644 feature/src/main/java/com/terning/feature/home/home/model/SortBy.kt diff --git a/feature/src/main/java/com/terning/feature/home/home/HomeViewModel.kt b/feature/src/main/java/com/terning/feature/home/home/HomeViewModel.kt index c89828ab1..374fe46bd 100644 --- a/feature/src/main/java/com/terning/feature/home/home/HomeViewModel.kt +++ b/feature/src/main/java/com/terning/feature/home/home/HomeViewModel.kt @@ -9,6 +9,7 @@ import com.terning.domain.entity.response.HomeTodayInternModel import com.terning.domain.repository.HomeRepository import com.terning.feature.R import com.terning.feature.home.home.model.InternFilterData +import com.terning.feature.home.home.model.SortBy import com.terning.feature.home.home.model.UserNameState import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableSharedFlow @@ -87,12 +88,4 @@ class HomeViewModel @Inject constructor( } } } - - enum class SortBy(val sortBy: String) { - EARLIEST("deadlineSoon"), - SHORTEST("shortestDuration"), - LONGEST("longestDuration"), - SCRAP("mostScrapped"), - VIEW_COUNT("mostViewed"), - } } \ No newline at end of file diff --git a/feature/src/main/java/com/terning/feature/home/home/model/SortBy.kt b/feature/src/main/java/com/terning/feature/home/home/model/SortBy.kt new file mode 100644 index 000000000..b820cd6ca --- /dev/null +++ b/feature/src/main/java/com/terning/feature/home/home/model/SortBy.kt @@ -0,0 +1,9 @@ +package com.terning.feature.home.home.model + +enum class SortBy(val sortBy: String) { + EARLIEST("deadlineSoon"), + SHORTEST("shortestDuration"), + LONGEST("longestDuration"), + SCRAP("mostScrapped"), + VIEW_COUNT("mostViewed"), +} \ No newline at end of file