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

[Session] 세션 하나의 정보를 가져올 수 있는 유즈케이스 구현 #136

Merged
merged 6 commits into from
Jul 29, 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
2 changes: 2 additions & 0 deletions core/data/src/main/assets/sessions.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[
{
"id": "1",
"title": "Keynote",
"content": [],
"speakers": [],
Expand All @@ -12,6 +13,7 @@
"endTime": "2023-09-12T13:20:00.000"
},
{
"id": "2",
"title": "Jetpack Compose로 Android UI 개발하기",
"content": [
"Jetpack Compose는 네이티브 UI를 빌드하기 위한 Android의 최신 권장 도구 키트입니다."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import kotlinx.serialization.Serializable

@Serializable
internal data class SessionResponse(
val id: String,
val title: String,
val content: List<String>,
val speakers: List<SpeakerResponse>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.droidknights.app2023.core.model.Speaker
import com.droidknights.app2023.core.model.Tag

internal fun SessionResponse.toData(): Session = Session(
id = this.id,
title = this.title,
content = this.content,
speakers = this.speakers.map { it.toData() },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,20 @@ import javax.inject.Inject
internal class DefaultSessionRepository @Inject constructor(
private val githubRawApi: GithubRawApi,
) : SessionRepository {
private var cachedSessions: List<Session> = emptyList()

override suspend fun getSessions(): List<Session> {
return githubRawApi.getSessions().map { it.toData() }
return githubRawApi.getSessions()
.map { it.toData() }
.also { cachedSessions = it }
}

override suspend fun getSession(sessionId: String): Session {
val cachedSession = cachedSessions.find { it.id == sessionId }
if (cachedSession != null) {
return cachedSession
}
return getSessions().find { it.id == sessionId }
?: throw IllegalStateException("Session not found with id: $sessionId")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ import com.droidknights.app2023.core.model.Session
interface SessionRepository {

suspend fun getSessions(): List<Session>

suspend fun getSession(sessionId: String): Session
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ internal class DefaultSessionRepositoryTest : StringSpec() {
"역직렬화 테스트" {
val expected = listOf(
Session(
id = "1",
title = "Keynote",
content = listOf(),
speakers = listOf(),
Expand All @@ -29,6 +30,7 @@ internal class DefaultSessionRepositoryTest : StringSpec() {
endTime = LocalDateTime(2023, 9, 12, 13, 20),
),
Session(
id = "2",
title = "Jetpack Compose로 Android UI 개발하기",
content = listOf("Jetpack Compose는 네이티브 UI를 빌드하기 위한 Android의 최신 권장 도구 키트입니다."),
speakers = listOf(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.droidknights.app2023.core.domain.usecase

import com.droidknights.app2023.core.data.repository.SessionRepository
import com.droidknights.app2023.core.model.Session
import javax.inject.Inject

class GetSessionUseCase @Inject constructor(
private val sessionRepository: SessionRepository,
) {

suspend operator fun invoke(sessionId: String): Session {
// TODO: Session 데이터 연결 후 제거
return GetSessionsUseCase(sessionRepository).invoke().first { it.id == sessionId }
return sessionRepository.getSession(sessionId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class GetSessionsUseCase @Inject constructor(
suspend operator fun invoke(): List<Session> {
return listOf(
Session(
id = "1",
title = "Jetpack Compose에 있는 것, 없는 것",
content = emptyList(),
speakers = listOf(
Expand All @@ -36,6 +37,7 @@ class GetSessionsUseCase @Inject constructor(
room = Room.TRACK1,
),
Session(
id = "2",
title = "Asynchronous Programming for Android",
content = emptyList(),
speakers = listOf(
Expand All @@ -57,6 +59,7 @@ class GetSessionsUseCase @Inject constructor(
room = Room.TRACK1,
),
Session(
id = "3",
title = "안드로이드 앱에서 Koin걷어내고 Hilt로 마이그레이션하기",
content = emptyList(),
speakers = listOf(
Expand All @@ -74,6 +77,7 @@ class GetSessionsUseCase @Inject constructor(
room = Room.TRACK2,
),
Session(
id = "4",
title = "Asynchronous Programming for Android",
content = emptyList(),
speakers = listOf(
Expand All @@ -91,6 +95,7 @@ class GetSessionsUseCase @Inject constructor(
room = Room.TRACK2,
),
Session(
id = "5",
title = "안드로이드 앱에서 Koin걷어내고 Hilt로 마이그레이션하기",
content = emptyList(),
speakers = listOf(
Expand All @@ -108,6 +113,7 @@ class GetSessionsUseCase @Inject constructor(
room = Room.TRACK3,
),
Session(
id = "6",
title = "Asynchronous Programming for Android",
content = emptyList(),
speakers = listOf(
Expand All @@ -125,6 +131,7 @@ class GetSessionsUseCase @Inject constructor(
room = Room.TRACK3,
),
Session(
id = "7",
title = "Asynchronous Programming for Android",
content = emptyList(),
speakers = listOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.droidknights.app2023.core.model
import kotlinx.datetime.LocalDateTime

data class Session(
val id: String,
val title: String,
val content: List<String>,
val speakers: List<Speaker>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ internal fun MainScreen(navigator: MainNavigator = rememberMainNavigator()) {

sessionNavGraph(
onBackClick = { navigator.popBackStack() },
onSessionClick = { navigator.navigateSessionDetail("TODO") }
onSessionClick = { navigator.navigateSessionDetail(it.id) }
)

composable("temp") { content("temp") }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ private val CardContentPadding =
@Composable
private fun SessionCardPreview() {
val fakeSession = Session(
id = "1",
title = "Jetpack Compose에 있는 것, 없는 것",
content = emptyList(),
speakers = listOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ data class SessionState(
.groupBy { it.room }
.map { (room, sessions) -> SessionGroup(room, sessions) }

val rooms: List<Room> = sessions.map { it.room }
val rooms: List<Room> = sessions.map { it.room }.distinct()

private val roomPositions: Map<Room, Int> = buildMap {
var position = 0
Expand Down