Skip to content

Commit

Permalink
feat: 가족 통계 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
CChuYong committed Jan 30, 2024
1 parent 65f8bdc commit f1a3a8d
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@ interface RestAPI {
interface FamilyApi {
@POST("v1/families")
suspend fun createFamily(): ApiResponse<Family>

@GET("v1/families/{familyId}/summary")
suspend fun getFamilySummary(
@Path("familyId") familyId: String,
): ApiResponse<FamilySummary>
}

/**
Expand Down Expand Up @@ -217,6 +212,11 @@ interface RestAPI {
@Query("yearMonth") yearMonth: String,
): ApiResponse<CalendarBanner>

@GET("v1/calendar/summary")
suspend fun getFamilySummary(
@Query("yearMonth") yearMonth: String,
): ApiResponse<FamilySummary>

@GET("v1/posts/{postId}/comments")
suspend fun getPostComments(
@Path("postId") postId: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,5 @@ import kotlinx.parcelize.Parcelize

@Parcelize
data class FamilySummary(
val totalParticipateCnt: Int,
val totalImageCnt: Int,
val myImageCnt: Int,
) : Parcelable, BaseModel()
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -67,6 +69,7 @@ fun MainCalendarPage(
onDispose: () -> Unit = {},
onTapDay: (LocalDate) -> Unit = {},
calendarMonthViewModel: CalendarMonthViewModel = hiltViewModel(),
calendarMonthStatViewModel: GetFamilySummaryViewModel = hiltViewModel(),
monthlyStatisticsViewModel: MonthlyStatisticsViewModel = hiltViewModel(),
) {
val (width, height) = getScreenSize()
Expand All @@ -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()) {
Expand All @@ -107,6 +115,7 @@ fun MainCalendarPage(
MainCalendarYearMonthBar(
yearMonthState = currentCalendarState.monthState.currentMonth,
statisticsState = monthlyStatisticsViewModel.uiState,
summaryState = calendarMonthStatViewModel.uiState,
)
if (statState.isReady()) {
Box(
Expand Down Expand Up @@ -238,8 +247,10 @@ private fun resolveBannerImageByName(bannerName: String): Int {
fun MainCalendarYearMonthBar(
yearMonthState: YearMonth,
statisticsState: StateFlow<APIResponse<CalendarBanner>>,
summaryState: StateFlow<APIResponse<FamilySummary>>,
) {
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 {
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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<APIResponse<FamilySummary>>() {
override fun initState(): APIResponse<FamilySummary> {
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())
}
}

}

0 comments on commit f1a3a8d

Please sign in to comment.