Skip to content
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

미션 상태 - 인원 미달, 종료 대기 대응 #73

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
Expand Up @@ -12,6 +12,7 @@ import com.goalpanzi.mission_mate.core.domain.mission.model.MissionRank
import com.goalpanzi.mission_mate.core.domain.mission.model.MissionVerification
import com.goalpanzi.mission_mate.core.domain.mission.model.MissionVerifications
import com.goalpanzi.mission_mate.core.domain.mission.repository.MissionRepository
import com.goalpanzi.mission_mate.core.network.model.request.CompleteMissionRequest
import com.goalpanzi.mission_mate.core.network.service.MissionService
import kotlinx.coroutines.flow.Flow
import okhttp3.MediaType.Companion.toMediaTypeOrNull
Expand Down Expand Up @@ -78,6 +79,12 @@ class MissionRepositoryImpl @Inject constructor(
it.toModel()
}

override suspend fun completeMission(missionId: Long): DomainResult<Unit> = handleResult {
missionService.completeMission(
CompleteMissionRequest(missionId)
)
}

override fun clearMissionData(): Flow<Unit> = missionDataSource.clearMissionData()

override fun setIsMissionJoined(data: Boolean): Flow<Unit> = missionDataSource.setIsMissionJoined(data)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.goalpanzi.mission_mate.core.data.onboarding.mapper

import com.goalpanzi.mission_mate.core.data.common.mapper.toModel
import com.goalpanzi.mission_mate.core.domain.common.model.mission.MissionStatus
import com.goalpanzi.mission_mate.core.domain.onboarding.model.CreateMissionBody
import com.goalpanzi.mission_mate.core.domain.onboarding.model.Mission
import com.goalpanzi.mission_mate.core.domain.onboarding.model.Missions
import com.goalpanzi.mission_mate.core.network.model.request.CreateMissionRequest
import com.goalpanzi.mission_mate.core.network.model.response.MissionResponse
import com.goalpanzi.mission_mate.core.network.model.response.MissionStatusResponse
import com.goalpanzi.mission_mate.core.network.model.response.MissionsResponse

fun CreateMissionBody.toRequest() : CreateMissionRequest {
Expand All @@ -23,7 +25,7 @@ fun MissionResponse.toModel() : Mission {
return Mission(
missionId = missionId,
description = description,
missionStatus = missionStatus
missionStatus = missionStatus.toModel()
)
}

Expand All @@ -36,3 +38,11 @@ fun MissionsResponse.toModel() : Missions {
}
)
}

