Skip to content

Commit

Permalink
Date 관련 컴포넌트 개편 (#334)
Browse files Browse the repository at this point in the history
- SessionTime을 String Type -> LocalDateTime으로 변경
- DateUtil제거
- UI에 존재하는 시간 관련 계산로직 제거
  • Loading branch information
toastmeister1 authored May 15, 2024
1 parent 1604d9a commit 14f512f
Show file tree
Hide file tree
Showing 50 changed files with 448 additions and 436 deletions.

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
}
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 {
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

0 comments on commit 14f512f

Please sign in to comment.