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

Date 관련 컴포넌트 개편 #334

Merged
merged 26 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a86ff60
RenewDateUtil 추가
toastmeister1 Jan 14, 2024
4ab3b1d
Session의 date 값을 LocalDateTime으로 변경
toastmeister1 Jan 14, 2024
245b83a
기존 DateUtil 제거
toastmeister1 Jan 14, 2024
3d1d849
RenewDateUtil 을 DateUtil로 네이밍 변경
toastmeister1 Jan 14, 2024
f513e62
DateParser를 다른 파일로 분리
toastmeister1 Jan 14, 2024
5e46440
develop 브랜치 rebase후 코드 수정
toastmeister1 Jan 20, 2024
7f3b2d9
기존 RemoteConfig에서 SessionList를 가져오는 로직 제거
toastmeister1 Jan 20, 2024
c4ed691
출석시 Session 모델에 담긴 Code로 출석하도록 수정
toastmeister1 Jan 20, 2024
fd662a7
불필요한 Nullable 제거
toastmeister1 Jan 27, 2024
b8052d1
메서드명 오탈자 수정
toastmeister1 Jan 27, 2024
40911c1
메서드명을 더 직관적으로 이해할수 있도록 변경
toastmeister1 Jan 27, 2024
3fc90df
WarningSign 제거
toastmeister1 Jan 27, 2024
c61af06
DateUtil의 함수명과 동작방식을 변경
toastmeister1 Jan 27, 2024
040f10a
불필요한 Test파일 제거
toastmeister1 May 4, 2024
f2686db
DateUtil 제거
toastmeister1 May 4, 2024
25a3a64
UseCase에서 DateUtil을 대신 LocalDateTime의 확장함수로 연산하도록 수정
toastmeister1 May 4, 2024
187278e
사용하지 않는 엔티티 제거
toastmeister1 May 4, 2024
48aac2e
YDSAttendanceType이 ResId를 가지고 있지 않도록 수정
toastmeister1 May 4, 2024
160adbb
UI에서 사용되던 checkSessionAttendance를 메서드 제거
toastmeister1 May 4, 2024
cfefc43
AdminMain 화면 DateUtil제거
toastmeister1 May 4, 2024
55e6af0
SessionDetail 화면 개선
toastmeister1 May 4, 2024
30ee163
MemberScore 화면 개선
toastmeister1 May 4, 2024
1160788
년, 월, 일, 일치하는 경우 오늘의 세션을 리턴하도록 수정
toastmeister1 May 5, 2024
0b78a99
출석 시간을 계산하는 로직을 GetUpComingSessionUseCase에 의존하도록 수정
toastmeister1 May 5, 2024
5c9afb6
UseCase 네이밍 수정
toastmeister1 May 5, 2024
a717860
오탈자 수정
toastmeister1 May 6, 2024
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.

