Skip to content

Commit

Permalink
Merge pull request #92 from Team-Walkie/refactor/challenge_model
Browse files Browse the repository at this point in the history
챌린지 응답 모델 변경, 챌린지 완료 Api 연동
  • Loading branch information
yonghanJu authored Nov 21, 2024
2 parents 2075b99 + 7a3e8d9 commit 4b0e4e1
Show file tree
Hide file tree
Showing 14 changed files with 153 additions and 93 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/com/whyranoid/walkie/KoinModules.kt
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ import java.util.concurrent.TimeUnit
val viewModelModule =
module {
viewModel { ChallengeMainViewModel(get(), get(), get(), get(), get()) }
viewModel { ChallengeDetailViewModel(get(), get()) }
viewModel { ChallengeDetailViewModel(get(), get(), get()) }
viewModel { ChallengeExitViewModel(get(), get()) }
viewModel {
UserPageViewModel(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.whyranoid.data.API
import com.whyranoid.data.model.StatusWithMessage
import com.whyranoid.data.model.challenge.BadgeResponse
import com.whyranoid.data.model.challenge.ChallengeDetailResponse
import com.whyranoid.data.model.challenge.ChallengePreviewResponse
import com.whyranoid.data.model.challenge.ChallengeResponse
import com.whyranoid.data.model.challenge.request.ChallengeChangeStatusRequest
import com.whyranoid.data.model.challenge.request.ChallengeStartRequest
import retrofit2.Response
Expand All @@ -18,19 +18,19 @@ interface ChallengeService {
@GET(API.NEW_CHALLENGE)
suspend fun getNewChallenges(
@Query("walkieId") uid: Int,
): Response<List<ChallengePreviewResponse>>
): Response<List<ChallengeResponse>>

@GET(API.PROGRESSING_CHALLENGE)
suspend fun getMyProcessingChallenges(@Query("walkieId") uid: Int): Response<List<ChallengePreviewResponse>>
suspend fun getMyProcessingChallenges(@Query("walkieId") uid: Int): Response<List<ChallengeResponse>>

@GET(API.TOP_RANK_CHALLENGE)
suspend fun getTopRankChallenges(): Response<List<ChallengePreviewResponse>>
suspend fun getTopRankChallenges(): Response<List<ChallengeResponse>>

@GET(API.CHALLENGE_CATEGORY)
suspend fun getChallengePreviewsByType(
@Query("walkieId") uid: Int,
@Query("category") type: String
): Response<List<ChallengePreviewResponse>>
): Response<List<ChallengeResponse>>

@GET(API.CHALLENGE_DETAIL)
suspend fun getChallengeDetail(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package com.whyranoid.data.model.challenge
data class BadgeResponse(
val badgeId: Int,
val badgeName: String,
val failureImg: String? = null,
val img: String
) {
fun toBadge(): com.whyranoid.domain.model.challenge.Badge {
return com.whyranoid.domain.model.challenge.Badge(
id = badgeId.toLong(),
name = badgeName,
imageUrl = img
imageUrl = img,
failureImageUrl = failureImg
)
}
}
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
}
}
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?
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@ package com.whyranoid.data.model.challenge
import com.whyranoid.domain.model.challenge.ChallengePreview
import com.whyranoid.domain.model.challenge.ChallengeType

data class ChallengePreviewResponse(
data class ChallengeResponse(
val calorie: Int,
val category: String,
val challengeId: Int,
val distance: Int,
val endTime: String,
val goalCount: Int,
val name: String,
val newFlag: Int,
val period: Int,
val progress: Int,
val status: String
val startTime: String,
val status: String,
val timeLimit: Int
) {
fun toChallengePreview(): ChallengePreview {
return ChallengePreview(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,6 @@ data class Badge(
val id: Long,
val name: String,
val imageUrl: String,
val failureImageUrl: String? = null,
) {
companion object {
val DUMMY = Badge(
id = 0L,
name = "badgeName",
imageUrl = "https://picsum.photos/250/250",
)

val DUMMY_LIST = listOf(
Badge(
id = 0L,
name = "badgeName1",
imageUrl = "https://picsum.photos/250/250",
),
Badge(
id = 1L,
name = "badgeName2",
imageUrl = "https://picsum.photos/250/250",
),
Badge(
id = 2L,
name = "badgeName3",
imageUrl = "https://picsum.photos/250/250",
),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,26 @@ package com.whyranoid.domain.model.challenge
import com.whyranoid.domain.model.user.User

data class Challenge(
val id: Long,
val imageUrl: String,
val title: String,
val contents: String,
val period: Int? = null,
val challengeType: ChallengeType,
val accCalories: Double?,
val accCount: Int?,
val accDistance: Double?,
val accTime: String?,
val badge: Badge,
val participantCount: Int,
val participants: List<User>,
val process: Int? = null,
val calorie: Int? = null,
val distance: Int? = null,
val endTime: String,
val startTime: String,
val status: String? = null
val calorie: Int,
val challengeType: ChallengeType,
val challengeEdate: String?,
val id: Int,
val challengeSdate: String?,
val content: String,
val distance: Int?,
val endTime: String?,
val goalCount: Int?,
val imageUrl: String,
val name: String,
val period: Int?,
val progress: Int?,
val startTime: String?,
val status: String?,
val timeLimit: Int?,
val walkies: List<User>
)
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)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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


Spacer(modifier = Modifier.height(30.dp))

Expand Down Expand Up @@ -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)
)
Expand Down Expand Up @@ -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),
Expand All @@ -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"
)

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ fun ChallengeExitModalBottomSheetContainer(
Spacer(modifier = Modifier.height(16.dp))

Text(
text = "진행률 ${challenge.process}%",
text = "진행률 ${challenge.progress}%",
style = WalkieTypography.Body2.copy(
color = SystemColor.Negative,
fontWeight = FontWeight(700)
Expand Down
Loading

0 comments on commit 4b0e4e1

Please sign in to comment.