Skip to content
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,11 +1,11 @@
package com.threegap.bitnagil.data.emotion.datasource

import com.threegap.bitnagil.data.emotion.model.dto.EmotionDto
import com.threegap.bitnagil.data.emotion.model.response.MyEmotionResponseDto
import com.threegap.bitnagil.data.emotion.model.response.GetEmotionResponse
import com.threegap.bitnagil.data.emotion.model.response.RegisterEmotionResponse

interface EmotionDataSource {
suspend fun getEmotions(): Result<List<EmotionDto>>
suspend fun registerEmotion(emotion: String): Result<RegisterEmotionResponse>
suspend fun getMyEmotionMarble(currentDate: String): Result<MyEmotionResponseDto>
suspend fun getEmotionMarble(currentDate: String): Result<GetEmotionResponse>
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.threegap.bitnagil.data.common.safeApiCall
import com.threegap.bitnagil.data.emotion.datasource.EmotionDataSource
import com.threegap.bitnagil.data.emotion.model.dto.EmotionDto
import com.threegap.bitnagil.data.emotion.model.request.RegisterEmotionRequest
import com.threegap.bitnagil.data.emotion.model.response.MyEmotionResponseDto
import com.threegap.bitnagil.data.emotion.model.response.GetEmotionResponse
import com.threegap.bitnagil.data.emotion.model.response.RegisterEmotionResponse
import com.threegap.bitnagil.data.emotion.service.EmotionService
import javax.inject.Inject
Expand All @@ -25,8 +25,8 @@ class EmotionDataSourceImpl @Inject constructor(
}
}

