Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TNT-180] 트레이니 홈 화면 주간 기록 출력 API 연동 #98

Merged
merged 3 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package co.kr.data.network.model.trainee

import co.kr.tnt.domain.model.trainee.TraineeDailyRecordStatus
import co.kr.tnt.domain.utils.DateFormatter
import kotlinx.serialization.Serializable

@Serializable
data class WeeklyRecordedDatesResponse(
val ptLessonDates: List<String>,
)

fun WeeklyRecordedDatesResponse.toDomain(dateFormatter: DateFormatter) =
TraineeDailyRecordStatus(
ptLessonDates.map { date ->
dateFormatter.parse(date)
},
)
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import co.kr.data.network.model.LoginResponse
import co.kr.data.network.model.SignUpResponse
import co.kr.data.network.model.UserResponse
import co.kr.data.network.model.VerifyCodeResponse
import co.kr.data.network.model.trainee.WeeklyRecordedDatesResponse
import co.kr.data.network.model.trainer.ActiveTraineesResponse
import co.kr.data.network.model.trainer.DailyPtSessionsResponse
import co.kr.data.network.model.trainer.MonthlyPtSessionCountsResponse
Expand Down Expand Up @@ -104,4 +105,10 @@ interface ApiService {
@Part dietImage: MultipartBody.Part?,
@Part("request") request: RequestBody,
)

@GET("/trainees/lessons/calendar")
suspend fun getWeeklyRecordedDates(
@Query("startDate") startDate: String,
@Query("endDate") endDate: String,
): WeeklyRecordedDatesResponse
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,11 @@ class TraineeRemoteDataSource @Inject constructor(
) = networkHandler {
apiService.postMealRecord(dietImage, request)
}

