diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml index 0c0c3383..24c8172a 100644 --- a/.idea/deploymentTargetDropDown.xml +++ b/.idea/deploymentTargetDropDown.xml @@ -3,7 +3,20 @@ - + + + + + + + + + + + + + + diff --git a/feature/profile/src/main/java/com/wap/wapp/feature/profile/ProfileScreen.kt b/feature/profile/src/main/java/com/wap/wapp/feature/profile/ProfileScreen.kt index 457391b4..a4ea9548 100644 --- a/feature/profile/src/main/java/com/wap/wapp/feature/profile/ProfileScreen.kt +++ b/feature/profile/src/main/java/com/wap/wapp/feature/profile/ProfileScreen.kt @@ -75,7 +75,7 @@ internal fun ProfileScreen( userRoleState: UserRoleState, userProfile: UserProfile, todayEventsState: ProfileViewModel.EventsState, - recentEventsState: ProfileViewModel.EventsState, + recentEventsState: ProfileViewModel.EventAttendanceStatusState, userRespondedSurveysState: ProfileViewModel.SurveysState, snackBarHostState: SnackbarHostState, navigateToProfileSetting: (String) -> Unit, diff --git a/feature/profile/src/main/java/com/wap/wapp/feature/profile/ProfileViewModel.kt b/feature/profile/src/main/java/com/wap/wapp/feature/profile/ProfileViewModel.kt index 063bdb87..4bf54a4c 100644 --- a/feature/profile/src/main/java/com/wap/wapp/feature/profile/ProfileViewModel.kt +++ b/feature/profile/src/main/java/com/wap/wapp/feature/profile/ProfileViewModel.kt @@ -3,6 +3,7 @@ package com.wap.wapp.feature.profile import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.wap.wapp.core.commmon.util.DateUtil +import com.wap.wapp.core.domain.usecase.attendancestatus.GetEventListAttendanceStatusUseCase import com.wap.wapp.core.domain.usecase.event.GetDateEventListUseCase import com.wap.wapp.core.domain.usecase.event.GetRecentEventListUseCase import com.wap.wapp.core.domain.usecase.survey.GetUserRespondedSurveyListUseCase @@ -12,6 +13,7 @@ import com.wap.wapp.core.model.event.Event import com.wap.wapp.core.model.survey.Survey import com.wap.wapp.core.model.user.UserProfile import com.wap.wapp.core.model.user.UserRole +import com.wap.wapp.feature.profile.model.EventAttendanceStatus import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.async import kotlinx.coroutines.flow.MutableSharedFlow @@ -30,6 +32,7 @@ class ProfileViewModel @Inject constructor( private val getUserProfileUseCase: GetUserProfileUseCase, private val getRecentEventListUseCase: GetRecentEventListUseCase, private val getDateEventListUseCase: GetDateEventListUseCase, + private val getEventListAttendanceStatusUseCase: GetEventListAttendanceStatusUseCase, private val getUserRespondedSurveyListUseCase: GetUserRespondedSurveyListUseCase, ) : ViewModel() { private val _errorFlow: MutableSharedFlow = MutableSharedFlow() @@ -38,8 +41,9 @@ class ProfileViewModel @Inject constructor( private val _todayEvents = MutableStateFlow(EventsState.Loading) val todayEvents: StateFlow = _todayEvents.asStateFlow() - private val _recentEvents = MutableStateFlow(EventsState.Loading) - val recentEvents: StateFlow = _recentEvents.asStateFlow() + private val _recentEvents = + MutableStateFlow(EventAttendanceStatusState.Loading) + val recentEvents: StateFlow = _recentEvents.asStateFlow() private val _userRespondedSurveys = MutableStateFlow(SurveysState.Loading) val userRespondedSurveys: StateFlow = _userRespondedSurveys.asStateFlow() @@ -101,11 +105,36 @@ class ProfileViewModel @Inject constructor( createRegistrationDate(registeredYear.toInt(), registeredSemester) getRecentEventListUseCase(registrationDate) - .onSuccess { - _recentEvents.value = EventsState.Success(it) + .onSuccess { eventList -> + getEventListAttendanceStatus( + eventList = eventList, + userId = _userProfile.value.userId, + ) }.onFailure { _errorFlow.emit(it) } } + // 최근 일정들 중, 유저가 출석을 했는 지 안했는 지를 판별합니다. + private suspend fun getEventListAttendanceStatus( + eventList: List, + userId: String, + ) = getEventListAttendanceStatusUseCase( + eventIdList = eventList.map { it.eventId }, + userId = userId, + ).onSuccess { attendanceStatusList -> + val eventAttendanceStatusList = eventList.zip(attendanceStatusList) + .map { (event, attendanceStatus) -> + EventAttendanceStatus( + eventId = event.eventId, + title = event.title, + content = event.content, + startDateTime = event.startDateTime, + isAttendance = attendanceStatus.isAttendance(), + ) + } + _recentEvents.value = + EventAttendanceStatusState.Success(eventAttendanceStatusList) + }.onFailure { _errorFlow.emit(it) } + private fun createRegistrationDate(year: Int, semester: String): LocalDate { // 학기에 따른 기준 날짜 설정 (예: 1학기는 3월 1일, 2학기는 9월 1일) val semesterNumber = semester.removeSuffix("학기").toInt() @@ -121,6 +150,11 @@ class ProfileViewModel @Inject constructor( data class Success(val events: List) : EventsState() } + sealed class EventAttendanceStatusState { + data object Loading : EventAttendanceStatusState() + data class Success(val events: List) : EventAttendanceStatusState() + } + sealed class SurveysState { data object Loading : SurveysState() data class Success(val surveys: List) : SurveysState() diff --git a/feature/profile/src/main/java/com/wap/wapp/feature/profile/component/WappAttendanceRow.kt b/feature/profile/src/main/java/com/wap/wapp/feature/profile/component/WappAttendanceRow.kt index f1b59399..c196fd45 100644 --- a/feature/profile/src/main/java/com/wap/wapp/feature/profile/component/WappAttendanceRow.kt +++ b/feature/profile/src/main/java/com/wap/wapp/feature/profile/component/WappAttendanceRow.kt @@ -14,11 +14,11 @@ import androidx.compose.ui.unit.dp import com.wap.designsystem.WappTheme import com.wap.wapp.core.commmon.util.DateUtil import com.wap.wapp.core.designresource.R -import com.wap.wapp.core.model.event.Event +import com.wap.wapp.feature.profile.model.EventAttendanceStatus @Composable internal fun WappAttendacneRow( - event: Event, + event: EventAttendanceStatus, isAttendance: Boolean, onClick: () -> Unit = {}, modifier: Modifier = Modifier, diff --git a/feature/profile/src/main/java/com/wap/wapp/feature/profile/model/EventAttendanceStatus.kt b/feature/profile/src/main/java/com/wap/wapp/feature/profile/model/EventAttendanceStatus.kt new file mode 100644 index 00000000..f624fba6 --- /dev/null +++ b/feature/profile/src/main/java/com/wap/wapp/feature/profile/model/EventAttendanceStatus.kt @@ -0,0 +1,11 @@ +package com.wap.wapp.feature.profile.model + +import java.time.LocalDateTime + +data class EventAttendanceStatus( + val content: String, + val eventId: String, + val title: String, + val startDateTime: LocalDateTime, + val isAttendance: Boolean = false, +) diff --git a/feature/profile/src/main/java/com/wap/wapp/feature/profile/profilesetting/component/UserProfile.kt b/feature/profile/src/main/java/com/wap/wapp/feature/profile/profilesetting/component/UserProfile.kt index 98df4c93..faee0a13 100644 --- a/feature/profile/src/main/java/com/wap/wapp/feature/profile/profilesetting/component/UserProfile.kt +++ b/feature/profile/src/main/java/com/wap/wapp/feature/profile/profilesetting/component/UserProfile.kt @@ -42,7 +42,7 @@ import com.wap.wapp.feature.profile.component.WappSurveyHistoryRow @Composable internal fun UserProfile( todayEventsState: ProfileViewModel.EventsState, - recentEventsState: ProfileViewModel.EventsState, + recentEventsState: ProfileViewModel.EventAttendanceStatusState, userRespondedSurveysState: ProfileViewModel.SurveysState, attendanceCardBoardColor: Color, navigateToAttendance: () -> Unit, @@ -151,7 +151,7 @@ private fun ProfileAttendanceCard( @Composable private fun MyAttendanceStatus( - recentEventsState: ProfileViewModel.EventsState, + recentEventsState: ProfileViewModel.EventAttendanceStatusState, modifier: Modifier = Modifier, ) { Column(modifier = modifier) { @@ -169,13 +169,13 @@ private fun MyAttendanceStatus( .padding(top = 10.dp), ) { when (recentEventsState) { - is ProfileViewModel.EventsState.Loading -> CircleLoader( + is ProfileViewModel.EventAttendanceStatusState.Loading -> CircleLoader( modifier = Modifier .padding(vertical = 10.dp) .height(130.dp), ) - is ProfileViewModel.EventsState.Success -> { + is ProfileViewModel.EventAttendanceStatusState.Success -> { if (recentEventsState.events.isEmpty()) { NothingToShow(title = R.string.no_events_recently) return@WappCard