diff --git a/app/src/main/java/com/terning/point/di/AuthInterceptor.kt b/app/src/main/java/com/terning/point/di/AuthInterceptor.kt index d54fffc06..c1009468d 100644 --- a/app/src/main/java/com/terning/point/di/AuthInterceptor.kt +++ b/app/src/main/java/com/terning/point/di/AuthInterceptor.kt @@ -77,7 +77,10 @@ class AuthInterceptor @Inject constructor( } private fun Request.Builder.newAuthBuilder() = - this.addHeader(AUTHORIZATION, "$BEARER ${terningDataStore.accessToken}") + this.addHeader( + AUTHORIZATION, "$BEARER " + //+ "$TEMP_TOKEN" + ) companion object { private const val CODE_TOKEN_EXPIRED = 401 @@ -85,5 +88,4 @@ class AuthInterceptor @Inject constructor( private const val BEARER = "Bearer" private const val AUTHORIZATION = "Authorization" } - } \ No newline at end of file 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 ca8f28b7d..055317328 100644 --- a/app/src/main/java/com/terning/point/di/DataSourceModule.kt +++ b/app/src/main/java/com/terning/point/di/DataSourceModule.kt @@ -1,12 +1,14 @@ package com.terning.point.di import com.terning.data.datasource.AuthDataSource +import com.terning.data.datasource.CalendarDataSource +import com.terning.data.datasource.FilteringDataSource import com.terning.data.datasource.SearchDataSource import com.terning.data.datasource.TokenReissueDataSource import com.terning.data.datasourceimpl.AuthDataSourceImpl -import com.terning.data.datasourceimpl.SearchDataSourceImpl -import com.terning.data.datasource.CalendarDataSource import com.terning.data.datasourceimpl.CalendarDataSourceImpl +import com.terning.data.datasourceimpl.FilteringDataSourceImpl +import com.terning.data.datasourceimpl.SearchDataSourceImpl import com.terning.data.datasourceimpl.TokenReissueDataSourceImpl import dagger.Binds import dagger.Module @@ -34,4 +36,8 @@ abstract class DataSourceModule { @Binds @Singleton abstract fun bindTokenReissueDataSource(tokenReissueDataSourceImpl: TokenReissueDataSourceImpl): TokenReissueDataSource + + @Binds + @Singleton + abstract fun bindFilteringDataSource(filteringDataSourceImpl: FilteringDataSourceImpl): FilteringDataSource } \ No newline at end of file diff --git a/app/src/main/java/com/terning/point/di/DataStoreModule.kt b/app/src/main/java/com/terning/point/di/DataStoreModule.kt index ca4b09d65..bfc402ad1 100644 --- a/app/src/main/java/com/terning/point/di/DataStoreModule.kt +++ b/app/src/main/java/com/terning/point/di/DataStoreModule.kt @@ -24,4 +24,5 @@ object DataStoreModule { @Singleton fun provideTerningDataStore(dataStoreImpl: TerningDataStoreImpl): TerningDataStore = dataStoreImpl + } \ 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 47fc858f4..c9bd66b2a 100644 --- a/app/src/main/java/com/terning/point/di/RepositoryModule.kt +++ b/app/src/main/java/com/terning/point/di/RepositoryModule.kt @@ -1,12 +1,14 @@ package com.terning.point.di import com.terning.data.repositoryimpl.AuthRepositoryImpl -import com.terning.data.repositoryimpl.SearchRepositoryImpl import com.terning.data.repositoryimpl.CalendarRepositoryImpl +import com.terning.data.repositoryimpl.FilteringRepositoryImpl +import com.terning.data.repositoryimpl.SearchRepositoryImpl import com.terning.data.repositoryimpl.TokenReissueRepositoryImpl import com.terning.data.repositoryimpl.TokenRepositoryImpl import com.terning.domain.repository.AuthRepository import com.terning.domain.repository.CalendarRepository +import com.terning.domain.repository.FilteringRepository import com.terning.domain.repository.SearchRepository import com.terning.domain.repository.TokenReissueRepository import com.terning.domain.repository.TokenRepository @@ -39,4 +41,8 @@ abstract class RepositoryModule { @Binds @Singleton abstract fun bindTokenReissueRepository(tokenReissueRepositoryImpl: TokenReissueRepositoryImpl): TokenReissueRepository + + @Binds + @Singleton + abstract fun bindFilteringRepository(filteringRepositoryImpl: FilteringRepositoryImpl): FilteringRepository } \ 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 57edf477f..00b32ee1d 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,7 @@ package com.terning.point.di import com.terning.data.service.AuthService +import com.terning.data.service.FilteringService import com.terning.data.service.CalendarService import com.terning.data.service.SearchService import com.terning.data.service.TokenReissueService @@ -37,4 +38,9 @@ object ServiceModule { @Singleton fun provideTokenReissueService(@REISSUE retrofit: Retrofit): TokenReissueService = retrofit.create(TokenReissueService::class.java) + + @Provides + @Singleton + fun provideFilteringService(@JWT retrofit: Retrofit): FilteringService = + retrofit.create(FilteringService::class.java) } \ No newline at end of file diff --git a/data/src/main/java/com/terning/data/datasource/FilteringDataSource.kt b/data/src/main/java/com/terning/data/datasource/FilteringDataSource.kt new file mode 100644 index 000000000..fa9778fb2 --- /dev/null +++ b/data/src/main/java/com/terning/data/datasource/FilteringDataSource.kt @@ -0,0 +1,8 @@ +package com.terning.data.datasource + +import com.terning.data.dto.NonDataBaseResponse +import com.terning.data.dto.request.FilteringRequestDto + +interface FilteringDataSource { + suspend fun postFiltering(userId: Long, request: FilteringRequestDto): NonDataBaseResponse +} \ No newline at end of file diff --git a/data/src/main/java/com/terning/data/datasourceimpl/FilteringDataSourceImpl.kt b/data/src/main/java/com/terning/data/datasourceimpl/FilteringDataSourceImpl.kt new file mode 100644 index 000000000..19443a235 --- /dev/null +++ b/data/src/main/java/com/terning/data/datasourceimpl/FilteringDataSourceImpl.kt @@ -0,0 +1,17 @@ +package com.terning.data.datasourceimpl + +import com.terning.data.datasource.FilteringDataSource +import com.terning.data.dto.NonDataBaseResponse +import com.terning.data.dto.request.FilteringRequestDto +import com.terning.data.service.FilteringService +import javax.inject.Inject + +class FilteringDataSourceImpl @Inject constructor( + private val filteringService: FilteringService +) : FilteringDataSource { + override suspend fun postFiltering( + userId: Long, + request: FilteringRequestDto + ): NonDataBaseResponse = + filteringService.postFilteringService(userId, request) +} \ No newline at end of file diff --git a/data/src/main/java/com/terning/data/dto/request/FilteringRequestDto.kt b/data/src/main/java/com/terning/data/dto/request/FilteringRequestDto.kt new file mode 100644 index 000000000..61606ef98 --- /dev/null +++ b/data/src/main/java/com/terning/data/dto/request/FilteringRequestDto.kt @@ -0,0 +1,25 @@ +package com.terning.data.dto.request + +import com.terning.domain.entity.request.FilteringRequestModel +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class FilteringRequestDto( + @SerialName("grade") + val grade: Int, + @SerialName("workingPeriod") + val workingPeriod: Int, + @SerialName("startYear") + val startYear: Int, + @SerialName("startMonth") + val startMonth: Int +) + +fun FilteringRequestModel.toFilteringRequestDto(): FilteringRequestDto = + FilteringRequestDto( + grade = grade, + workingPeriod = workingPeriod, + startYear = startYear, + startMonth = startMonth + ) \ No newline at end of file diff --git a/data/src/main/java/com/terning/data/repositoryimpl/FilteringRepositoryImpl.kt b/data/src/main/java/com/terning/data/repositoryimpl/FilteringRepositoryImpl.kt new file mode 100644 index 000000000..e98de70e3 --- /dev/null +++ b/data/src/main/java/com/terning/data/repositoryimpl/FilteringRepositoryImpl.kt @@ -0,0 +1,22 @@ +package com.terning.data.repositoryimpl + +import com.terning.data.datasource.FilteringDataSource +import com.terning.data.dto.request.toFilteringRequestDto +import com.terning.domain.entity.request.FilteringRequestModel +import com.terning.domain.repository.FilteringRepository +import javax.inject.Inject + +class FilteringRepositoryImpl @Inject constructor( + private val filteringDataSource: FilteringDataSource +) : FilteringRepository { + override suspend fun postFiltering( + userId: Long, + request: FilteringRequestModel + ): Result = + runCatching { + filteringDataSource.postFiltering( + userId, + request.toFilteringRequestDto() + ) + } +} \ No newline at end of file diff --git a/data/src/main/java/com/terning/data/repositoryimpl/TokenRepositoryImpl.kt b/data/src/main/java/com/terning/data/repositoryimpl/TokenRepositoryImpl.kt index 5d8fef947..e0465112f 100644 --- a/data/src/main/java/com/terning/data/repositoryimpl/TokenRepositoryImpl.kt +++ b/data/src/main/java/com/terning/data/repositoryimpl/TokenRepositoryImpl.kt @@ -20,6 +20,8 @@ class TokenRepositoryImpl @Inject constructor( terningDataStore.userId = userId } + override fun getUserId(): Long = terningDataStore.userId + override fun clearInfo() { terningDataStore.clearInfo() } diff --git a/data/src/main/java/com/terning/data/service/FilteringService.kt b/data/src/main/java/com/terning/data/service/FilteringService.kt new file mode 100644 index 000000000..9dcb125e9 --- /dev/null +++ b/data/src/main/java/com/terning/data/service/FilteringService.kt @@ -0,0 +1,15 @@ +package com.terning.data.service + +import com.terning.data.dto.NonDataBaseResponse +import com.terning.data.dto.request.FilteringRequestDto +import retrofit2.http.Body +import retrofit2.http.Header +import retrofit2.http.POST + +interface FilteringService { + @POST("/api/v1/auth/sign-up/filter") + suspend fun postFilteringService( + @Header("User-Id") userId: Long, + @Body request: FilteringRequestDto + ): NonDataBaseResponse +} \ No newline at end of file diff --git a/domain/src/main/java/com/terning/domain/entity/request/FilteringRequestModel.kt b/domain/src/main/java/com/terning/domain/entity/request/FilteringRequestModel.kt new file mode 100644 index 000000000..fd6205dbc --- /dev/null +++ b/domain/src/main/java/com/terning/domain/entity/request/FilteringRequestModel.kt @@ -0,0 +1,8 @@ +package com.terning.domain.entity.request + +data class FilteringRequestModel( + val grade: Int, + val workingPeriod: Int, + val startYear: Int, + val startMonth: Int +) \ No newline at end of file diff --git a/domain/src/main/java/com/terning/domain/repository/FilteringRepository.kt b/domain/src/main/java/com/terning/domain/repository/FilteringRepository.kt new file mode 100644 index 000000000..5828acf3c --- /dev/null +++ b/domain/src/main/java/com/terning/domain/repository/FilteringRepository.kt @@ -0,0 +1,10 @@ +package com.terning.domain.repository + +import com.terning.domain.entity.request.FilteringRequestModel + +interface FilteringRepository { + suspend fun postFiltering( + userId: Long, + request: FilteringRequestModel + ): Result +} \ No newline at end of file diff --git a/domain/src/main/java/com/terning/domain/repository/TokenRepository.kt b/domain/src/main/java/com/terning/domain/repository/TokenRepository.kt index d55d469ef..f9aad28a3 100644 --- a/domain/src/main/java/com/terning/domain/repository/TokenRepository.kt +++ b/domain/src/main/java/com/terning/domain/repository/TokenRepository.kt @@ -9,5 +9,7 @@ interface TokenRepository { fun setUserId(userId: Long) + fun getUserId() : Long + fun clearInfo() } diff --git a/feature/src/main/java/com/terning/feature/onboarding/filtering/FilteringOneScreen.kt b/feature/src/main/java/com/terning/feature/filtering/filtering/FilteringOneScreen.kt similarity index 79% rename from feature/src/main/java/com/terning/feature/onboarding/filtering/FilteringOneScreen.kt rename to feature/src/main/java/com/terning/feature/filtering/filtering/FilteringOneScreen.kt index 33c76066f..820f67c76 100644 --- a/feature/src/main/java/com/terning/feature/onboarding/filtering/FilteringOneScreen.kt +++ b/feature/src/main/java/com/terning/feature/filtering/filtering/FilteringOneScreen.kt @@ -1,4 +1,4 @@ -package com.terning.feature.onboarding.filtering +package com.terning.feature.filtering.filtering import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Spacer @@ -7,8 +7,11 @@ import androidx.compose.foundation.layout.padding import androidx.compose.material3.Scaffold import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp @@ -19,18 +22,21 @@ import com.terning.core.designsystem.component.image.TerningImage import com.terning.core.designsystem.component.topappbar.BackButtonTopAppBar import com.terning.core.designsystem.theme.TerningTheme import com.terning.feature.R -import com.terning.feature.onboarding.filtering.component.StatusOneRadioGroup -import com.terning.feature.onboarding.filtering.navigation.navigateFilteringTwo +import com.terning.feature.filtering.filtering.component.StatusOneRadioGroup +import com.terning.feature.filtering.filtering.navigation.navigateFilteringTwo @Composable fun FilteringOneScreen( + name: String, navController: NavController, modifier: Modifier = Modifier, - filteringViewModel: FilteringViewModel = hiltViewModel(), - onButtonClick: () -> Unit = {}, + viewModel: FilteringViewModel = hiltViewModel(), + onButtonClick: (Int) -> Unit = {}, ) { val isButtonValid = remember { mutableStateOf(false) } + var grade by remember { mutableIntStateOf(-1) } + Scaffold( modifier = modifier, topBar = { @@ -54,7 +60,7 @@ fun FilteringOneScreen( Text( text = stringResource( id = R.string.filtering_status1_title, - filteringViewModel.name + name ), style = TerningTheme.typography.title3, modifier = modifier.padding( @@ -63,7 +69,10 @@ fun FilteringOneScreen( ) ) Text( - text = stringResource(id = R.string.filtering_status1_sub, filteringViewModel.name), + text = stringResource( + id = R.string.filtering_status1_sub, + name + ), style = TerningTheme.typography.body5, modifier = modifier.padding( top = 3.dp, @@ -72,9 +81,10 @@ fun FilteringOneScreen( ) ) StatusOneRadioGroup( - onButtonClick = { - onButtonClick() + onButtonClick = { index -> + onButtonClick(index) isButtonValid.value = true + grade = index } ) Text( @@ -90,7 +100,7 @@ fun FilteringOneScreen( style = TerningTheme.typography.button0, paddingVertical = 20.dp, text = R.string.filtering_button, - onButtonClick = { navController.navigateFilteringTwo() }, + onButtonClick = { navController.navigateFilteringTwo(grade) }, modifier = modifier.padding(bottom = 12.dp), isEnabled = isButtonValid.value ) diff --git a/feature/src/main/java/com/terning/feature/filtering/filtering/FilteringSideEffect.kt b/feature/src/main/java/com/terning/feature/filtering/filtering/FilteringSideEffect.kt new file mode 100644 index 000000000..52c9b3a68 --- /dev/null +++ b/feature/src/main/java/com/terning/feature/filtering/filtering/FilteringSideEffect.kt @@ -0,0 +1,8 @@ +package com.terning.feature.filtering.filtering + +import androidx.annotation.StringRes + +sealed class FilteringSideEffect { + data object NavigateToStartHome : FilteringSideEffect() + data class ShowToast(@StringRes val message: Int) : FilteringSideEffect() +} \ No newline at end of file diff --git a/feature/src/main/java/com/terning/feature/filtering/filtering/FilteringState.kt b/feature/src/main/java/com/terning/feature/filtering/filtering/FilteringState.kt new file mode 100644 index 000000000..b35e6fbd2 --- /dev/null +++ b/feature/src/main/java/com/terning/feature/filtering/filtering/FilteringState.kt @@ -0,0 +1,8 @@ +package com.terning.feature.filtering.filtering + +data class FilteringState( + val grade: Int = -1, + val workingPeriod: Int = -1, + val startYear: Int = -1, + val startMonth: Int = -1 +) \ No newline at end of file diff --git a/feature/src/main/java/com/terning/feature/onboarding/filtering/FilteringThreeScreen.kt b/feature/src/main/java/com/terning/feature/filtering/filtering/FilteringThreeScreen.kt similarity index 64% rename from feature/src/main/java/com/terning/feature/onboarding/filtering/FilteringThreeScreen.kt rename to feature/src/main/java/com/terning/feature/filtering/filtering/FilteringThreeScreen.kt index bf16f2a1e..51c1a204e 100644 --- a/feature/src/main/java/com/terning/feature/onboarding/filtering/FilteringThreeScreen.kt +++ b/feature/src/main/java/com/terning/feature/filtering/filtering/FilteringThreeScreen.kt @@ -1,4 +1,4 @@ -package com.terning.feature.onboarding.filtering +package com.terning.feature.filtering.filtering import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Spacer @@ -7,35 +7,68 @@ import androidx.compose.foundation.layout.padding import androidx.compose.material3.Scaffold import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.mutableIntStateOf 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.NavController import com.terning.core.designsystem.component.button.RectangleButton import com.terning.core.designsystem.component.datepicker.DatePickerUI import com.terning.core.designsystem.component.image.TerningImage import com.terning.core.designsystem.component.topappbar.BackButtonTopAppBar import com.terning.core.designsystem.theme.TerningTheme +import com.terning.core.extension.toast import com.terning.feature.R -import com.terning.feature.onboarding.starthome.navigation.navigateStartHome +import com.terning.feature.filtering.starthome.navigation.navigateStartHome import java.util.Calendar @Composable fun FilteringThreeScreen( + grade: Int, + workingPeriod: Int, navController: NavController, modifier: Modifier = Modifier, - filteringViewModel: FilteringViewModel = hiltViewModel(), + viewModel: FilteringViewModel = hiltViewModel(), ) { + val state by viewModel.state.collectAsStateWithLifecycle() + + val context = LocalContext.current + val lifecycleOwner = LocalLifecycleOwner.current + val currentYear = Calendar.getInstance().get(Calendar.YEAR) val currentMonth = Calendar.getInstance().get(Calendar.MONTH) - var chosenYear by remember { mutableStateOf(currentYear) } - var chosenMonth by remember { mutableStateOf(currentMonth) } + var chosenYear by remember { mutableIntStateOf(currentYear) } + var chosenMonth by remember { mutableIntStateOf(currentMonth) } + + LaunchedEffect(key1 = true) { + viewModel.fetchGrade(grade = grade) + viewModel.fetchWorkingPeriod(workingPeriod = workingPeriod) + } + + LaunchedEffect(key1 = chosenYear, key2 = chosenMonth) { + viewModel.fetchStartYear(chosenYear) + viewModel.fetchStartMonth(chosenMonth) + } + + LaunchedEffect(viewModel.sideEffects, lifecycleOwner) { + viewModel.sideEffects.flowWithLifecycle(lifecycle = lifecycleOwner.lifecycle) + .collect { sideEffect -> + when (sideEffect) { + is FilteringSideEffect.NavigateToStartHome -> navController.navigateStartHome() + is FilteringSideEffect.ShowToast -> context.toast(sideEffect.message) + } + } + } Scaffold( modifier = modifier, @@ -86,7 +119,7 @@ fun FilteringThreeScreen( style = TerningTheme.typography.button0, paddingVertical = 20.dp, text = R.string.filtering_button, - onButtonClick = { navController.navigateStartHome() }, + onButtonClick = { viewModel.postFilteringWithServer() }, modifier = modifier.padding(bottom = 12.dp), ) } diff --git a/feature/src/main/java/com/terning/feature/onboarding/filtering/FilteringTwoScreen.kt b/feature/src/main/java/com/terning/feature/filtering/filtering/FilteringTwoScreen.kt similarity index 82% rename from feature/src/main/java/com/terning/feature/onboarding/filtering/FilteringTwoScreen.kt rename to feature/src/main/java/com/terning/feature/filtering/filtering/FilteringTwoScreen.kt index 0f07a9d11..fd56e08cd 100644 --- a/feature/src/main/java/com/terning/feature/onboarding/filtering/FilteringTwoScreen.kt +++ b/feature/src/main/java/com/terning/feature/filtering/filtering/FilteringTwoScreen.kt @@ -1,4 +1,4 @@ -package com.terning.feature.onboarding.filtering +package com.terning.feature.filtering.filtering import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Spacer @@ -7,8 +7,11 @@ import androidx.compose.foundation.layout.padding import androidx.compose.material3.Scaffold import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp @@ -19,19 +22,22 @@ import com.terning.core.designsystem.component.image.TerningImage import com.terning.core.designsystem.component.topappbar.BackButtonTopAppBar import com.terning.core.designsystem.theme.TerningTheme import com.terning.feature.R -import com.terning.feature.onboarding.filtering.component.StatusTwoRadioGroup -import com.terning.feature.onboarding.filtering.navigation.navigateFilteringThree +import com.terning.feature.filtering.filtering.component.StatusTwoRadioGroup +import com.terning.feature.filtering.filtering.navigation.navigateFilteringThree @Composable fun FilteringTwoScreen( + grade : Int, navController: NavController, modifier: Modifier = Modifier, - filteringViewModel: FilteringViewModel = hiltViewModel(), - onButtonClick: () -> Unit = {}, + viewModel: FilteringViewModel = hiltViewModel(), + onButtonClick: (Int) -> Unit = {}, ) { val isButtonValid = remember { mutableStateOf(false) } + var workingPeriod by remember{ mutableIntStateOf(-1) } + Scaffold( modifier = modifier, topBar = { @@ -70,9 +76,10 @@ fun FilteringTwoScreen( ) ) StatusTwoRadioGroup( - onButtonClick = { - onButtonClick() + onButtonClick = {index -> + onButtonClick(index) isButtonValid.value = true + workingPeriod = index } ) Text( @@ -88,7 +95,7 @@ fun FilteringTwoScreen( style = TerningTheme.typography.button0, paddingVertical = 20.dp, text = R.string.filtering_button, - onButtonClick = { navController.navigateFilteringThree() }, + onButtonClick = { navController.navigateFilteringThree(grade, workingPeriod) }, modifier = modifier.padding(bottom = 12.dp), isEnabled = isButtonValid.value ) diff --git a/feature/src/main/java/com/terning/feature/filtering/filtering/FilteringViewModel.kt b/feature/src/main/java/com/terning/feature/filtering/filtering/FilteringViewModel.kt new file mode 100644 index 000000000..ebea0abe6 --- /dev/null +++ b/feature/src/main/java/com/terning/feature/filtering/filtering/FilteringViewModel.kt @@ -0,0 +1,67 @@ +package com.terning.feature.filtering.filtering + +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import com.terning.domain.entity.request.FilteringRequestModel +import com.terning.domain.repository.FilteringRepository +import com.terning.domain.repository.TokenRepository +import com.terning.feature.R +import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.flow.MutableSharedFlow +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.SharedFlow +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.asSharedFlow +import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.launch +import javax.inject.Inject + +@HiltViewModel +class FilteringViewModel @Inject constructor( + private val filteringRepository: FilteringRepository, + private val tokenRepository: TokenRepository +) : ViewModel() { + + private val _state = MutableStateFlow(FilteringState()) + val state: StateFlow get() = _state.asStateFlow() + + private val _sideEffects = MutableSharedFlow() + val sideEffects: SharedFlow get() = _sideEffects.asSharedFlow() + + fun fetchGrade(grade: Int) { + _state.value = _state.value.copy(grade = grade) + } + + fun fetchWorkingPeriod(workingPeriod: Int) { + _state.value = _state.value.copy(workingPeriod = workingPeriod) + } + + fun fetchStartYear(startYear: Int) { + _state.value = _state.value.copy(startYear = startYear) + } + + fun fetchStartMonth(startMonth: Int) { + _state.value = _state.value.copy(startMonth = startMonth) + } + + fun postFilteringWithServer() { + viewModelScope.launch { + filteringRepository.postFiltering( + tokenRepository.getUserId(), + state.value.run { + FilteringRequestModel( + grade = grade, + workingPeriod = workingPeriod, + startYear = startYear, + startMonth = startMonth + ) + } + ).onSuccess { + _sideEffects.emit(FilteringSideEffect.NavigateToStartHome) + }.onFailure { + _sideEffects.emit(FilteringSideEffect.ShowToast(R.string.server_failure)) + } + } + } + +} \ No newline at end of file diff --git a/feature/src/main/java/com/terning/feature/onboarding/filtering/component/StatusOneRadioGroup.kt b/feature/src/main/java/com/terning/feature/filtering/filtering/component/StatusOneRadioGroup.kt similarity index 97% rename from feature/src/main/java/com/terning/feature/onboarding/filtering/component/StatusOneRadioGroup.kt rename to feature/src/main/java/com/terning/feature/filtering/filtering/component/StatusOneRadioGroup.kt index def61d2b4..9efc5cbf1 100644 --- a/feature/src/main/java/com/terning/feature/onboarding/filtering/component/StatusOneRadioGroup.kt +++ b/feature/src/main/java/com/terning/feature/filtering/filtering/component/StatusOneRadioGroup.kt @@ -1,4 +1,4 @@ -package com.terning.feature.onboarding.filtering.component +package com.terning.feature.filtering.filtering.component import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.fillMaxWidth diff --git a/feature/src/main/java/com/terning/feature/onboarding/filtering/component/StatusTwoRadioGroup.kt b/feature/src/main/java/com/terning/feature/filtering/filtering/component/StatusTwoRadioGroup.kt similarity index 97% rename from feature/src/main/java/com/terning/feature/onboarding/filtering/component/StatusTwoRadioGroup.kt rename to feature/src/main/java/com/terning/feature/filtering/filtering/component/StatusTwoRadioGroup.kt index c7b273abc..c97d92321 100644 --- a/feature/src/main/java/com/terning/feature/onboarding/filtering/component/StatusTwoRadioGroup.kt +++ b/feature/src/main/java/com/terning/feature/filtering/filtering/component/StatusTwoRadioGroup.kt @@ -1,4 +1,4 @@ -package com.terning.feature.onboarding.filtering.component +package com.terning.feature.filtering.filtering.component import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.fillMaxWidth diff --git a/feature/src/main/java/com/terning/feature/onboarding/filtering/navigation/FilteringOneNavigation.kt b/feature/src/main/java/com/terning/feature/filtering/filtering/navigation/FilteringOneNavigation.kt similarity index 57% rename from feature/src/main/java/com/terning/feature/onboarding/filtering/navigation/FilteringOneNavigation.kt rename to feature/src/main/java/com/terning/feature/filtering/filtering/navigation/FilteringOneNavigation.kt index 55be952bb..d0bff745a 100644 --- a/feature/src/main/java/com/terning/feature/onboarding/filtering/navigation/FilteringOneNavigation.kt +++ b/feature/src/main/java/com/terning/feature/filtering/filtering/navigation/FilteringOneNavigation.kt @@ -1,17 +1,21 @@ -package com.terning.feature.onboarding.filtering.navigation +package com.terning.feature.filtering.filtering.navigation import androidx.navigation.NavController import androidx.navigation.NavGraphBuilder import androidx.navigation.NavHostController import androidx.navigation.NavOptions import androidx.navigation.compose.composable +import androidx.navigation.toRoute import com.terning.core.navigation.Route -import com.terning.feature.onboarding.filtering.FilteringOneScreen +import com.terning.feature.filtering.filtering.FilteringOneScreen import kotlinx.serialization.Serializable -fun NavController.navigateFilteringOne(navOptions: NavOptions? = null) { +fun NavController.navigateFilteringOne( + name: String, + navOptions: NavOptions? = null +) { navigate( - route = FilteringOne, + route = FilteringOne(name = name), navOptions = navOptions ) } @@ -20,11 +24,15 @@ fun NavGraphBuilder.filteringOneNavGraph( navHostController: NavHostController ) { composable { + val args = it.toRoute() FilteringOneScreen( + name = args.name, navController = navHostController ) } } @Serializable -data object FilteringOne : Route \ No newline at end of file +data class FilteringOne( + val name: String +) : Route \ No newline at end of file diff --git a/feature/src/main/java/com/terning/feature/onboarding/filtering/navigation/FilteringTwoNavigation.kt b/feature/src/main/java/com/terning/feature/filtering/filtering/navigation/FilteringTwoNavigation.kt similarity index 57% rename from feature/src/main/java/com/terning/feature/onboarding/filtering/navigation/FilteringTwoNavigation.kt rename to feature/src/main/java/com/terning/feature/filtering/filtering/navigation/FilteringTwoNavigation.kt index d7faf0d22..93f4d36d7 100644 --- a/feature/src/main/java/com/terning/feature/onboarding/filtering/navigation/FilteringTwoNavigation.kt +++ b/feature/src/main/java/com/terning/feature/filtering/filtering/navigation/FilteringTwoNavigation.kt @@ -1,17 +1,21 @@ -package com.terning.feature.onboarding.filtering.navigation +package com.terning.feature.filtering.filtering.navigation import androidx.navigation.NavController import androidx.navigation.NavGraphBuilder import androidx.navigation.NavHostController import androidx.navigation.NavOptions import androidx.navigation.compose.composable +import androidx.navigation.toRoute import com.terning.core.navigation.Route -import com.terning.feature.onboarding.filtering.FilteringTwoScreen +import com.terning.feature.filtering.filtering.FilteringTwoScreen import kotlinx.serialization.Serializable -fun NavController.navigateFilteringTwo(navOptions: NavOptions? = null) { +fun NavController.navigateFilteringTwo( + grade: Int, + navOptions: NavOptions? = null +) { navigate( - route = FilteringTwo, + route = FilteringTwo(grade = grade), navOptions = navOptions ) } @@ -20,11 +24,15 @@ fun NavGraphBuilder.filteringTwoNavGraph( navHostController: NavHostController ) { composable { + val args = it.toRoute() FilteringTwoScreen( + grade = args.grade, navController = navHostController ) } } @Serializable -data object FilteringTwo : Route \ No newline at end of file +data class FilteringTwo( + val grade: Int +) : Route \ No newline at end of file diff --git a/feature/src/main/java/com/terning/feature/onboarding/filtering/navigation/ThreeNavigation.kt b/feature/src/main/java/com/terning/feature/filtering/filtering/navigation/ThreeNavigation.kt similarity index 50% rename from feature/src/main/java/com/terning/feature/onboarding/filtering/navigation/ThreeNavigation.kt rename to feature/src/main/java/com/terning/feature/filtering/filtering/navigation/ThreeNavigation.kt index 8c98afbae..9aeae7c9a 100644 --- a/feature/src/main/java/com/terning/feature/onboarding/filtering/navigation/ThreeNavigation.kt +++ b/feature/src/main/java/com/terning/feature/filtering/filtering/navigation/ThreeNavigation.kt @@ -1,17 +1,21 @@ -package com.terning.feature.onboarding.filtering.navigation +package com.terning.feature.filtering.filtering.navigation import androidx.navigation.NavController import androidx.navigation.NavGraphBuilder import androidx.navigation.NavHostController import androidx.navigation.NavOptions import androidx.navigation.compose.composable +import androidx.navigation.toRoute import com.terning.core.navigation.Route -import com.terning.feature.onboarding.filtering.FilteringThreeScreen +import com.terning.feature.filtering.filtering.FilteringThreeScreen import kotlinx.serialization.Serializable -fun NavController.navigateFilteringThree(navOptions: NavOptions? = null) { +fun NavController.navigateFilteringThree( + grade : Int, + workingPeriod : Int, + navOptions: NavOptions? = null) { navigate( - route = FilteringThree, + route = FilteringThree(grade = grade, workingPeriod = workingPeriod), navOptions = navOptions ) } @@ -20,11 +24,17 @@ fun NavGraphBuilder.filteringThreeNavGraph( navHostController: NavHostController ) { composable { + val args = it.toRoute() FilteringThreeScreen( + grade = args.grade, + workingPeriod = args.workingPeriod, navController = navHostController ) } } @Serializable -data object FilteringThree : Route \ No newline at end of file +data class FilteringThree( + val grade : Int, + val workingPeriod: Int +) : Route \ No newline at end of file diff --git a/feature/src/main/java/com/terning/feature/onboarding/startfiltering/StartFilteringScreen.kt b/feature/src/main/java/com/terning/feature/filtering/startfiltering/StartFilteringScreen.kt similarity index 93% rename from feature/src/main/java/com/terning/feature/onboarding/startfiltering/StartFilteringScreen.kt rename to feature/src/main/java/com/terning/feature/filtering/startfiltering/StartFilteringScreen.kt index 6c083aa5f..74f2f8576 100644 --- a/feature/src/main/java/com/terning/feature/onboarding/startfiltering/StartFilteringScreen.kt +++ b/feature/src/main/java/com/terning/feature/filtering/startfiltering/StartFilteringScreen.kt @@ -1,4 +1,4 @@ -package com.terning.feature.onboarding.startfiltering +package com.terning.feature.filtering.startfiltering import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.fadeIn @@ -25,13 +25,14 @@ import androidx.navigation.NavController import com.terning.core.designsystem.component.button.RectangleButton import com.terning.core.designsystem.theme.TerningTheme import com.terning.feature.R -import com.terning.feature.onboarding.filtering.navigation.navigateFilteringOne +import com.terning.feature.filtering.filtering.navigation.navigateFilteringOne import kotlinx.coroutines.delay @Composable fun StartFilteringScreen( + name: String, modifier: Modifier = Modifier, - navController: NavController + navController: NavController, ) { var isVisible by remember { mutableStateOf(false) } @@ -73,7 +74,7 @@ fun StartFilteringScreen( style = TerningTheme.typography.button0, paddingVertical = 20.dp, text = R.string.start_filtering_button, - onButtonClick = { navController.navigateFilteringOne() }, + onButtonClick = { navController.navigateFilteringOne(name) }, ) } } diff --git a/feature/src/main/java/com/terning/feature/filtering/startfiltering/navigation/StartFilteringNavigation.kt b/feature/src/main/java/com/terning/feature/filtering/startfiltering/navigation/StartFilteringNavigation.kt new file mode 100644 index 000000000..7cc79470b --- /dev/null +++ b/feature/src/main/java/com/terning/feature/filtering/startfiltering/navigation/StartFilteringNavigation.kt @@ -0,0 +1,38 @@ +package com.terning.feature.filtering.startfiltering.navigation + +import androidx.navigation.NavController +import androidx.navigation.NavGraphBuilder +import androidx.navigation.NavHostController +import androidx.navigation.NavOptions +import androidx.navigation.compose.composable +import androidx.navigation.toRoute +import com.terning.core.navigation.Route +import com.terning.feature.filtering.startfiltering.StartFilteringScreen +import kotlinx.serialization.Serializable + +fun NavController.navigateStartFiltering( + name: String, + navOptions: NavOptions? = null +) { + navigate( + route = StartFiltering(name = name), + navOptions = navOptions + ) +} + +fun NavGraphBuilder.startFilteringNavGraph( + navHostController: NavHostController +) { + composable { + val args = it.toRoute() + StartFilteringScreen( + name = args.name, + navController = navHostController, + ) + } +} + +@Serializable +data class StartFiltering( + val name: String +) : Route \ No newline at end of file diff --git a/feature/src/main/java/com/terning/feature/onboarding/starthome/StartHomeScreen.kt b/feature/src/main/java/com/terning/feature/filtering/starthome/StartHomeScreen.kt similarity index 98% rename from feature/src/main/java/com/terning/feature/onboarding/starthome/StartHomeScreen.kt rename to feature/src/main/java/com/terning/feature/filtering/starthome/StartHomeScreen.kt index 86bd93a73..687bca841 100644 --- a/feature/src/main/java/com/terning/feature/onboarding/starthome/StartHomeScreen.kt +++ b/feature/src/main/java/com/terning/feature/filtering/starthome/StartHomeScreen.kt @@ -1,4 +1,4 @@ -package com.terning.feature.onboarding.starthome +package com.terning.feature.filtering.starthome import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.fadeIn diff --git a/feature/src/main/java/com/terning/feature/onboarding/starthome/navigation/StartHomeNavigation.kt b/feature/src/main/java/com/terning/feature/filtering/starthome/navigation/StartHomeNavigation.kt similarity index 84% rename from feature/src/main/java/com/terning/feature/onboarding/starthome/navigation/StartHomeNavigation.kt rename to feature/src/main/java/com/terning/feature/filtering/starthome/navigation/StartHomeNavigation.kt index 7cd5a3d3a..424406917 100644 --- a/feature/src/main/java/com/terning/feature/onboarding/starthome/navigation/StartHomeNavigation.kt +++ b/feature/src/main/java/com/terning/feature/filtering/starthome/navigation/StartHomeNavigation.kt @@ -1,4 +1,4 @@ -package com.terning.feature.onboarding.starthome.navigation +package com.terning.feature.filtering.starthome.navigation import androidx.navigation.NavController import androidx.navigation.NavGraphBuilder @@ -6,7 +6,7 @@ import androidx.navigation.NavHostController import androidx.navigation.NavOptions import androidx.navigation.compose.composable import com.terning.core.navigation.Route -import com.terning.feature.onboarding.starthome.StartHomeScreen +import com.terning.feature.filtering.starthome.StartHomeScreen import kotlinx.serialization.Serializable fun NavController.navigateStartHome(navOptions: NavOptions? = null) { 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 736728c99..f460a4f28 100644 --- a/feature/src/main/java/com/terning/feature/main/MainNavigator.kt +++ b/feature/src/main/java/com/terning/feature/main/MainNavigator.kt @@ -12,7 +12,7 @@ import androidx.navigation.navOptions import com.terning.feature.calendar.calendar.navigation.navigateCalendar import com.terning.feature.home.home.navigation.navigateHome import com.terning.feature.mypage.navigation.navigateMyPage -import com.terning.feature.onboarding.signin.navigation.SignIn +import com.terning.feature.onboarding.signup.navigation.SignUp import com.terning.feature.search.search.navigation.navigateSearch class MainNavigator( @@ -22,7 +22,7 @@ class MainNavigator( @Composable get() = navController .currentBackStackEntryAsState().value?.destination - val startDestination = SignIn + val startDestination = SignUp val currentTab: MainTab? @Composable get() = MainTab.find { tab -> diff --git a/feature/src/main/java/com/terning/feature/main/MainScreen.kt b/feature/src/main/java/com/terning/feature/main/MainScreen.kt index b5f8e5d1c..8ef53be83 100644 --- a/feature/src/main/java/com/terning/feature/main/MainScreen.kt +++ b/feature/src/main/java/com/terning/feature/main/MainScreen.kt @@ -25,13 +25,13 @@ import com.terning.feature.home.changefilter.navigation.changeFilterNavGraph import com.terning.feature.home.home.navigation.homeNavGraph import com.terning.feature.intern.navigation.internNavGraph import com.terning.feature.mypage.navigation.myPageNavGraph -import com.terning.feature.onboarding.filtering.navigation.filteringOneNavGraph -import com.terning.feature.onboarding.filtering.navigation.filteringThreeNavGraph -import com.terning.feature.onboarding.filtering.navigation.filteringTwoNavGraph +import com.terning.feature.filtering.filtering.navigation.filteringOneNavGraph +import com.terning.feature.filtering.filtering.navigation.filteringThreeNavGraph +import com.terning.feature.filtering.filtering.navigation.filteringTwoNavGraph import com.terning.feature.onboarding.signin.navigation.signInNavGraph import com.terning.feature.onboarding.signup.navigation.signUpNavGraph -import com.terning.feature.onboarding.startfiltering.navigation.startFilteringNavGraph -import com.terning.feature.onboarding.starthome.navigation.startHomeNavGraph +import com.terning.feature.filtering.startfiltering.navigation.startFilteringNavGraph +import com.terning.feature.filtering.starthome.navigation.startHomeNavGraph import com.terning.feature.search.search.navigation.searchNavGraph import com.terning.feature.search.searchprocess.navigation.searchProcessNavGraph diff --git a/feature/src/main/java/com/terning/feature/onboarding/filtering/FilteringViewModel.kt b/feature/src/main/java/com/terning/feature/onboarding/filtering/FilteringViewModel.kt deleted file mode 100644 index b05c6266f..000000000 --- a/feature/src/main/java/com/terning/feature/onboarding/filtering/FilteringViewModel.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.terning.feature.onboarding.filtering - -import androidx.lifecycle.ViewModel -import dagger.hilt.android.lifecycle.HiltViewModel -import javax.inject.Inject - -@HiltViewModel -class FilteringViewModel @Inject constructor() : ViewModel() { - - val name = "남지우" - -} \ No newline at end of file diff --git a/feature/src/main/java/com/terning/feature/onboarding/signup/SignUpRoute.kt b/feature/src/main/java/com/terning/feature/onboarding/signup/SignUpRoute.kt index 61ce9b6d7..f98115bc3 100644 --- a/feature/src/main/java/com/terning/feature/onboarding/signup/SignUpRoute.kt +++ b/feature/src/main/java/com/terning/feature/onboarding/signup/SignUpRoute.kt @@ -30,7 +30,8 @@ import com.terning.core.extension.addFocusCleaner import com.terning.core.extension.noRippleClickable import com.terning.core.extension.toast import com.terning.feature.R -import com.terning.feature.onboarding.filtering.navigation.navigateFilteringOne +import com.terning.feature.filtering.filtering.navigation.navigateFilteringOne +import com.terning.feature.filtering.startfiltering.navigation.navigateStartFiltering import com.terning.feature.onboarding.signup.component.SignUpProfile @Composable @@ -48,8 +49,8 @@ fun SignUpRoute( .collect { sideEffect -> when (sideEffect) { is SignUpSideEffect.ShowToast -> context.toast(sideEffect.message) - is SignUpSideEffect.NavigateToFiltering -> { - navController.navigateFilteringOne() + is SignUpSideEffect.NavigateToStartFiltering -> { + navController.navigateStartFiltering(signUpState.name) } } } diff --git a/feature/src/main/java/com/terning/feature/onboarding/signup/SignUpSideEffect.kt b/feature/src/main/java/com/terning/feature/onboarding/signup/SignUpSideEffect.kt index c618f52c2..3120e6032 100644 --- a/feature/src/main/java/com/terning/feature/onboarding/signup/SignUpSideEffect.kt +++ b/feature/src/main/java/com/terning/feature/onboarding/signup/SignUpSideEffect.kt @@ -3,6 +3,6 @@ package com.terning.feature.onboarding.signup import androidx.annotation.StringRes sealed class SignUpSideEffect { - data object NavigateToFiltering : SignUpSideEffect() + data object NavigateToStartFiltering : SignUpSideEffect() data class ShowToast(@StringRes val message: Int) : SignUpSideEffect() } \ No newline at end of file diff --git a/feature/src/main/java/com/terning/feature/onboarding/signup/SignUpViewModel.kt b/feature/src/main/java/com/terning/feature/onboarding/signup/SignUpViewModel.kt index 1ea721ad1..360cb5bf5 100644 --- a/feature/src/main/java/com/terning/feature/onboarding/signup/SignUpViewModel.kt +++ b/feature/src/main/java/com/terning/feature/onboarding/signup/SignUpViewModel.kt @@ -89,7 +89,7 @@ class SignUpViewModel @Inject constructor( tokenRepository.setTokens(response.accessToken, response.refreshToken) tokenRepository.setUserId(response.userId) - _sideEffects.emit(SignUpSideEffect.NavigateToFiltering) + _sideEffects.emit(SignUpSideEffect.NavigateToStartFiltering) }.onFailure { _sideEffects.emit(SignUpSideEffect.ShowToast(R.string.server_failure)) } diff --git a/feature/src/main/java/com/terning/feature/onboarding/startfiltering/navigation/StartFilteringNavigation.kt b/feature/src/main/java/com/terning/feature/onboarding/startfiltering/navigation/StartFilteringNavigation.kt deleted file mode 100644 index 2bcf37a82..000000000 --- a/feature/src/main/java/com/terning/feature/onboarding/startfiltering/navigation/StartFilteringNavigation.kt +++ /dev/null @@ -1,28 +0,0 @@ -package com.terning.feature.onboarding.startfiltering.navigation - -import androidx.navigation.NavController -import androidx.navigation.NavGraphBuilder -import androidx.navigation.NavHostController -import androidx.navigation.NavOptions -import androidx.navigation.compose.composable -import com.terning.core.navigation.Route -import com.terning.feature.onboarding.startfiltering.StartFilteringScreen -import kotlinx.serialization.Serializable - -fun NavController.navigateStartFiltering(navOptions: NavOptions? = null) { - navigate( - route = StartFiltering, - navOptions = navOptions - ) -} - -fun NavGraphBuilder.startFilteringNavGraph( - navHostController: NavHostController -) { - composable { - StartFilteringScreen(navController = navHostController) - } -} - -@Serializable -data object StartFiltering : Route \ No newline at end of file