Skip to content

Commit

Permalink
체크리스트 상세 api 연결
Browse files Browse the repository at this point in the history
  • Loading branch information
leesa-l committed Dec 15, 2023
1 parent 3e6bffe commit 3a030c4
Show file tree
Hide file tree
Showing 16 changed files with 334 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ internal object PlanUseCaseModule {
deviceIdProvider: DeviceIdProvider
) = GetMyChecklistUseCase(
coroutineDispatcherProvider,
planRepository,
deviceIdProvider
planRepository
)

@Provides
Expand All @@ -96,8 +95,7 @@ internal object PlanUseCaseModule {
deviceIdProvider: DeviceIdProvider
) = GetMyTemplateListUseCase(
coroutineDispatcherProvider,
planRepository,
deviceIdProvider
planRepository
)

@Provides
Expand All @@ -116,8 +114,7 @@ internal object PlanUseCaseModule {
deviceIdProvider: DeviceIdProvider
) = GetChecklistUseCase(
coroutineDispatcherProvider,
planRepository,
deviceIdProvider
planRepository
)

@Provides
Expand All @@ -127,8 +124,7 @@ internal object PlanUseCaseModule {
deviceIdProvider: DeviceIdProvider
) = GetTemplateUseCase(
coroutineDispatcherProvider,
planRepository,
deviceIdProvider
planRepository
)

@Provides
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.dkin.chevit.data.model.request

import com.dkin.chevit.data.DataModel
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
internal data class CheckItemCheckedPayload(
@SerialName("isCheck") val checked: Boolean,
) : DataModel
6 changes: 3 additions & 3 deletions data/src/main/java/com/dkin/chevit/data/remote/PlanAPI.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.dkin.chevit.data.remote

