-
Notifications
You must be signed in to change notification settings - Fork 1
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
챌린지 응답 모델 변경, 챌린지 완료 Api 연동 #92
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 27 additions & 18 deletions
45
data/src/main/java/com/whyranoid/data/model/challenge/ChallengeDetailResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,38 @@ | ||
package com.whyranoid.data.model.challenge | ||
|
||
import com.whyranoid.domain.model.challenge.Challenge | ||
import com.whyranoid.domain.model.challenge.ChallengeType | ||
import com.whyranoid.domain.util.EMPTY | ||
|
||
data class ChallengeDetailResponse( | ||
val challenge: ChallengeFromServer, | ||
val walkies: List<Walkie> | ||
) { | ||
fun toChallenge(): com.whyranoid.domain.model.challenge.Challenge { | ||
val participants = walkies.map { it.toUser() } | ||
return com.whyranoid.domain.model.challenge.Challenge( | ||
badge = challenge.badge.toBadge(), | ||
calorie = challenge.calorie, | ||
challengeType = ChallengeType.getChallengeTypeByString(challenge.category), | ||
id = challenge.challengeId.toLong(), | ||
contents = challenge.content, | ||
imageUrl = challenge.img, | ||
title = challenge.name, | ||
process = challenge.progress, | ||
participants = participants, | ||
participantCount = participants.size, | ||
period = challenge.period, | ||
distance = challenge.distance, | ||
endTime = challenge.endTime, | ||
startTime = challenge.startTime, | ||
status = challenge.status | ||
fun toChallenge(): Challenge { | ||
val challenge = Challenge( | ||
challenge.accCalories, | ||
challenge.accCount, | ||
challenge.accDistance, | ||
challenge.accTime, | ||
challenge.badge.toBadge(), | ||
challenge.calorie, | ||
ChallengeType.getChallengeTypeByString(challenge.category ?: String.EMPTY), | ||
challenge.challengeEdate, | ||
challenge.challengeId, | ||
challenge.challengeSdate, | ||
challenge.content, | ||
challenge.distance, | ||
challenge.endTime, | ||
challenge.goalCount, | ||
challenge.img, | ||
challenge.name, | ||
challenge.period, | ||
challenge.progress, | ||
challenge.startTime, | ||
challenge.status, | ||
challenge.timeLimit, | ||
walkies.map { it.toUser() } | ||
) | ||
return challenge | ||
} | ||
} |
20 changes: 14 additions & 6 deletions
20
data/src/main/java/com/whyranoid/data/model/challenge/ChallengeFromServer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,25 @@ | ||
package com.whyranoid.data.model.challenge | ||
|
||
data class ChallengeFromServer( | ||
val accCalories: Double?, | ||
val accCount: Int?, | ||
val accDistance: Double?, | ||
val accTime: String? = null, | ||
val badge: BadgeResponse, | ||
val calorie: Int?, | ||
val category: String, | ||
val calorie: Int, | ||
val category: String?, | ||
val challengeEdate: String? = null, | ||
val challengeId: Int, | ||
val challengeSdate: String? = null, | ||
val content: String, | ||
val distance: Int?, | ||
val endTime: String, | ||
val endTime: String?, | ||
val goalCount: Int?, | ||
val img: String, | ||
val name: String, | ||
val period: Int?, | ||
val progress: Int, | ||
val startTime: String, | ||
val status: String | ||
val progress: Int?, | ||
val startTime: String?, | ||
val status: String?, | ||
val timeLimit: Int? | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
domain/src/main/java/com/whyranoid/domain/usecase/CompleteChallengeUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.whyranoid.domain.usecase | ||
|
||
import com.whyranoid.domain.repository.ChallengeRepository | ||
import javax.inject.Inject | ||
|
||
class CompleteChallengeUseCase @Inject constructor( | ||
private val challengeRepository: ChallengeRepository, | ||
private val getMyUidUseCase: GetMyUidUseCase | ||
) { | ||
suspend operator fun invoke(challengeId: Int): Result<Unit> { | ||
val myId = getMyUidUseCase() | ||
return challengeRepository.changeChallengeStatus(challengeId,"C", myId.getOrNull()?.toInt() ?: -1) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,7 +55,9 @@ fun ChallengeGoalContent( | |
|
||
val progressBarColor = challengeColor.progressBarColor | ||
|
||
val progress = if (challenge.process == null) 0f else requireNotNull(challenge.process) / 100f | ||
val progress = | ||
if (challenge.progress == null) 0f else requireNotNull(challenge.progress) / 100f | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 코드 로직상 문제는 없지만 중복 null 체크 인 것 같아요! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 감사합니다!! |
||
|
||
|
||
Spacer(modifier = Modifier.height(30.dp)) | ||
|
||
|
@@ -114,7 +116,7 @@ fun ChallengeGoalContent( | |
dstSize = bitMapIconSize, | ||
dstOffset = IntOffset( | ||
(barEnd - bitMapIconSize.width / 2).toInt(), | ||
- bitMapIconSize.height / 2, | ||
-bitMapIconSize.height / 2, | ||
), | ||
colorFilter = ColorFilter.tint(progressBarColor) | ||
) | ||
|
@@ -158,16 +160,19 @@ fun ChallengeGoalContent( | |
modifier = Modifier.weight(1f), | ||
// TODO : limit에 적합한 값 필요(새로운 필드) | ||
// TODO : time 포멧 변경 | ||
goal = "${challenge.startTime}~${challenge.endTime}시 사이", limit = challenge.period.toString() | ||
goal = "${challenge.startTime}~${challenge.endTime}시 사이", | ||
limit = challenge.period.toString() | ||
) | ||
} | ||
|
||
ChallengeType.CALORIE -> { | ||
ChallengeGoalItem( | ||
modifier = Modifier.weight(1f), | ||
// TODO: 정확한 형식 필요, ex) 20일 | ||
goal = "기간", limit = challenge.period.toString() | ||
) | ||
} | ||
|
||
ChallengeType.DISTANCE -> { | ||
ChallengeGoalItem( | ||
modifier = Modifier.weight(1f), | ||
|
@@ -186,7 +191,8 @@ fun ChallengeGoalContent( | |
|
||
ChallengeGoalItem( | ||
modifier = Modifier.weight(1f), | ||
goal = "칼로리", limit = if (challenge.challengeType == ChallengeType.CALORIE) "${challenge.calorie}kcal" else "0kcal" | ||
goal = "칼로리", | ||
limit = if (challenge.challengeType == ChallengeType.CALORIE) "${challenge.calorie}kcal" else "0kcal" | ||
) | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit) 다음과 같이 줄여 볼 수 있을 것 같습니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!! orEmpty 좋네요! 코틀린에서 자체적으로 있는 메서드인가요?