Skip to content

Commit 90494f7

Browse files
committed
REFACTOR: 감정 구슬 관련 데이터 형식을 서버 데이터 기반으로 통일화
1 parent 61889dc commit 90494f7

20 files changed

Lines changed: 195 additions & 204 deletions

File tree

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package com.threegap.bitnagil.data.emotion.datasource
22

33
import com.threegap.bitnagil.data.emotion.model.dto.EmotionDto
4-
import com.threegap.bitnagil.data.emotion.model.response.MyEmotionResponseDto
4+
import com.threegap.bitnagil.data.emotion.model.response.GetEmotionResponse
55
import com.threegap.bitnagil.data.emotion.model.response.RegisterEmotionResponse
66

77
interface EmotionDataSource {
88
suspend fun getEmotions(): Result<List<EmotionDto>>
99
suspend fun registerEmotion(emotion: String): Result<RegisterEmotionResponse>
10-
suspend fun getMyEmotionMarble(currentDate: String): Result<MyEmotionResponseDto>
10+
suspend fun getEmotionMarble(currentDate: String): Result<GetEmotionResponse>
1111
}

data/src/main/java/com/threegap/bitnagil/data/emotion/datasourceImpl/EmotionDataSourceImpl.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import com.threegap.bitnagil.data.common.safeApiCall
44
import com.threegap.bitnagil.data.emotion.datasource.EmotionDataSource
55
import com.threegap.bitnagil.data.emotion.model.dto.EmotionDto
66
import com.threegap.bitnagil.data.emotion.model.request.RegisterEmotionRequest
7-
import com.threegap.bitnagil.data.emotion.model.response.MyEmotionResponseDto
7+
import com.threegap.bitnagil.data.emotion.model.response.GetEmotionResponse
88
import com.threegap.bitnagil.data.emotion.model.response.RegisterEmotionResponse
99
import com.threegap.bitnagil.data.emotion.service.EmotionService
1010
import javax.inject.Inject
@@ -25,8 +25,8 @@ class EmotionDataSourceImpl @Inject constructor(
2525
}
2626
}
2727

28-
override suspend fun getMyEmotionMarble(currentDate: String): Result<MyEmotionResponseDto> =
28+
override suspend fun getEmotionMarble(currentDate: String): Result<GetEmotionResponse> =
2929
safeApiCall {
30-
emotionService.getMyEmotionMarble(currentDate)
30+
emotionService.getEmotionMarble(currentDate)
3131
}
3232
}

data/src/main/java/com/threegap/bitnagil/data/emotion/model/dto/EmotionDto.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.threegap.bitnagil.data.emotion.model.dto
22

3+
import com.threegap.bitnagil.domain.emotion.model.Emotion
34
import kotlinx.serialization.SerialName
45
import kotlinx.serialization.Serializable
56

@@ -11,4 +12,11 @@ data class EmotionDto(
1112
val emotionMarbleName: String,
1213
@SerialName("imageUrl")
1314
val imageUrl: String,
14-
)
15+
) {
16+
fun toDomain(): Emotion =
17+
Emotion(
18+
emotionType = emotionMarbleType,
19+
emotionMarbleName = emotionMarbleName,
20+
imageUrl = imageUrl,
21+
)
22+
}

data/src/main/java/com/threegap/bitnagil/data/emotion/model/response/MyEmotionResponseDto.kt renamed to data/src/main/java/com/threegap/bitnagil/data/emotion/model/response/GetEmotionResponse.kt

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
package com.threegap.bitnagil.data.emotion.model.response
22

33
import com.threegap.bitnagil.domain.emotion.model.Emotion
4-
import com.threegap.bitnagil.domain.emotion.model.MyEmotion
54
import kotlinx.serialization.SerialName
65
import kotlinx.serialization.Serializable
76