import com.dkin.chevit.data.model.request.CategoryPayload
import com.dkin.chevit.data.model.request.CheckItemCheckedPayload
import com.dkin.chevit.data.model.request.CheckItemPayload
import com.dkin.chevit.data.model.request.NewSchedulePayload
import com.dkin.chevit.data.model.request.NewTemplatePayload
Expand All @@ -11,6 +12,7 @@ import com.dkin.chevit.data.model.response.LocaleResponse
import com.dkin.chevit.data.model.response.NewsResponse
import com.dkin.chevit.data.model.response.PlanResponse
import com.dkin.chevit.data.model.response.WeatherListResponse
import com.dkin.chevit.domain.base.None
import retrofit2.http.Body
import retrofit2.http.DELETE
import retrofit2.http.Field
Expand Down Expand Up @@ -60,7 +62,6 @@ internal interface PlanAPI {
*/
@GET("fetchMyPlanList")
suspend fun fetchMyPlanList(
@Query("Device-Id") deviceId: String,
@Query("typ") typ: String
): List<PlanResponse>

Expand All @@ -86,7 +87,6 @@ internal interface PlanAPI {
@GET("plan/{planId}")
suspend fun fetchPlan(
@Path("planId") planId: String,
@Query("Device-Id") deviceId: String,
@Query("typ") typ: String
): PlanResponse

Expand Down Expand Up @@ -184,6 +184,6 @@ internal interface PlanAPI {
suspend fun checkCheckItem(
@Path("planId") planId: String,
@Path("checkItemId") checkItemId: String,
@Field("isCheck") checked: Boolean
@Body body: CheckItemCheckedPayload
): CheckItemResponse
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.dkin.chevit.data.model.mapper.TravelWithMapper
import com.dkin.chevit.data.model.mapper.WeatherListMapper
import com.dkin.chevit.data.model.mapper.mapDomainList
import com.dkin.chevit.data.model.request.CategoryPayload
import com.dkin.chevit.data.model.request.CheckItemCheckedPayload
import com.dkin.chevit.data.model.request.CheckItemPayload
import com.dkin.chevit.data.model.request.NewSchedulePayload
import com.dkin.chevit.data.model.request.NewTemplatePayload
Expand Down Expand Up @@ -75,8 +76,8 @@ internal class PlanRepositoryImpl @Inject constructor(
return planAPI.newTemplate(payload).let(PlanMapper::mapDomain)
}

override suspend fun fetchMyPlanList(deviceId: String, typ: PlanType): DomainListModel<Plan> {
return planAPI.fetchMyPlanList(deviceId, typ.name).mapDomainList(PlanMapper::mapDomain)
override suspend fun fetchMyPlanList(typ: PlanType): DomainListModel<Plan> {
return planAPI.fetchMyPlanList(typ.name).mapDomainList(PlanMapper::mapDomain)
}

override suspend fun updateTemplate(planId: String, subject: String, color: ColorType): Plan {
Expand All @@ -92,8 +93,8 @@ internal class PlanRepositoryImpl @Inject constructor(
return None
}

override suspend fun fetchPlan(planId: String, deviceId: String, typ: PlanType): Plan {
return planAPI.fetchPlan(planId, deviceId, typ.name).let(PlanMapper::mapDomain)
override suspend fun fetchPlan(planId: String, typ: PlanType): Plan {
return planAPI.fetchPlan(planId, typ.name).let(PlanMapper::mapDomain)
}

override suspend fun copyTemplate(planId: String, refPlanId: String?): Plan {
Expand Down Expand Up @@ -182,6 +183,7 @@ internal class PlanRepositoryImpl @Inject constructor(
checkItemId: String,
checked: Boolean
): CheckItem {
return planAPI.checkCheckItem(planId, checkItemId, checked).let(CheckItemMapper::mapDomain)
val payload = CheckItemCheckedPayload(checked)
return planAPI.checkCheckItem(planId, checkItemId, payload).let(CheckItemMapper::mapDomain)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ interface PlanRepository {

suspend fun newTemplate(subject: String, color: ColorType, refPlanId: String?): Plan

suspend fun fetchMyPlanList(deviceId: String, typ: PlanType): DomainListModel<Plan>
suspend fun fetchMyPlanList(typ: PlanType): DomainListModel<Plan>

suspend fun updateTemplate(planId: String, subject: String, color: ColorType): Plan

suspend fun deletePlan(planId: String): None

suspend fun fetchPlan(planId: String, deviceId: String, typ: PlanType): Plan
suspend fun fetchPlan(planId: String, typ: PlanType): Plan

suspend fun copyTemplate(planId: String, refPlanId: String?): Plan

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@ import com.dkin.chevit.domain.base.CoroutineDispatcherProvider
import com.dkin.chevit.domain.base.IOUseCase
import com.dkin.chevit.domain.model.Plan
import com.dkin.chevit.domain.model.PlanType
import com.dkin.chevit.domain.provider.DeviceIdProvider
import com.dkin.chevit.domain.repository.PlanRepository

class GetChecklistUseCase(
coroutineDispatcherProvider: CoroutineDispatcherProvider,
private val planRepository: PlanRepository,
private val deviceIdProvider: DeviceIdProvider,
) : IOUseCase<GetChecklistUseCase.Param, Plan>(coroutineDispatcherProvider) {
override suspend fun execute(params: Param): Plan {
return planRepository.fetchPlan(
params.planId, deviceId = deviceIdProvider.getDeviceId(),
params.planId,
typ = PlanType.SCHEDULE,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@ import com.dkin.chevit.domain.base.DomainListModel
import com.dkin.chevit.domain.base.IOUseCase
import com.dkin.chevit.domain.model.Plan
import com.dkin.chevit.domain.model.PlanType
import com.dkin.chevit.domain.provider.DeviceIdProvider
import com.dkin.chevit.domain.repository.PlanRepository

class GetMyChecklistUseCase(
coroutineDispatcherProvider: CoroutineDispatcherProvider,
private val planRepository: PlanRepository,
private val deviceIdProvider: DeviceIdProvider,
) : IOUseCase<Unit, DomainListModel<Plan>>(coroutineDispatcherProvider) {
override suspend fun execute(params: Unit): DomainListModel<Plan> {
return planRepository.fetchMyPlanList(
deviceId = deviceIdProvider.getDeviceId(),
typ = PlanType.SCHEDULE,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@ import com.dkin.chevit.domain.base.DomainListModel
import com.dkin.chevit.domain.base.IOUseCase
import com.dkin.chevit.domain.model.Plan
import com.dkin.chevit.domain.model.PlanType
import com.dkin.chevit.domain.provider.DeviceIdProvider
import com.dkin.chevit.domain.repository.PlanRepository

class GetMyTemplateListUseCase(
coroutineDispatcherProvider: CoroutineDispatcherProvider,
private val planRepository: PlanRepository,
private val deviceIdProvider: DeviceIdProvider,
) : IOUseCase<Unit, DomainListModel<Plan>>(coroutineDispatcherProvider) {
override suspend fun execute(params: Unit): DomainListModel<Plan> {
return planRepository.fetchMyPlanList(
deviceId = deviceIdProvider.getDeviceId(),
typ = PlanType.TEMPLATE,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@ import com.dkin.chevit.domain.base.CoroutineDispatcherProvider
import com.dkin.chevit.domain.base.IOUseCase
import com.dkin.chevit.domain.model.Plan
import com.dkin.chevit.domain.model.PlanType
import com.dkin.chevit.domain.provider.DeviceIdProvider
import com.dkin.chevit.domain.repository.PlanRepository

class GetTemplateUseCase(
coroutineDispatcherProvider: CoroutineDispatcherProvider,
private val planRepository: PlanRepository,
private val deviceIdProvider: DeviceIdProvider,
) : IOUseCase<GetTemplateUseCase.Param, Plan>(coroutineDispatcherProvider) {
override suspend fun execute(params: Param): Plan {
return planRepository.fetchPlan(
params.planId, deviceId = deviceIdProvider.getDeviceId(),
params.planId,
typ = PlanType.SCHEDULE,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,10 @@ fun AddItemScreen(
.fillMaxWidth()
.height(54.dp),
enabled = isValidInput,
onClick = { viewModel.addItem(title = title, memo = memo, count = count) }
onClick = {
viewModel.dispatch(ChecklistDetailIntent.AddCheckItem(content = title, memo = memo, quantity = count))
onClickBack()
}
) {
Text(text = "추가하기")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.platform.ComposeView
Expand All @@ -27,7 +28,29 @@ class ChecklistDetail :
MVIComposeFragment<ChecklistDetailIntent, ChecklistDetailState, ChecklistDetailEffect>() {
override val viewModel: ChecklistDetailViewModel by viewModels()

override fun processEffect(effect: ChecklistDetailEffect) {}
override fun processEffect(effect: ChecklistDetailEffect) {
when (effect) {
ChecklistDetailEffect.GetChecklistFailed -> {
Toast.makeText(requireContext(), "체크리스트 가져오기에 실패하였습니다.", Toast.LENGTH_SHORT).show()
}

ChecklistDetailEffect.AddItemFailed -> {
Toast.makeText(requireContext(), "아이템 추가에 실패하였습니다.", Toast.LENGTH_SHORT).show()
}

ChecklistDetailEffect.CheckItemFailed -> {
Toast.makeText(requireContext(), "아이템 체크에 실패하였습니다.", Toast.LENGTH_SHORT).show()
}

ChecklistDetailEffect.DeleteItemFailed -> {
Toast.makeText(requireContext(), "아이템 삭제에 실패하였습니다.", Toast.LENGTH_SHORT).show()
}

ChecklistDetailEffect.EditItemFailed -> {
Toast.makeText(requireContext(), "아이템 업데이트에 실패하였습니다.", Toast.LENGTH_SHORT).show()
}
}
}

override fun processState(state: ChecklistDetailState) {}

Expand Down Expand Up @@ -74,7 +97,10 @@ class ChecklistDetail :
EditItemScreen(
viewModel = viewModel,
onClickBack = { navController.popBackStack() },
itemId = itemId, savedTitle = title, savedMemo = memo, savedCount = count
itemId = itemId,
savedTitle = title,
savedMemo = memo,
savedCount = count
)
}
dialog(
Expand All @@ -84,7 +110,14 @@ class ChecklistDetail :
val sortType by viewModel.sortType.collectAsState()
ChecklistDetailSortContents(
selectedType = sortType,
onClickType = { type -> viewModel.sortItem(type) },
onClickType = { type ->
viewModel.dispatch(
ChecklistDetailIntent.SortItem(
type
)
)
navController.popBackStack()
},
onClose = { navController.popBackStack() }
)
}
Expand All @@ -107,7 +140,14 @@ class ChecklistDetail :
navigateEditItem = {
navController.navigate("editItem/${itemId}?title=${title}?memo=${memo}?count=${count}")
},
deleteItem = { viewModel.removeItem(itemId) },
deleteItem = {
viewModel.dispatch(
ChecklistDetailIntent.DeleteCheckItem(
itemId
)
)
navController.popBackStack()
},
onClose = { navController.popBackStack() }
)
}
Expand Down
Loading

0 comments on commit 3a030c4

Please sign in to comment.