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

데일리 문제 화면/결과 구현 #28

Merged
merged 8 commits into from
Aug 16, 2023
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.keyme.app.navigation

import androidx.annotation.DrawableRes
import com.keyme.presentation.feed.ui.FeedDestination
import com.keyme.presentation.dailykeymetest.DailyKeymeTestDestination
import com.keyme.presentation.myprofile.ui.MyProfileDestination
import com.keyme.presentation.navigation.KeymeNavigationDestination

Expand All @@ -14,8 +14,8 @@ data class TopLevelDestination(

val keymeTopLevelDestinations = listOf(
TopLevelDestination(
route = FeedDestination.route,
destination = FeedDestination.destination,
route = DailyKeymeTestDestination.route,
destination = DailyKeymeTestDestination.destination,
selectedIconResId = com.keyme.presentation.R.drawable.icon_tab_feed,
unselectedIconResId = com.keyme.presentation.R.drawable.icon_tab_feed_unselected,
),
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/java/com/keyme/app/ui/KeymeApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import com.keyme.app.navigation.TopLevelDestination
import com.keyme.app.navigation.keymeTopLevelDestinations
import com.keyme.presentation.alarm.ui.AlarmDestination
import com.keyme.presentation.alarm.ui.alarmGraph
import com.keyme.presentation.dailykeymetest.DailyKeymeTestDestination
import com.keyme.presentation.dailykeymetest.dailyKeymeTestGraph
import com.keyme.presentation.designsystem.theme.KeymeTheme
import com.keyme.presentation.feed.ui.FeedDestination
import com.keyme.presentation.feed.ui.feedGraph
import com.keyme.presentation.keymetest.KeymeTestDestination
import com.keyme.presentation.keymetest.keymeTestGraph
import com.keyme.presentation.myprofile.ui.KeymeQuestionResultDestination
Expand Down Expand Up @@ -51,13 +51,13 @@ fun KeymeApp() {
) {
onboardingGraph(
navigateToOnboardingTest = { appState.navigate(KeymeTestDestination) },
navigateToMyDaily = { appState.navigate(FeedDestination) },
navigateToMyDaily = { appState.navigate(DailyKeymeTestDestination) },
)
keymeTestGraph(
onBackClick = appState::onBackClick,
navigateToMyDaily = { appState.navigate(FeedDestination) },
navigateToMyDaily = { appState.navigate(DailyKeymeTestDestination) },
)
feedGraph(
dailyKeymeTestGraph(
navigateToAlarm = { appState.navigate(AlarmDestination) },
nestedGraphs = {
alarmGraph(onBackClick = appState::onBackClick)
Expand Down
19 changes: 14 additions & 5 deletions data/src/main/java/com/keyme/data/remote/api/KeymeApi.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.keyme.data.remote.api

import com.keyme.domain.entity.request.SignInRequest
import com.keyme.domain.entity.response.DailyTestResponse
import com.keyme.domain.entity.response.MemberStatistics
import com.keyme.domain.entity.response.MemberStatisticsResponse
import com.keyme.domain.entity.response.OnBoardingTestResponse
import com.keyme.domain.entity.response.QuestionSolvedScoreListResponse
import com.keyme.domain.entity.response.QuestionSolvedScoreResponse
import com.keyme.domain.entity.response.QuestionStatisticsResponse
import com.keyme.domain.entity.response.SignInResponse
import com.keyme.domain.entity.response.TestStatisticResponse
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.POST
Expand All @@ -20,11 +23,6 @@ interface KeymeApi {
@Body signInRequest: SignInRequest,
): SignInResponse

// @GET("tests/{id}/statistics")
// suspend fun getKeymeTestResultStatistics(
// @Path("id") questionId: String,
// ): KeymeTestResultStatisticsResponse

@GET("members/{memberId}/statistics")
suspend fun getMemberStatistics(
@Path("memberId") memberId: String,
Expand All @@ -50,4 +48,15 @@ interface KeymeApi {
@Query("limit") limit: Int = 20,
@Query("ownerId") ownerId: Int,
): QuestionSolvedScoreListResponse

@GET("tests/onboarding")
suspend fun getOnBoardingTest(): OnBoardingTestResponse

@GET("tests/daily")
suspend fun getDailyTest(): DailyTestResponse

@GET("tests/{id}/statistics")
suspend fun getTestStatistic(
@Path("id") testId: Int,
): TestStatisticResponse
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.keyme.data.remote.di

import com.keyme.data.remote.repositoryimpl.KeymeTestRepositoryImpl
import com.keyme.data.remote.repositoryimpl.MemberRepositoryImpl
import com.keyme.data.remote.repositoryimpl.QuestionRepositoryImpl
import com.keyme.data.remote.repositoryimpl.SignInRepositoryImpl
import com.keyme.domain.repository.KeymeTestRepository
import com.keyme.domain.repository.MemberRepository
import com.keyme.domain.repository.QuestionRepository
import com.keyme.domain.repository.SignInRepository
Expand All @@ -23,4 +25,7 @@ abstract class RepositoryModule {

@Binds
abstract fun bindQuestionRepository(impl: QuestionRepositoryImpl): QuestionRepository

@Binds
abstract fun bindKeymeTestRepository(impl: KeymeTestRepositoryImpl): KeymeTestRepository
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.keyme.data.remote.repositoryimpl

import com.keyme.data.remote.api.KeymeApi
import com.keyme.domain.entity.response.DailyTestResponse
import com.keyme.domain.entity.response.OnBoardingTestResponse
import com.keyme.domain.entity.response.TestStatisticResponse
import com.keyme.domain.repository.KeymeTestRepository
import javax.inject.Inject

class KeymeTestRepositoryImpl @Inject constructor(
private val keymeApi: KeymeApi,
) : KeymeTestRepository {
override suspend fun getOnBoardingTest(): OnBoardingTestResponse {
return keymeApi.getOnBoardingTest()
}

override suspend fun getDailyTest(): DailyTestResponse {
return keymeApi.getDailyTest()
}

override suspend fun getTestStatistic(testId: Int): TestStatisticResponse {
return keymeApi.getTestStatistic(testId)
}
}
10 changes: 5 additions & 5 deletions domain/src/main/java/com/keyme/domain/entity/member/Member.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.keyme.domain.entity.member

data class Member(
val friendCode: String,
val id: Int,
val nickname: String,
val profileImage: String,
val profileThumbnail: String,
val friendCode: String = "",
val id: Int = 0,
val nickname: String = "",
val profileImage: String = "",
val profileThumbnail: String = "",
) {
companion object {
val EMPTY = Member(friendCode = "", id = 0, nickname = "", profileImage = "", profileThumbnail = "")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.keyme.domain.entity.response

import com.keyme.domain.entity.BaseResponse

class DailyTestResponse : BaseResponse<Test>()
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.keyme.domain.entity.response

import com.keyme.domain.entity.BaseResponse

class OnBoardingTestResponse : BaseResponse<Test>()
29 changes: 29 additions & 0 deletions domain/src/main/java/com/keyme/domain/entity/response/Test.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.keyme.domain.entity.response

import com.keyme.domain.entity.member.Member

data class Test(
val questions: List<Question>,
val owner: Member,
val solvedCount: Int,
val testId: Int,
val testResultId: Int,
val title: String,
) {
companion object {
val EMPTY = Test(
questions = listOf(),
owner = Member(
friendCode = "",
id = 0,
nickname = "",
profileImage = "",
profileThumbnail = "",
),
solvedCount = 0,
testId = 0,
testResultId = 0,
title = "",
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.keyme.domain.entity.response

data class TestStatistic(
val averageRate: Float,
val solvedCount: Int,
val questionsStatistics: List<QuestionStatistic>,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.keyme.domain.entity.response

import com.keyme.domain.entity.BaseResponse

class TestStatisticResponse : BaseResponse<TestStatistic>()
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.keyme.domain.repository

import com.keyme.domain.entity.response.DailyTestResponse
import com.keyme.domain.entity.response.OnBoardingTestResponse
import com.keyme.domain.entity.response.TestStatisticResponse

interface KeymeTestRepository {

suspend fun getOnBoardingTest(): OnBoardingTestResponse

suspend fun getDailyTest(): DailyTestResponse

suspend fun getTestStatistic(testId: Int): TestStatisticResponse
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.keyme.domain.usecase

import com.keyme.domain.entity.apiResult
import com.keyme.domain.repository.KeymeTestRepository
import javax.inject.Inject

class GetDailyKeymeTestUseCase @Inject constructor(
private val keymeTestRepository: KeymeTestRepository,
) {
suspend operator fun invoke() = apiResult { keymeTestRepository.getDailyTest() }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.keyme.domain.usecase

import com.keyme.domain.entity.apiResult
import com.keyme.domain.repository.KeymeTestRepository
import javax.inject.Inject

class GetKeymeTestStatisticUseCase @Inject constructor(
private val keymeTestRepository: KeymeTestRepository,
) {

suspend operator fun invoke(testId: Int) = apiResult { keymeTestRepository.getTestStatistic(testId) }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.keyme.presentation.dailykeymetest

import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.composable
import androidx.navigation.navigation
import com.keyme.presentation.navigation.KeymeNavigationDestination

object DailyKeymeTestDestination : KeymeNavigationDestination {
override val route = "daily_keyme_test_route"
override val destination = "daily_keyme_test_destination"
}

fun NavGraphBuilder.dailyKeymeTestGraph(
navigateToAlarm: () -> Unit,
nestedGraphs: NavGraphBuilder.() -> Unit,
) {
navigation(
route = DailyKeymeTestDestination.route,
startDestination = DailyKeymeTestDestination.destination,
) {
composable(route = DailyKeymeTestDestination.destination) {
DailyKeymeTestRoute()
}
nestedGraphs()
}
}

@Composable
fun DailyKeymeTestRoute(
dailyKeymeTestViewModel: DailyKeymeTestViewModel = hiltViewModel(),
) {
val myCharacter by dailyKeymeTestViewModel.myCharacterState.collectAsStateWithLifecycle()
val dailyKeymeTest by dailyKeymeTestViewModel.dailyKeymeTestState.collectAsStateWithLifecycle()
val dailyKeymeTestStatistic by dailyKeymeTestViewModel.dailyKeymeTestStatisticState.collectAsStateWithLifecycle()

DailyKeymeTestScreen(
myCharacter = myCharacter,
dailyKeymeTest = dailyKeymeTest,
dailyKeymeTestStatistic = dailyKeymeTestStatistic,
onDailyKeymeTestClick = {
// todo navigate to keyme test
},
)
}
Loading