fun MissionStatusResponse.toModel() : MissionStatus {
return try{
MissionStatus.valueOf(this.name)
}catch (e : Exception){
MissionStatus.COMPLETED
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class OnboardingRepositoryImpl @Inject constructor(
onboardingService.joinMission(JoinMissionRequest(invitationCode))
}

override suspend fun getJoinedMissions(): DomainResult<Missions> = handleResult {
onboardingService.getJoinedMissions()
override suspend fun getJoinedMissions(filter : String): DomainResult<Missions> = handleResult {
onboardingService.getJoinedMissions(filter)
}.convert { it.toModel() }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.goalpanzi.mission_mate.core.domain.common.model.mission

enum class MissionStatus {
CREATED,
CANCELED,
IN_PROGRESS,
DELETED,
PENDING_COMPLETION,
COMPLETED;

companion object {
val statusString: String = listOf(CREATED, CANCELED, IN_PROGRESS, PENDING_COMPLETION)
.joinToString(",") { it.name }
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ interface MissionRepository {

suspend fun getMyMissionVerification(missionId: Long, number : Int) : DomainResult<MissionVerification>

suspend fun completeMission(missionId : Long) : DomainResult<Unit>

fun clearMissionData() : Flow<Unit>
fun setIsMissionJoined(data: Boolean) : Flow<Unit>
fun getIsMissionJoined() : Flow<Boolean?>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.goalpanzi.mission_mate.core.domain.mission.usecase

import com.goalpanzi.mission_mate.core.domain.common.DomainResult
import com.goalpanzi.mission_mate.core.domain.mission.repository.MissionRepository
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import javax.inject.Inject

class CompleteMissionUseCase @Inject constructor(
private val missionRepository: MissionRepository
) {
operator fun invoke(missionId: Long) : Flow<DomainResult<Unit>> = flow {
emit(missionRepository.completeMission(missionId))
}
}

Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.goalpanzi.mission_mate.core.domain.onboarding.model

import com.goalpanzi.mission_mate.core.domain.common.model.mission.MissionStatus

data class Mission(
val missionId : Long,
val description : String,
val missionStatus : String
val missionStatus : MissionStatus
)
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ interface OnboardingRepository {
invitationCode: String
) : DomainResult<Unit>

suspend fun getJoinedMissions() : DomainResult<Missions>
suspend fun getJoinedMissions(filter : String) : DomainResult<Missions>
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import javax.inject.Inject
class GetJoinedMissionsUseCase @Inject constructor(
private val onboardingRepository: OnboardingRepository
) {
operator fun invoke(): Flow<DomainResult<Missions>> = flow {
emit(onboardingRepository.getJoinedMissions())
operator fun invoke(filter : String): Flow<DomainResult<Missions>> = flow {
emit(onboardingRepository.getJoinedMissions(filter))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.goalpanzi.mission_mate.core.network.model.request

import kotlinx.serialization.Serializable

@Serializable
data class CompleteMissionRequest(
val missionId : Long
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ import kotlinx.serialization.Serializable
data class MissionResponse(
val missionId : Long,
val description : String,
val missionStatus : String
val missionStatus : MissionStatusResponse
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.goalpanzi.mission_mate.core.network.model.response

enum class MissionStatusResponse {
CREATED,
CANCELED,
IN_PROGRESS,
DELETED,
PENDING_COMPLETION,
COMPLETED
}
Comment on lines +3 to +10
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enum을 리스폰스로 받거나 리퀘스트로 json 파싱해서 넘겨줄 때 SerializedName 쓰거나 JsonAdapter 사용하는 방식도 있는데, 우리가 kotlin-serialize 사용하고 있어서 그 방법으로는 못하는거야?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

못한다기보다는 안 써도 되는 형태라고 봐야하지 않을까 싶어! https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/builtin-classes.md#enum-classes
보면 enum class name이랑 동일한 경우 그대로 사용해도 되고 다른 경우에는 @SerialName 를 통해 지정을 해도 되는 형태인 것 같아.
필드값으로 들어가는 enum class 에 대해서는 @serializable annotation을 안 써도 되는지에 대해서 확실하게 몰랐는데 공식 가이드에서 안 써도 된다고 적혀있네!

Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.goalpanzi.mission_mate.core.network.service

import com.goalpanzi.mission_mate.core.network.model.request.CompleteMissionRequest
import com.goalpanzi.mission_mate.core.network.model.response.MissionBoardsResponse
import com.goalpanzi.mission_mate.core.network.model.response.MissionDetailResponse
import com.goalpanzi.mission_mate.core.network.model.response.MissionRankResponse
import com.goalpanzi.mission_mate.core.network.model.response.MissionVerificationResponse
import com.goalpanzi.mission_mate.core.network.model.response.MissionVerificationsResponse
import okhttp3.MultipartBody
import retrofit2.Response
import retrofit2.http.Body
import retrofit2.http.DELETE
import retrofit2.http.GET
import retrofit2.http.Multipart
Expand Down Expand Up @@ -54,4 +56,9 @@ interface MissionService {
@Path("missionId") missionId: Long,
@Path("number") number: Int
) : Response<MissionVerificationResponse>

@POST("/api/mission-members/complete")
suspend fun completeMission(
@Body request: CompleteMissionRequest
): Response<Unit>
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ fun NavGraphBuilder.boardFinishNavGraph(
arguments = listOf(navArgument(missionIdArg) { type = NavType.LongType })
) {
BoardFinishRoute(
onClickSetting = onClickSetting,
onClickOk = onClickOk
onSettingClick = onClickSetting,
onOkClick = onClickOk
)
}
}
Expand Down
Loading
Loading