override suspend fun getMyEmotionMarble(currentDate: String): Result<MyEmotionResponseDto> =
override suspend fun getEmotionMarble(currentDate: String): Result<GetEmotionResponse> =
safeApiCall {
emotionService.getMyEmotionMarble(currentDate)
emotionService.getEmotionMarble(currentDate)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.threegap.bitnagil.data.emotion.model.dto

import com.threegap.bitnagil.domain.emotion.model.Emotion
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

Expand All @@ -11,4 +12,11 @@ data class EmotionDto(
val emotionMarbleName: String,
@SerialName("imageUrl")
val imageUrl: String,
)
) {
fun toDomain(): Emotion =
Emotion(
emotionType = emotionMarbleType,
emotionMarbleName = emotionMarbleName,
imageUrl = imageUrl,
)
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.threegap.bitnagil.data.emotion.model.response

import com.threegap.bitnagil.domain.emotion.model.Emotion
import com.threegap.bitnagil.domain.emotion.model.MyEmotion
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class MyEmotionResponseDto(
data class GetEmotionResponse(
@SerialName("emotionMarbleType")
val emotionMarbleType: String?,
@SerialName("emotionMarbleName")
Expand All @@ -15,9 +14,14 @@ data class MyEmotionResponseDto(
val imageUrl: String?,
)

fun MyEmotionResponseDto.toDomain(): MyEmotion =
MyEmotion(
emotionMarbleType = emotionMarbleType?.let { Emotion.valueOf(it) },
emotionMarbleName = emotionMarbleName,
imageUrl = imageUrl,
)
fun GetEmotionResponse.toDomain(): Emotion? {
return if (emotionMarbleType != null && emotionMarbleName != null && imageUrl != null) {
Emotion(
emotionType = emotionMarbleType,
emotionMarbleName = emotionMarbleName,
imageUrl = imageUrl,
)
} else {
null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,39 @@ package com.threegap.bitnagil.data.emotion.repositoryImpl
import com.threegap.bitnagil.data.emotion.datasource.EmotionDataSource
import com.threegap.bitnagil.data.emotion.model.response.toDomain
import com.threegap.bitnagil.domain.emotion.model.Emotion
import com.threegap.bitnagil.domain.emotion.model.EmotionChangeEvent
import com.threegap.bitnagil.domain.emotion.model.EmotionRecommendRoutine
import com.threegap.bitnagil.domain.emotion.model.MyEmotion
import com.threegap.bitnagil.domain.emotion.repository.EmotionRepository
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.asSharedFlow
import javax.inject.Inject

class EmotionRepositoryImpl @Inject constructor(
private val emotionDataSource: EmotionDataSource,
) : EmotionRepository {
override suspend fun getEmotions(): Result<List<Emotion>> {
return emotionDataSource.getEmotions().map { response ->
response.mapNotNull {
when (it.emotionMarbleType) {
"CALM" -> Emotion.CALM
"VITALITY" -> Emotion.VITALITY
"LETHARGY" -> Emotion.LETHARGY
"ANXIETY" -> Emotion.ANXIETY
"SATISFACTION" -> Emotion.SATISFACTION
"FATIGUE" -> Emotion.FATIGUE
else -> null
}
}
response.map { it.toDomain() }
}
}

override suspend fun registerEmotion(emotion: Emotion): Result<List<EmotionRecommendRoutine>> {
val selectedEmotion = when (emotion) {
Emotion.CALM -> "CALM"
Emotion.VITALITY -> "VITALITY"
Emotion.LETHARGY -> "LETHARGY"
Emotion.ANXIETY -> "ANXIETY"
Emotion.SATISFACTION -> "SATISFACTION"
Emotion.FATIGUE -> "FATIGUE"
}

return emotionDataSource.registerEmotion(selectedEmotion).map {
override suspend fun registerEmotion(emotionMarbleType: String): Result<List<EmotionRecommendRoutine>> {
return emotionDataSource.registerEmotion(emotionMarbleType).map {
it.recommendedRoutines.map {
emotionRecommendedRoutineDto ->
emotionRecommendedRoutineDto.toEmotionRecommendRoutine()
}
}.also {
if (it.isSuccess) {
_emotionChangeEventFlow.emit(EmotionChangeEvent.ChangeEmotion(emotionMarbleType))
}
}
}

override suspend fun getMyEmotionMarble(currentDate: String): Result<MyEmotion> =
emotionDataSource.getMyEmotionMarble(currentDate).map { it.toDomain() }
override suspend fun getEmotionMarble(currentDate: String): Result<Emotion?> =
emotionDataSource.getEmotionMarble(currentDate).map { it.toDomain() }

private val _emotionChangeEventFlow = MutableSharedFlow<EmotionChangeEvent>()
override suspend fun getEmotionChangeEventFlow(): Flow<EmotionChangeEvent> = _emotionChangeEventFlow.asSharedFlow()
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.threegap.bitnagil.data.emotion.service

import com.threegap.bitnagil.data.emotion.model.dto.EmotionDto
import com.threegap.bitnagil.data.emotion.model.request.RegisterEmotionRequest
import com.threegap.bitnagil.data.emotion.model.response.MyEmotionResponseDto
import com.threegap.bitnagil.data.emotion.model.response.GetEmotionResponse
import com.threegap.bitnagil.data.emotion.model.response.RegisterEmotionResponse
import com.threegap.bitnagil.network.model.BaseResponse
import retrofit2.http.Body
Expand All @@ -20,7 +20,7 @@ interface EmotionService {
): BaseResponse<RegisterEmotionResponse>

@GET("/api/v1/emotion-marbles/{searchDate}")
suspend fun getMyEmotionMarble(
suspend fun getEmotionMarble(
@Path("searchDate") date: String,
): BaseResponse<MyEmotionResponseDto>
): BaseResponse<GetEmotionResponse>
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package com.threegap.bitnagil.domain.emotion.model

enum class Emotion {
CALM,
VITALITY,
LETHARGY,
ANXIETY,
SATISFACTION,
FATIGUE,
}
data class Emotion(
val emotionType: String,
val emotionMarbleName: String,
val imageUrl: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.threegap.bitnagil.domain.emotion.model

sealed interface EmotionChangeEvent {
data class ChangeEmotion(val emotionType: String) : EmotionChangeEvent
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.threegap.bitnagil.domain.emotion.repository

import com.threegap.bitnagil.domain.emotion.model.Emotion
import com.threegap.bitnagil.domain.emotion.model.EmotionChangeEvent
import com.threegap.bitnagil.domain.emotion.model.EmotionRecommendRoutine
import com.threegap.bitnagil.domain.emotion.model.MyEmotion
import kotlinx.coroutines.flow.Flow

interface EmotionRepository {
suspend fun getEmotions(): Result<List<Emotion>>
suspend fun registerEmotion(emotion: Emotion): Result<List<EmotionRecommendRoutine>>
suspend fun getMyEmotionMarble(currentDate: String): Result<MyEmotion>
suspend fun registerEmotion(emotionMarbleType: String): Result<List<EmotionRecommendRoutine>>
suspend fun getEmotionMarble(currentDate: String): Result<Emotion?>
suspend fun getEmotionChangeEventFlow(): Flow<EmotionChangeEvent>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.threegap.bitnagil.domain.emotion.usecase

import com.threegap.bitnagil.domain.emotion.model.EmotionChangeEvent
import com.threegap.bitnagil.domain.emotion.repository.EmotionRepository
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

class GetEmotionChangeEventFlowUseCase @Inject constructor(
private val repository: EmotionRepository,
) {
suspend operator fun invoke(): Flow<EmotionChangeEvent> = repository.getEmotionChangeEventFlow()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.threegap.bitnagil.domain.emotion.usecase

import com.threegap.bitnagil.domain.emotion.model.Emotion
import com.threegap.bitnagil.domain.emotion.repository.EmotionRepository
import javax.inject.Inject

class GetEmotionUseCase @Inject constructor(
private val emotionRepository: EmotionRepository,
) {
suspend operator fun invoke(currentDate: String): Result<Emotion?> =
emotionRepository.getEmotionMarble(currentDate)
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.threegap.bitnagil.domain.emotion.usecase

import com.threegap.bitnagil.domain.emotion.model.Emotion
import com.threegap.bitnagil.domain.emotion.model.EmotionRecommendRoutine
import com.threegap.bitnagil.domain.emotion.repository.EmotionRepository
import javax.inject.Inject

class RegisterEmotionUseCase @Inject constructor(
private val emotionRepository: EmotionRepository,
) {
suspend operator fun invoke(emotion: Emotion): Result<List<EmotionRecommendRoutine>> {
return emotionRepository.registerEmotion(emotion)
suspend operator fun invoke(emotionType: String): Result<List<EmotionRecommendRoutine>> {
return emotionRepository.registerEmotion(emotionType)
}
}
10 changes: 10 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ orbit = "6.1.0"
javax = "1"
kakaoLogin = "2.21.4"
lottie-compose = "6.6.0"
coil = "3.3.0"

[libraries]
## Android Gradle Plugin
Expand Down Expand Up @@ -115,6 +116,10 @@ androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "j
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
kotlin-coroutines-test = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-test", version.ref = "kotlinxCoroutines" }

## coil
coil-compose = { group = "io.coil-kt.coil3", name = "coil-compose", version.ref = "coil" }
coil-network = { group = "io.coil-kt.coil3", name = "coil-network-okhttp", version.ref = "coil" }

## Other
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
kakao-v2-user = { group = "com.kakao.sdk", name = "v2-user", version.ref = "kakaoLogin" }
Expand Down Expand Up @@ -171,6 +176,11 @@ orbit = [
"orbit-viewmodel"
]

coil = [
"coil-compose",
"coil-network"
]

[plugins]
android-application = { id = "com.android.application", version.ref = "androidGradlePlugin" }
android-library = { id = "com.android.library", version.ref = "androidGradlePlugin" }
Expand Down
1 change: 1 addition & 0 deletions presentation/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ dependencies {
implementation(libs.kakao.v2.user)
implementation(libs.kotlinx.serialization.json)
implementation(libs.lottie.compose)
implementation(libs.bundles.coil)

testImplementation(libs.junit)
testImplementation(libs.kotlin.coroutines.test)
Expand Down
Loading