8 changes: 5 additions & 3 deletions app/src/main/java/com/yapp/attendance/di/DataModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.yapp.domain.repository.MemberRepository
import com.yapp.domain.repository.RemoteConfigRepository
import com.yapp.domain.repository.SessionRepository
import com.yapp.domain.repository.TeamRepository
import com.yapp.domain.util.DateParser
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
Expand Down Expand Up @@ -57,15 +58,16 @@ object DataModule {
@Provides
@Singleton
fun provideSessionRepository(
sessionDataSource: SessionRemoteDataSource
sessionDataSource: SessionRemoteDataSource,
dateParser: DateParser
): SessionRepository {
return SessionRepositoryImpl(sessionDataSource)
return SessionRepositoryImpl(sessionDataSource, dateParser)
}

@Provides
@Singleton
fun provideRemoteConfigRepository(
remoteConfigDataSource: FirebaseRemoteConfigDataSource,
remoteConfigDataSource: FirebaseRemoteConfigDataSource
): RemoteConfigRepository {
return RemoteConfigRepositoryImpl(remoteConfigDataSource)
}
Expand Down
5 changes: 5 additions & 0 deletions buildSrc/src/main/java/com/yapp/buildsrc/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ object Dependencies {
const val JUNIT = "junit:junit:4.+"
const val ANDROID_JUNIT = "androidx.test.ext:junit:1.1.3"
const val ESPRESSO_CORE = "androidx.test.espresso:espresso-core:3.4.0"

private const val kotest_version = "5.8.0"
const val KOTEST_RUNNER = "io.kotest:kotest-runner-junit5:${kotest_version}"
const val KOTEST_ASSERTION = "io.kotest:kotest-assertions-core:${kotest_version}"
const val KOTEST_PROPERTY = "io.kotest:kotest-property:${kotest_version}"
}

object Firebase {
Expand Down
44 changes: 33 additions & 11 deletions common/src/main/java/com/yapp/common/yds/YDSAttendanceList.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.yapp.common.yds

import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
Expand All @@ -17,6 +15,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow
Expand Down Expand Up @@ -44,7 +43,7 @@ fun YDSAttendanceList(
.padding(24.dp)
) {
Icon(
painterResource(id = attendanceType.icon),
painter = attendanceType.icon(),
contentDescription = null,
tint = Color.Unspecified,
modifier = Modifier.alpha(
Expand All @@ -61,7 +60,7 @@ fun YDSAttendanceList(
horizontalArrangement = Arrangement.SpaceBetween
) {
Text(
text = stringResource(attendanceType.title),
text = attendanceType.text(),
style = AttendanceTypography.body2,
color = when (attendanceType) {
YDSAttendanceType.ATTEND -> AttendanceTheme.colors.etcColors.EtcGreen
Expand Down Expand Up @@ -97,11 +96,34 @@ fun YDSAttendanceList(
}
}

enum class YDSAttendanceType(@DrawableRes val icon: Int, @StringRes val title: Int) {
ATTEND(R.drawable.icon_attend, R.string.attend),
TARDY(R.drawable.icon_tardy, R.string.tardy),
ABSENT(R.drawable.icon_absent, R.string.absent),
TBD(R.drawable.icon_absent, R.string.tbd),
NO_ATTENDANCE(R.drawable.icon_absent, R.string.no_attendance),
NO_YAPP(R.drawable.icon_absent, R.string.no_yapp)
@Composable
fun YDSAttendanceType.text(): String {
return stringResource(
id = when (this) {
YDSAttendanceType.ATTEND -> R.string.attend
YDSAttendanceType.TARDY -> R.string.tardy
YDSAttendanceType.ABSENT -> R.string.absent
YDSAttendanceType.TBD -> R.string.tbd
YDSAttendanceType.NO_ATTENDANCE -> R.string.no_attendance
YDSAttendanceType.NO_YAPP -> R.string.no_yapp
}
)
}

@Composable
fun YDSAttendanceType.icon(): Painter {
return painterResource(
id = when (this) {
YDSAttendanceType.ATTEND -> R.drawable.icon_attend
YDSAttendanceType.TARDY -> R.drawable.icon_tardy
YDSAttendanceType.ABSENT -> R.drawable.icon_absent
YDSAttendanceType.TBD -> R.drawable.icon_absent
YDSAttendanceType.NO_ATTENDANCE -> R.drawable.icon_absent
YDSAttendanceType.NO_YAPP -> R.drawable.icon_absent
}
)
}

enum class YDSAttendanceType {
ATTEND, TARDY, ABSENT, TBD, NO_ATTENDANCE, NO_YAPP
Comment on lines +127 to +128
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

YDSAttendanceTypeResId를 가지고 있는 바람에 ViewModel 단에서 사용하지 못하는 단점이 존재

이 부분에 대해 제대로 이해하지 못했어요 ㅠㅠ
AttendanceTypeMapper 가 있다면 ResId 가 있더라도 ViewModel 에서 매핑이 가능하지 않나용?? ㅠㅠ

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checkAttendanceType 메서드가 왜 UI쪽에 있는지를 보다가
YDSAttendanceType이 ResId를 가지고 있어서 ViewModel에서 사용이 어려워서 그랬구나 판단했습니다
(ViewModel에서 리소스를 사용하는건 메모리 릭 우려가 있어 권장되지 않는다는 글이 생각났네요)

그리고 YDSAttendanceType은 icon과 텍스트 resId를 가지고 있지 않게 수정한 이유는 단순 아이콘, 텍스트 이외에도 컬러를 지정할때도 사용하고 있는데요
그렇다면 YDSAttendanceType에는 또 다시 컬러의 resId가 들어가게 될것이고,
앞으로 AttendanceType에 관련된 컴포넌트들이 생긴다면 이곳에 계속 몰리는걸 우려했네요

YDSAttendanceType를 최대한 가볍게 가져가는 게 좋을것 같다는 이유였어요

}
22 changes: 0 additions & 22 deletions data/src/androidTest/java/com/yapp/data/ExampleInstrumentedTest.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import com.yapp.data.model.VersionEntity

interface FirebaseRemoteConfigDataSource {
suspend fun getMaginotlineTime(): String
suspend fun getSessionList(): List<SessionEntity>
suspend fun getConfig(): ConfigEntity
suspend fun getTeamList(): List<TeamEntity>
suspend fun getQrPassword(): String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,6 @@ class FirebaseRemoteConfigDataSourceImpl @Inject constructor() : FirebaseRemoteC
}
}

override suspend fun getSessionList(): List<SessionEntity> {
return suspendCancellableCoroutine { cancellableContinuation ->
firebaseRemoteConfig.fetchAndActivate().addOnSuccessListener {
val entities = firebaseRemoteConfig.getString(RemoteConfigData.SessionList.key)
.let { jsonString ->
Json.decodeFromString<List<SessionEntity>>(jsonString)
}

cancellableContinuation.resume(value = entities, onCancellation = null)
}.addOnFailureListener { exception ->
cancellableContinuation.resumeWithException(exception)
}
}
}

override suspend fun getConfig(): ConfigEntity {
return suspendCancellableCoroutine { cancellableContinuation ->
firebaseRemoteConfig.fetchAndActivate().addOnSuccessListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import com.yapp.data.model.SessionEntity

interface SessionRemoteDataSource {
suspend fun setSession(session: SessionEntity)
suspend fun getSession(id: Long): SessionEntity?
suspend fun getSession(id: Int): SessionEntity?
suspend fun getAllSession(): List<SessionEntity>
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class SessionRemoteDataSourceImpl @Inject constructor(
}
}

override suspend fun getSession(id: Long): SessionEntity? {
override suspend fun getSession(id: Int): SessionEntity? {
return suspendCancellableCoroutine { cancellableContinuation ->
fireStore.sessionRef()
.document(id.toString())
Expand Down
4 changes: 4 additions & 0 deletions data/src/main/java/com/yapp/data/model/AttendanceEntity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ fun Attendance.toData(): AttendanceEntity {
status = status.toData()
)
}

fun Attendance.Status.toData(): String {
return this.name.uppercase()
}
17 changes: 9 additions & 8 deletions data/src/main/java/com/yapp/data/model/SessionEntity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.yapp.data.model
import com.google.firebase.firestore.PropertyName
import com.yapp.domain.model.Session
import com.yapp.domain.model.types.NeedToAttendType
import com.yapp.domain.util.DateParser
import kotlinx.serialization.Serializable

@Serializable
Expand All @@ -21,24 +22,24 @@ data class SessionEntity(
val code: String? = null
)

fun SessionEntity.toDomain(): Session {
fun SessionEntity.toDomain(dateParser: DateParser): Session {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

도메인 계층으로 매핑할 때 날짜를 LocalDateTime 형태로 파싱하는 아이디어 되게 좋은 것 같아요 !! 👍👍👍👍

return Session(
sessionId = sessionId!!,
title = title!!,
startTime = startTime!!,
description = description!!,
type = NeedToAttendType.valueOf(type!!),
code = code ?: ""
startTime = dateParser.parse(rawDate = startTime!!),
description = description!!,
code = code!!
)
}

fun Session.toData(): SessionEntity {
fun Session.toData(dateParser: DateParser): SessionEntity {
return SessionEntity(
sessionId = sessionId,
title = title,
startTime = startTime,
description = description,
type = type.name,
startTime = dateParser.format(date = startTime),
description = description,
code = code
)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import com.yapp.domain.model.Config
import com.yapp.domain.model.Session
import com.yapp.domain.model.Team
import com.yapp.domain.model.Version
import com.yapp.domain.model.types.NeedToAttendType
import com.yapp.domain.repository.RemoteConfigRepository
import com.yapp.domain.util.DateParser
import javax.inject.Inject


class RemoteConfigRepositoryImpl @Inject constructor(
private val firebaseRemoteConfigDataSource: FirebaseRemoteConfigDataSource,
private val firebaseRemoteConfigDataSource: FirebaseRemoteConfigDataSource
) : RemoteConfigRepository {

private var isAlreadyRequestUpdate = false
Expand All @@ -33,19 +35,6 @@ class RemoteConfigRepositoryImpl @Inject constructor(
)
}

override suspend fun getSessionList(): Result<List<Session>> {
return runCatching {
firebaseRemoteConfigDataSource.getSessionList()
}.fold(
onSuccess = { entities: List<SessionEntity> ->
Result.success(entities.map { it.toDomain() })
},
onFailure = { exception ->
Result.failure(exception)
}
)
}

override suspend fun getConfig(): Result<Config> {
return runCatching {
firebaseRemoteConfigDataSource.getConfig()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ import com.yapp.data.model.toData
import com.yapp.data.model.toDomain
import com.yapp.domain.model.Session
import com.yapp.domain.repository.SessionRepository
import com.yapp.domain.util.DateParser
import javax.inject.Inject

class SessionRepositoryImpl @Inject constructor(
private val sessionRemoteDataSource: SessionRemoteDataSource,
private val dateParser: DateParser
) : SessionRepository {
override suspend fun setSession(session: Session): Result<Unit> {
return runCatching {
sessionRemoteDataSource.setSession(session.toData())
sessionRemoteDataSource.setSession(session.toData(dateParser))
}.fold(
onSuccess = {
Result.success(Unit)
Expand All @@ -23,9 +25,9 @@ class SessionRepositoryImpl @Inject constructor(
)
}

override suspend fun getSession(id: Long): Result<Session?> {
override suspend fun getSession(id: Int): Result<Session?> {
return runCatching {
sessionRemoteDataSource.getSession(id)?.toDomain()
sessionRemoteDataSource.getSession(id)?.toDomain(dateParser)
}.fold(
onSuccess = {
Result.success(it)
Expand All @@ -38,9 +40,7 @@ class SessionRepositoryImpl @Inject constructor(

override suspend fun getAllSession(): Result<List<Session>> {
return runCatching {
sessionRemoteDataSource.getAllSession().map {
it.toDomain()
}
sessionRemoteDataSource.getAllSession().map { entity -> entity.toDomain(dateParser) }
}.fold(
onSuccess = {
Result.success(it)
Expand Down
7 changes: 7 additions & 0 deletions domain/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@ plugins {
kotlin("kapt")
}

tasks.test {
useJUnitPlatform()
}

dependencies {
implementation(Dependencies.INJECT)
implementation(Dependencies.Kotlin.COROUTINE_CORE)

testImplementation(Dependencies.Test.KOTEST_RUNNER)
testImplementation(Dependencies.Test.KOTEST_ASSERTION)
testImplementation(Dependencies.Test.KOTEST_PROPERTY)
}
Loading
Loading