87
@Serializable
9-
data class MyEmotionResponseDto(
8+
data class GetEmotionResponse(
109
@SerialName("emotionMarbleType")
1110
val emotionMarbleType: String?,
1211
@SerialName("emotionMarbleName")
@@ -15,9 +14,14 @@ data class MyEmotionResponseDto(
1514
val imageUrl: String?,
1615
)
1716

18-
fun MyEmotionResponseDto.toDomain(): MyEmotion =
19-
MyEmotion(
20-
emotionMarbleType = emotionMarbleType?.let { Emotion.valueOf(it) },
21-
emotionMarbleName = emotionMarbleName,
22-
imageUrl = imageUrl,
23-
)
17+
fun GetEmotionResponse.toDomain(): Emotion? {
18+
return if (emotionMarbleType != null && emotionMarbleName != null && imageUrl != null) {
19+
Emotion(
20+
emotionType = emotionMarbleType,
21+
emotionMarbleName = emotionMarbleName,
22+
imageUrl = imageUrl
23+
)
24+
} else {
25+
null
26+
}
27+
}

data/src/main/java/com/threegap/bitnagil/data/emotion/repositoryImpl/EmotionRepositoryImpl.kt

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ package com.threegap.bitnagil.data.emotion.repositoryImpl
22

33
import com.threegap.bitnagil.data.emotion.datasource.EmotionDataSource
44
import com.threegap.bitnagil.data.emotion.model.response.toDomain
5-
import com.threegap.bitnagil.domain.emotion.model.Emotion
65
import com.threegap.bitnagil.domain.emotion.model.EmotionRecommendRoutine
7-
import com.threegap.bitnagil.domain.emotion.model.MyEmotion
6+
import com.threegap.bitnagil.domain.emotion.model.Emotion
87
import com.threegap.bitnagil.domain.emotion.repository.EmotionRepository
98
import javax.inject.Inject
109

@@ -13,38 +12,19 @@ class EmotionRepositoryImpl @Inject constructor(
1312
) : EmotionRepository {
1413
override suspend fun getEmotions(): Result<List<Emotion>> {
1514
return emotionDataSource.getEmotions().map { response ->
16-
response.mapNotNull {
17-
when (it.emotionMarbleType) {
18-
"CALM" -> Emotion.CALM
19-
"VITALITY" -> Emotion.VITALITY
20-
"LETHARGY" -> Emotion.LETHARGY
21-
"ANXIETY" -> Emotion.ANXIETY
22-
"SATISFACTION" -> Emotion.SATISFACTION
23-
"FATIGUE" -> Emotion.FATIGUE
24-
else -> null
25-
}
26-
}
15+
response.map { it.toDomain() }
2716
}
2817
}
2918

30-
override suspend fun registerEmotion(emotion: Emotion): Result<List<EmotionRecommendRoutine>> {
31-
val selectedEmotion = when (emotion) {
32-
Emotion.CALM -> "CALM"
33-
Emotion.VITALITY -> "VITALITY"
34-
Emotion.LETHARGY -> "LETHARGY"
35-
Emotion.ANXIETY -> "ANXIETY"
36-
Emotion.SATISFACTION -> "SATISFACTION"
37-
Emotion.FATIGUE -> "FATIGUE"
38-
}
39-
40-
return emotionDataSource.registerEmotion(selectedEmotion).map {
19+
override suspend fun registerEmotion(emotionMarbleType: String): Result<List<EmotionRecommendRoutine>> {
20+
return emotionDataSource.registerEmotion(emotionMarbleType).map {
4121
it.recommendedRoutines.map {
4222
emotionRecommendedRoutineDto ->
4323
emotionRecommendedRoutineDto.toEmotionRecommendRoutine()
4424
}
4525
}
4626
}
4727

48-
override suspend fun getMyEmotionMarble(currentDate: String): Result<MyEmotion> =
49-
emotionDataSource.getMyEmotionMarble(currentDate).map { it.toDomain() }
28+
override suspend fun getEmotionMarble(currentDate: String): Result<Emotion?> =
29+
emotionDataSource.getEmotionMarble(currentDate).map { it.toDomain() }
5030
}

data/src/main/java/com/threegap/bitnagil/data/emotion/service/EmotionService.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package com.threegap.bitnagil.data.emotion.service
22

33
import com.threegap.bitnagil.data.emotion.model.dto.EmotionDto
44
import com.threegap.bitnagil.data.emotion.model.request.RegisterEmotionRequest
5-
import com.threegap.bitnagil.data.emotion.model.response.MyEmotionResponseDto
5+
import com.threegap.bitnagil.data.emotion.model.response.GetEmotionResponse
66
import com.threegap.bitnagil.data.emotion.model.response.RegisterEmotionResponse
77
import com.threegap.bitnagil.network.model.BaseResponse
88
import retrofit2.http.Body
@@ -20,7 +20,7 @@ interface EmotionService {
2020
): BaseResponse<RegisterEmotionResponse>
2121

2222
@GET("/api/v1/emotion-marbles/{searchDate}")
23-
suspend fun getMyEmotionMarble(
23+
suspend fun getEmotionMarble(
2424
@Path("searchDate") date: String,
25-
): BaseResponse<MyEmotionResponseDto>
25+
): BaseResponse<GetEmotionResponse>
2626
}
Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
package com.threegap.bitnagil.domain.emotion.model
22

3-
enum class Emotion {
4-
CALM,
5-
VITALITY,
6-
LETHARGY,
7-
ANXIETY,
8-
SATISFACTION,
9-
FATIGUE,
10-
}
3+
data class Emotion(
4+
val emotionType: String,
5+
val emotionMarbleName: String,
6+
val imageUrl: String,
7+
)

domain/src/main/java/com/threegap/bitnagil/domain/emotion/model/MyEmotion.kt

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
package com.threegap.bitnagil.domain.emotion.repository
22

3-
import com.threegap.bitnagil.domain.emotion.model.Emotion
43
import com.threegap.bitnagil.domain.emotion.model.EmotionRecommendRoutine
5-
import com.threegap.bitnagil.domain.emotion.model.MyEmotion
4+
import com.threegap.bitnagil.domain.emotion.model.Emotion
65

76
interface EmotionRepository {
87
suspend fun getEmotions(): Result<List<Emotion>>
9-
suspend fun registerEmotion(emotion: Emotion): Result<List<EmotionRecommendRoutine>>
10-
suspend fun getMyEmotionMarble(currentDate: String): Result<MyEmotion>
8+
suspend fun registerEmotion(emotionMarbleType: String): Result<List<EmotionRecommendRoutine>>
9+
suspend fun getEmotionMarble(currentDate: String): Result<Emotion?>
1110
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.threegap.bitnagil.domain.emotion.usecase
2+
3+
import com.threegap.bitnagil.domain.emotion.model.Emotion
4+
import com.threegap.bitnagil.domain.emotion.repository.EmotionRepository
5+
import javax.inject.Inject
6+
7+
class GetEmotionUseCase @Inject constructor(
8+
private val emotionRepository: EmotionRepository,
9+
) {
10+
suspend operator fun invoke(currentDate: String): Result<Emotion?> =
11+
emotionRepository.getEmotionMarble(currentDate)
12+
}

0 commit comments

Comments
 (0)