Skip to content

Commit

Permalink
[FEATURE] #106 : Profile 화면에 출석 정보 받아오도록 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
tgyuuAn committed Jan 19, 2024
1 parent 58679cd commit 7a56ebc
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 12 deletions.
15 changes: 14 additions & 1 deletion .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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<Throwable> = MutableSharedFlow()
Expand All @@ -38,8 +41,9 @@ class ProfileViewModel @Inject constructor(
private val _todayEvents = MutableStateFlow<EventsState>(EventsState.Loading)
val todayEvents: StateFlow<EventsState> = _todayEvents.asStateFlow()

private val _recentEvents = MutableStateFlow<EventsState>(EventsState.Loading)
val recentEvents: StateFlow<EventsState> = _recentEvents.asStateFlow()
private val _recentEvents =
MutableStateFlow<EventAttendanceStatusState>(EventAttendanceStatusState.Loading)
val recentEvents: StateFlow<EventAttendanceStatusState> = _recentEvents.asStateFlow()

private val _userRespondedSurveys = MutableStateFlow<SurveysState>(SurveysState.Loading)
val userRespondedSurveys: StateFlow<SurveysState> = _userRespondedSurveys.asStateFlow()
Expand Down Expand Up @@ -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<Event>,
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()
Expand All @@ -121,6 +150,11 @@ class ProfileViewModel @Inject constructor(
data class Success(val events: List<Event>) : EventsState()
}

sealed class EventAttendanceStatusState {
data object Loading : EventAttendanceStatusState()
data class Success(val events: List<EventAttendanceStatus>) : EventAttendanceStatusState()
}

sealed class SurveysState {
data object Loading : SurveysState()
data class Success(val surveys: List<Survey>) : SurveysState()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
)
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -151,7 +151,7 @@ private fun ProfileAttendanceCard(

@Composable
private fun MyAttendanceStatus(
recentEventsState: ProfileViewModel.EventsState,
recentEventsState: ProfileViewModel.EventAttendanceStatusState,
modifier: Modifier = Modifier,
) {
Column(modifier = modifier) {
Expand All @@ -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
Expand Down

0 comments on commit 7a56ebc

Please sign in to comment.