From 7a56ebcde603b75b778fd216c9c469d09bf41445 Mon Sep 17 00:00:00 2001 From: tgyuu-An Date: Sat, 20 Jan 2024 04:30:40 +0900 Subject: [PATCH] =?UTF-8?q?[FEATURE]=20#106=20:=20Profile=20=ED=99=94?= =?UTF-8?q?=EB=A9=B4=EC=97=90=20=EC=B6=9C=EC=84=9D=20=EC=A0=95=EB=B3=B4=20?= =?UTF-8?q?=EB=B0=9B=EC=95=84=EC=98=A4=EB=8F=84=EB=A1=9D=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/deploymentTargetDropDown.xml | 15 ++++++- .../wap/wapp/feature/profile/ProfileScreen.kt | 2 +- .../wapp/feature/profile/ProfileViewModel.kt | 42 +++++++++++++++++-- .../profile/component/WappAttendanceRow.kt | 4 +- .../profile/model/EventAttendanceStatus.kt | 11 +++++ .../profilesetting/component/UserProfile.kt | 8 ++-- 6 files changed, 70 insertions(+), 12 deletions(-) create mode 100644 feature/profile/src/main/java/com/wap/wapp/feature/profile/model/EventAttendanceStatus.kt diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml index 0c0c33838..24c8172a3 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 457391b4b..a4ea95480 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 063bdb87f..4bf54a4c7 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 f1b59399b..c196fd45d 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 000000000..f624fba65 --- /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 98df4c93d..faee0a131 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