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

Feature/implement onboarding api #24

Merged
merged 4 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -4,7 +4,9 @@ import com.goalpanzi.mission_mate.core.domain.repository.OnboardingRepository
import com.goalpanzi.mission_mate.core.network.service.OnboardingService
import com.luckyoct.core.model.base.NetworkResult
import com.luckyoct.core.model.request.CreateMissionRequest
import com.luckyoct.core.model.request.JoinMissionRequest
import com.luckyoct.core.model.response.MissionDetailResponse
import com.luckyoct.core.model.response.MissionsResponse
import javax.inject.Inject

class OnboardingRepositoryImpl @Inject constructor(
Expand All @@ -13,4 +15,16 @@ class OnboardingRepositoryImpl @Inject constructor(
override suspend fun createMission(missionRequest: CreateMissionRequest): NetworkResult<MissionDetailResponse> = handleResult {
onboardingService.createMission(missionRequest)
}

override suspend fun getMissionByInvitationCode(invitationCode: String): NetworkResult<MissionDetailResponse> = handleResult{
onboardingService.getMissionByInvitationCode(invitationCode)
}

override suspend fun joinMission(invitationCode: String): NetworkResult<Unit> = handleResult {
onboardingService.joinMission(JoinMissionRequest(invitationCode))
}

override suspend fun getJoinedMissions(): NetworkResult<MissionsResponse> = handleResult {
onboardingService.getJoinedMissions()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,20 @@ import com.goalpanzi.mission_mate.core.network.ResultHandler
import com.luckyoct.core.model.base.NetworkResult
import com.luckyoct.core.model.request.CreateMissionRequest
import com.luckyoct.core.model.response.MissionDetailResponse
import com.luckyoct.core.model.response.MissionsResponse

interface OnboardingRepository : ResultHandler {
suspend fun createMission(
missionRequest: CreateMissionRequest
): NetworkResult<MissionDetailResponse>

suspend fun getMissionByInvitationCode(
invitationCode : String
) : NetworkResult<MissionDetailResponse>

suspend fun joinMission(
invitationCode: String
) : NetworkResult<Unit>

suspend fun getJoinedMissions() : NetworkResult<MissionsResponse>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.goalpanzi.mission_mate.core.domain.usecase

import com.goalpanzi.mission_mate.core.domain.repository.OnboardingRepository
import com.luckyoct.core.model.base.NetworkResult
import com.luckyoct.core.model.response.MissionsResponse
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import javax.inject.Inject

class GetJoinedMissionsUseCase @Inject constructor(
private val onboardingRepository: OnboardingRepository
) {
operator fun invoke(): Flow<NetworkResult<MissionsResponse>> = flow {
emit(onboardingRepository.getJoinedMissions())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.goalpanzi.mission_mate.core.domain.usecase

import com.goalpanzi.mission_mate.core.domain.repository.OnboardingRepository
import com.luckyoct.core.model.base.NetworkResult
import com.luckyoct.core.model.response.MissionDetailResponse
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import javax.inject.Inject

class GetMissionByInvitationCodeUseCase @Inject constructor(
private val onboardingRepository: OnboardingRepository
) {
operator fun invoke(
invitationCode: String
): Flow<NetworkResult<MissionDetailResponse>> = flow {
emit(onboardingRepository.getMissionByInvitationCode(invitationCode))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.goalpanzi.mission_mate.core.domain.usecase

import com.goalpanzi.mission_mate.core.domain.repository.OnboardingRepository
import com.luckyoct.core.model.base.NetworkResult
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import javax.inject.Inject

class JoinMissionUseCase @Inject constructor(
private val onboardingRepository: OnboardingRepository
) {
operator fun invoke(
invitationCode: String
): Flow<NetworkResult<Unit>> = flow {
emit(onboardingRepository.joinMission(invitationCode))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.luckyoct.core.model.request

import kotlinx.serialization.Serializable

@Serializable
data class JoinMissionRequest(
val invitationCode : String
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package com.luckyoct.core.model.response

import kotlinx.serialization.Serializable
import java.time.DayOfWeek
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import java.time.format.TextStyle
import java.util.Locale

@Serializable
data class MissionDetailResponse(
Expand All @@ -13,4 +18,28 @@ data class MissionDetailResponse(
val missionDays : List<String>,
val boardCount : Int,
val invitationCode : String
)
){
val missionPeriod : String by lazy {
try {
val inputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss")
val outputFormatter = DateTimeFormatter.ofPattern("MM-dd")

val startDate = LocalDateTime.parse(missionStartDate, inputFormatter)
val endDate = LocalDateTime.parse(missionEndDate, inputFormatter)

"${startDate.format(outputFormatter)} ~ ${endDate.format(outputFormatter)}"
}catch (e: Exception){
"$missionStartDate ~ $missionEndDate"
}
}

val missionDaysOfWeek : List<String> by lazy {
try {
missionDays.map {
DayOfWeek.valueOf(it).getDisplayName(TextStyle.SHORT, Locale.getDefault())
}
}catch (e: Exception){
missionDays
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.luckyoct.core.model.response

import kotlinx.serialization.Serializable

@Serializable
data class MissionResponse(
val missionId : Long,
val description : String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.luckyoct.core.model.response

import kotlinx.serialization.Serializable

@Serializable
data class MissionsResponse(
val profile : ProfileResponse,
val missions : List<MissionResponse>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.luckyoct.core.model.response

import kotlinx.serialization.Serializable

@Serializable
data class ProfileResponse(
val nickname : String,
val characterType : String
)
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
package com.goalpanzi.mission_mate.core.network.service

import com.luckyoct.core.model.request.CreateMissionRequest
import com.luckyoct.core.model.request.JoinMissionRequest
import com.luckyoct.core.model.response.MissionDetailResponse
import com.luckyoct.core.model.response.MissionsResponse
import retrofit2.Response
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.Query

interface OnboardingService {
@POST("/api/missions")
suspend fun createMission(
@Body request: CreateMissionRequest
): Response<MissionDetailResponse>

@GET("/api/missions")
suspend fun getMissionByInvitationCode(
@Query("invitationCode") invitationCode : String
) : Response<MissionDetailResponse>

@POST("/api/mission-members")
suspend fun joinMission(
@Body request : JoinMissionRequest
) : Response<Unit>

@GET("/api/mission-members/me")
suspend fun getJoinedMissions() : Response<MissionsResponse>
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ internal fun MainNavHost(
onboardingNavGraph(
onClickBoardSetup = { navigator.navigationToBoardSetup() },
onClickInvitationCode = { navigator.navigationToInvitationCode() },
onClickSetting = { }
onClickSetting = { },
onNavigateMissionBoard = { missionId ->

}
)
boardSetupNavGraph(
onSuccess = {
Expand All @@ -55,6 +58,9 @@ internal fun MainNavHost(
invitationCodeNavGraph(
onBackClick = {
navigator.popBackStack()
},
onNavigateMissionBoard = { missionId ->

}
)
profileNavGraph(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ fun NavController.navigateToInvitationCode() {
fun NavGraphBuilder.onboardingNavGraph(
onClickBoardSetup: () -> Unit,
onClickInvitationCode: () -> Unit,
onClickSetting: () -> Unit
onClickSetting: () -> Unit,
onNavigateMissionBoard : (Long) -> Unit
) {
composable<RouteModel.Onboarding> {
OnboardingRoute(
onClickBoardSetup = onClickBoardSetup,
onClickInvitationCode = onClickInvitationCode,
onClickSetting = onClickSetting
onClickSetting = onClickSetting,
onNavigateMissionBoard = onNavigateMissionBoard
)
}
}
Expand Down Expand Up @@ -63,11 +65,13 @@ fun NavGraphBuilder.boardSetupSuccessNavGraph(
}

fun NavGraphBuilder.invitationCodeNavGraph(
onBackClick: () -> Unit
onBackClick: () -> Unit,
onNavigateMissionBoard: (Long) -> Unit,
) {
composable<OnboardingRouteModel.InvitationCode> {
InvitationCodeRoute(
onBackClick = onBackClick
onBackClick = onBackClick,
onNavigateMissionBoard = onNavigateMissionBoard
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.goalpanzi.mission_mate.feature.onboarding.model

sealed class JoinResultEvent {
data class Success(val missionId : Long) : JoinResultEvent()
data object Error : JoinResultEvent()
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
package com.goalpanzi.mission_mate.feature.onboarding.model

import com.luckyoct.core.model.response.MissionDetailResponse

data class MissionUiModel(
val missionId : Long,
val missionTitle : String,
val missionPeriod : String,
val missionDays : String,
val missionTime : String
val missionDays : List<String>,
val missionTime : VerificationTimeType,
val missionBoardCount : Int
)

fun MissionDetailResponse.toMissionUiModel() =
MissionUiModel(
missionId = missionId,
missionTitle = description,
missionPeriod = missionPeriod,
missionDays = missionDaysOfWeek,
missionTime = VerificationTimeType.valueOf(timeOfDay),
missionBoardCount = boardCount
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.goalpanzi.mission_mate.feature.onboarding.model

import com.luckyoct.core.model.response.MissionResponse

sealed class OnboardingResultEvent {
data class SuccessWithJoinedMissions(val mission : MissionResponse) : OnboardingResultEvent()
data object Error : OnboardingResultEvent()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.goalpanzi.mission_mate.feature.onboarding.model

import com.luckyoct.core.model.response.ProfileResponse

sealed class OnboardingUiModel {
data object Loading : OnboardingUiModel()
data class Success(val profileResponse: ProfileResponse) : OnboardingUiModel()
}
Loading
Loading