suspend fun getWeeklyRecordedDates(
startDate: String,
endDate: String,
) = networkHandler {
apiService.getWeeklyRecordedDates(startDate, endDate)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ package co.kr.data.repository
import co.kr.data.network.model.toDomain
import co.kr.data.network.model.trainee.DailyRecordsResponse
import co.kr.data.network.model.trainee.MealRecordRequest
import co.kr.data.network.model.trainee.MonthlyRecordedDatesResponse
import co.kr.data.network.model.trainee.PtSessionResponse
import co.kr.data.network.model.trainee.RecordResponse
import co.kr.data.network.model.trainee.RecordedDateResponse
import co.kr.data.network.model.trainee.toDomain
import co.kr.data.network.source.TraineeRemoteDataSource
import co.kr.data.network.source.UserRemoteDataSource
Expand All @@ -25,7 +23,6 @@ import okhttp3.RequestBody.Companion.toRequestBody
import java.io.File
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.YearMonth
import javax.inject.Inject
import javax.inject.Singleton

Expand All @@ -42,21 +39,13 @@ internal class TraineeRepositoryImpl @Inject constructor(
return user
}

// TODO : API에 맞춰 수정
override suspend fun getDailyDataStatus(yearMonth: YearMonth): List<TraineeDailyRecordStatus> {
val result = MonthlyRecordedDatesResponse(
listOf(
RecordedDateResponse(date = "2025-02-03"),
RecordedDateResponse(date = "2025-02-08"),
RecordedDateResponse(date = "2025-02-10"),
RecordedDateResponse(date = "2025-02-15"),
RecordedDateResponse(date = "2025-02-23"),
),
).calendarRecordInfo.map { response ->
response.toDomain(dateFormatter)
}
override suspend fun getWeeklyRecordedDate(
startDate: String,
endDate: String,
): TraineeDailyRecordStatus {
val response = traineeRemoteDataSource.getWeeklyRecordedDates(startDate, endDate)

return result
return response.toDomain(dateFormatter)
}

// TODO : API에 맞춰 수정
Expand All @@ -69,23 +58,23 @@ internal class TraineeRepositoryImpl @Inject constructor(
trainerName = "김헬스",
trainerImage = "https://buly.kr/44x6xFN",
session = 12,
startTime = "2025-02-03T08:00:00.000Z",
endTime = "2025-02-03T09:00:00.000Z",
startTime = "2025-02-03T08:00:00",
endTime = "2025-02-03T09:00:00",
hasRecord = true,
),
records = listOf(
RecordResponse(
recordId = "VDF1D907",
recordType = "BREAKFAST",
recordTime = "2025-02-03T08:00:00.000Z",
recordTime = "2025-02-03T08:00:00",
recordImage = "https://buly.kr/BpESNP5",
recordContents = "아침으로 계란 2개 먹었습니다.",
feedbackCount = 1,
),
RecordResponse(
recordId = "VDF1D907",
recordType = "LUNCH",
recordTime = "2025-02-03T13:00:00.000Z",
recordTime = "2025-02-03T13:00:00",
recordImage = "https://buly.kr/BpESNP5",
recordContents = "점심으로 계란 5개 먹었습니다.",
feedbackCount = 0,
Expand All @@ -99,23 +88,23 @@ internal class TraineeRepositoryImpl @Inject constructor(
RecordResponse(
recordId = "VDF1D907",
recordType = "BREAKFAST",
recordTime = "2025-02-08T13:00:00.000Z",
recordTime = "2025-02-08T13:00:00",
recordImage = "https://buly.kr/BpESNP5",
recordContents = "계란 2개 먹었습니다.",
feedbackCount = 1,
),
RecordResponse(
recordId = "VDF1D907",
recordType = "SNACK",
recordTime = "2025-02-08T15:00:00.000Z",
recordTime = "2025-02-08T15:00:00",
recordImage = "https://buly.kr/BpESNP5",
recordContents = "계란 반개 먹었습니다.",
feedbackCount = 0,
),
RecordResponse(
recordId = "VDF1D907",
recordType = "DINNER",
recordTime = "2025-02-08T18:40:00.000Z",
recordTime = "2025-02-08T18:40:00",
recordImage = null,
recordContents = "저녁으로 소고기 먹었습니다.",
feedbackCount = 2,
Expand All @@ -129,23 +118,23 @@ internal class TraineeRepositoryImpl @Inject constructor(
trainerName = "이강사",
trainerImage = null,
session = 15,
startTime = "2025-02-15T18:00:00.000Z",
endTime = "2025-02-15T19:00:00.000Z",
startTime = "2025-02-15T18:00:00",
endTime = "2025-02-15T19:00:00",
hasRecord = true,
),
records = listOf(
RecordResponse(
recordId = "VDF1D907",
recordType = "LUNCH",
recordTime = "2025-02-15T13:00:00.000Z",
recordTime = "2025-02-15T13:00:00",
recordImage = null,
recordContents = "비빔밥, 바나나 1개",
feedbackCount = 1,
),
RecordResponse(
recordId = "VDF1D907",
recordType = "DINNER",
recordTime = "2025-02-03T20:00:00.000Z",
recordTime = "2025-02-03T20:00:00",
recordImage = "https://buly.kr/BpESNP5",
recordContents = "계란 5개 먹었습니다.",
feedbackCount = 0,
Expand All @@ -159,8 +148,8 @@ internal class TraineeRepositoryImpl @Inject constructor(
trainerName = "박트레이너",
trainerImage = null,
session = 10,
startTime = "2025-02-10T14:30:00.000Z",
endTime = "2025-02-10T15:30:00.000Z",
startTime = "2025-02-10T14:30:00",
endTime = "2025-02-10T15:30:00",
hasRecord = false,
),
records = emptyList(),
Expand All @@ -172,8 +161,8 @@ internal class TraineeRepositoryImpl @Inject constructor(
trainerName = "정트레이너",
trainerImage = "https://buly.kr/44x6xFN",
session = 25,
startTime = "2025-02-23T06:00:00.000Z",
endTime = "2025-02-23T06:50:00.000Z",
startTime = "2025-02-23T06:00:00",
endTime = "2025-02-23T06:50:00",
hasRecord = true,
),
records = emptyList(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ package co.kr.tnt.domain.model.trainee
import java.time.LocalDate

data class TraineeDailyRecordStatus(
val date: LocalDate,
val dates: List<LocalDate>,
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@ import co.kr.tnt.domain.model.trainee.TraineeDailyRecordStatus
import java.io.File
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.YearMonth

interface TraineeRepository {
suspend fun getMyInfo(): User.Trainee
suspend fun getDailyDataStatus(yearMonth: YearMonth): List<TraineeDailyRecordStatus>
suspend fun getTraineeDailyRecord(day: LocalDate): TraineeDailyRecord
suspend fun postMealRecord(
mealImage: File?,
date: LocalDateTime,
mealType: String,
memo: String,
)
suspend fun getWeeklyRecordedDate(
startDate: String,
endDate: String,
): TraineeDailyRecordStatus
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ import java.time.YearMonth
internal class TraineeHomeContract {
data class TraineeHomeUiState(
val selectedDay: LocalDate = LocalDate.now(),
val dailyRecordStatus: List<TraineeDailyRecordStatus> = emptyList(),
val recordedDates: TraineeDailyRecordStatus? = null,
val ptSessions: TraineePtSession? = null,
val recordList: List<DailyRecord> = emptyList(),
) : UiState

sealed interface TraineeHomeUiEvent : UiEvent {
data object OnScreen : TraineeHomeUiEvent
data class OnChangeVisibleMonth(val yearMonth: YearMonth) : TraineeHomeUiEvent
data class OnClickPtSessionCard(val ptSessionId: String) : TraineeHomeUiEvent
data object OnClickExerciseRecord : TraineeHomeUiEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ internal fun TraineeHomeRoute(
}
}
}

// TODO 홈 화면 진입 시마다 데이터 조회 재고 필요
LaunchedEffect(true) { viewModel.setEvent(TraineeHomeUiEvent.OnScreen) }
}

@Composable
Expand Down Expand Up @@ -194,7 +197,7 @@ private fun TraineeHomeScreen(
Calendar(
weekCalendarState = weekCalendarState,
selectedDay = state.selectedDay,
dailyDataState = state.dailyRecordStatus,
dailyDataState = state.recordedDates,
onClickDay = onClickDay,
)
Spacer(modifier = Modifier.height(12.dp))
Expand Down Expand Up @@ -269,15 +272,15 @@ private fun TraineeHomeScreen(
private fun Calendar(
weekCalendarState: WeekCalendarState,
selectedDay: LocalDate,
dailyDataState: List<TraineeDailyRecordStatus>,
dailyDataState: TraineeDailyRecordStatus?,
onClickDay: (LocalDate) -> Unit,
modifier: Modifier = Modifier,
) {
TnTIndicatorWeekCalendar(
state = weekCalendarState,
dayState = { day -> DayState(isSelected = day == selectedDay) },
indicatorState = { day ->
DayIndicatorState(showIcon = dailyDataState.any { it.date == day })
DayIndicatorState(showIcon = dailyDataState?.dates?.contains(day) ?: false)
},
onClickDay = onClickDay,
modifier = modifier.background(TnTTheme.colors.commonColors.Common0),
Expand Down
Loading