diff --git a/app/src/main/java/com/no5ing/bbibbi/data/datasource/network/RestAPI.kt b/app/src/main/java/com/no5ing/bbibbi/data/datasource/network/RestAPI.kt index d0475d7..72a22d9 100644 --- a/app/src/main/java/com/no5ing/bbibbi/data/datasource/network/RestAPI.kt +++ b/app/src/main/java/com/no5ing/bbibbi/data/datasource/network/RestAPI.kt @@ -53,11 +53,6 @@ interface RestAPI { interface FamilyApi { @POST("v1/families") suspend fun createFamily(): ApiResponse - - @GET("v1/families/{familyId}/summary") - suspend fun getFamilySummary( - @Path("familyId") familyId: String, - ): ApiResponse } /** @@ -217,6 +212,11 @@ interface RestAPI { @Query("yearMonth") yearMonth: String, ): ApiResponse + @GET("v1/calendar/summary") + suspend fun getFamilySummary( + @Query("yearMonth") yearMonth: String, + ): ApiResponse + @GET("v1/posts/{postId}/comments") suspend fun getPostComments( @Path("postId") postId: String, diff --git a/app/src/main/java/com/no5ing/bbibbi/data/model/family/FamilySummary.kt b/app/src/main/java/com/no5ing/bbibbi/data/model/family/FamilySummary.kt index da3b265..be6f788 100644 --- a/app/src/main/java/com/no5ing/bbibbi/data/model/family/FamilySummary.kt +++ b/app/src/main/java/com/no5ing/bbibbi/data/model/family/FamilySummary.kt @@ -6,7 +6,5 @@ import kotlinx.parcelize.Parcelize @Parcelize data class FamilySummary( - val totalParticipateCnt: Int, val totalImageCnt: Int, - val myImageCnt: Int, ) : Parcelable, BaseModel() diff --git a/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view/main/calendar/MainCalendarPage.kt b/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view/main/calendar/MainCalendarPage.kt index 3390d6f..a3d65cf 100644 --- a/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view/main/calendar/MainCalendarPage.kt +++ b/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view/main/calendar/MainCalendarPage.kt @@ -35,11 +35,13 @@ import androidx.compose.ui.unit.sp import androidx.hilt.navigation.compose.hiltViewModel import com.no5ing.bbibbi.R import com.no5ing.bbibbi.data.model.APIResponse +import com.no5ing.bbibbi.data.model.family.FamilySummary import com.no5ing.bbibbi.data.model.post.CalendarBanner import com.no5ing.bbibbi.data.repository.Arguments import com.no5ing.bbibbi.presentation.component.BBiBBiSurface import com.no5ing.bbibbi.presentation.component.DisposableTopBar import com.no5ing.bbibbi.presentation.feature.view_model.post.CalendarMonthViewModel +import com.no5ing.bbibbi.presentation.feature.view_model.post.GetFamilySummaryViewModel import com.no5ing.bbibbi.presentation.feature.view_model.post.MonthlyStatisticsViewModel import com.no5ing.bbibbi.presentation.theme.bbibbiScheme import com.no5ing.bbibbi.presentation.theme.bbibbiTypo @@ -67,6 +69,7 @@ fun MainCalendarPage( onDispose: () -> Unit = {}, onTapDay: (LocalDate) -> Unit = {}, calendarMonthViewModel: CalendarMonthViewModel = hiltViewModel(), + calendarMonthStatViewModel: GetFamilySummaryViewModel = hiltViewModel(), monthlyStatisticsViewModel: MonthlyStatisticsViewModel = hiltViewModel(), ) { val (width, height) = getScreenSize() @@ -93,6 +96,11 @@ fun MainCalendarPage( arguments = mapOf("yearMonth" to currentCalendarState.monthState.currentMonth.toString()), ) ) + calendarMonthStatViewModel.invoke( + Arguments( + arguments = mapOf("yearMonth" to currentCalendarState.monthState.currentMonth.toString()), + ) + ) } BBiBBiSurface(modifier = Modifier.fillMaxSize()) { @@ -107,6 +115,7 @@ fun MainCalendarPage( MainCalendarYearMonthBar( yearMonthState = currentCalendarState.monthState.currentMonth, statisticsState = monthlyStatisticsViewModel.uiState, + summaryState = calendarMonthStatViewModel.uiState, ) if (statState.isReady()) { Box( @@ -238,8 +247,10 @@ private fun resolveBannerImageByName(bannerName: String): Int { fun MainCalendarYearMonthBar( yearMonthState: YearMonth, statisticsState: StateFlow>, + summaryState: StateFlow>, ) { val statistics by statisticsState.collectAsState() + val summary by summaryState.collectAsState() val balloonColor = MaterialTheme.bbibbiScheme.button val balloonText = stringResource(id = R.string.calendar_everyday_info) val builder = rememberBalloonBuilder { @@ -305,7 +316,7 @@ fun MainCalendarYearMonthBar( Text( text = stringResource( id = R.string.calendar_history_cnt, - statistics.data.allFamilyMembersUploadedDays + if(summary.isReady()) summary.data.totalImageCnt else 0 ), color = MaterialTheme.bbibbiScheme.textPrimary, style = MaterialTheme.bbibbiTypo.bodyOneRegular, diff --git a/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view_model/post/GetFamilySummaryViewModel.kt b/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view_model/post/GetFamilySummaryViewModel.kt new file mode 100644 index 0000000..6a6feaf --- /dev/null +++ b/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view_model/post/GetFamilySummaryViewModel.kt @@ -0,0 +1,29 @@ +package com.no5ing.bbibbi.presentation.feature.view_model.post + +import com.no5ing.bbibbi.data.datasource.network.RestAPI +import com.no5ing.bbibbi.data.model.APIResponse +import com.no5ing.bbibbi.data.model.APIResponse.Companion.wrapToAPIResponse +import com.no5ing.bbibbi.data.model.family.FamilySummary +import com.no5ing.bbibbi.data.repository.Arguments +import com.no5ing.bbibbi.presentation.feature.view_model.BaseViewModel +import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.Dispatchers +import javax.inject.Inject + +@HiltViewModel +class GetFamilySummaryViewModel @Inject constructor( + private val restAPI: RestAPI, +) : BaseViewModel>() { + override fun initState(): APIResponse { + return APIResponse.idle() + } + + override fun invoke(arguments: Arguments) { + val yearMonth = arguments.get("yearMonth") ?: throw RuntimeException() + withMutexScope(Dispatchers.IO) { + val result = restAPI.getPostApi().getFamilySummary(yearMonth) + setState(result.wrapToAPIResponse()) + } + } + +} \ No newline at end of file