Skip to content

Commit 7de8c13

Browse files
authored
Merge pull request #81 from YAPP-Github/fix/#73-motion
[Fix/#73] 감정 구슬 관련 기능 수정
2 parents 7656c49 + e615480 commit 7de8c13

File tree

24 files changed

+248
-203
lines changed

24 files changed

+248
-203
lines changed
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+
}
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: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,39 @@ package com.threegap.bitnagil.data.emotion.repositoryImpl
33
import com.threegap.bitnagil.data.emotion.datasource.EmotionDataSource
44
import com.threegap.bitnagil.data.emotion.model.response.toDomain
55
import com.threegap.bitnagil.domain.emotion.model.Emotion
6+
import com.threegap.bitnagil.domain.emotion.model.EmotionChangeEvent
67
import com.threegap.bitnagil.domain.emotion.model.EmotionRecommendRoutine
7-
import com.threegap.bitnagil.domain.emotion.model.MyEmotion
88
import com.threegap.bitnagil.domain.emotion.repository.EmotionRepository
9+
import kotlinx.coroutines.flow.Flow
10+
import kotlinx.coroutines.flow.MutableSharedFlow
11+
import kotlinx.coroutines.flow.asSharedFlow
912
import javax.inject.Inject
1013

1114
class EmotionRepositoryImpl @Inject constructor(
1215
private val emotionDataSource: EmotionDataSource,
1316
) : EmotionRepository {
1417
override suspend fun getEmotions(): Result<List<Emotion>> {
1518
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-
}
19+
response.map { it.toDomain() }
2720
}
2821
}
2922

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 {
23+
override suspend fun registerEmotion(emotionMarbleType: String): Result<List<EmotionRecommendRoutine>> {
24+
return emotionDataSource.registerEmotion(emotionMarbleType).map {
4125
it.recommendedRoutines.map {
4226
emotionRecommendedRoutineDto ->
4327
emotionRecommendedRoutineDto.toEmotionRecommendRoutine()
4428
}
29+
}.also {
30+
if (it.isSuccess) {
31+
_emotionChangeEventFlow.emit(EmotionChangeEvent.ChangeEmotion(emotionMarbleType))
32+
}
4533
}
4634
}
4735

48-
override suspend fun getMyEmotionMarble(currentDate: String): Result<MyEmotion> =
49-
emotionDataSource.getMyEmotionMarble(currentDate).map { it.toDomain() }
36+
override suspend fun getEmotionMarble(currentDate: String): Result<Emotion?> =
37+
emotionDataSource.getEmotionMarble(currentDate).map { it.toDomain() }
38+
39+
private val _emotionChangeEventFlow = MutableSharedFlow<EmotionChangeEvent>()
40+
override suspend fun getEmotionChangeEventFlow(): Flow<EmotionChangeEvent> = _emotionChangeEventFlow.asSharedFlow()
5041
}

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+
)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.threegap.bitnagil.domain.emotion.model
2+
3+
sealed interface EmotionChangeEvent {
4+
data class ChangeEmotion(val emotionType: String) : EmotionChangeEvent
5+
}

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

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

33
import com.threegap.bitnagil.domain.emotion.model.Emotion
4+
import com.threegap.bitnagil.domain.emotion.model.EmotionChangeEvent
45
import com.threegap.bitnagil.domain.emotion.model.EmotionRecommendRoutine
5-
import com.threegap.bitnagil.domain.emotion.model.MyEmotion
6+
import kotlinx.coroutines.flow.Flow
67

78
interface EmotionRepository {
89
suspend fun getEmotions(): Result<List<Emotion>>
9-
suspend fun registerEmotion(emotion: Emotion): Result<List<EmotionRecommendRoutine>>
10-
suspend fun getMyEmotionMarble(currentDate: String): Result<MyEmotion>
10+
suspend fun registerEmotion(emotionMarbleType: String): Result<List<EmotionRecommendRoutine>>
11+
suspend fun getEmotionMarble(currentDate: String): Result<Emotion?>
12+
suspend fun getEmotionChangeEventFlow(): Flow<EmotionChangeEvent>
1113
}

0 commit comments

Comments
 (0)