diff --git a/core/model/src/main/java/com/easyhz/noffice/core/model/task/Task.kt b/core/model/src/main/java/com/easyhz/noffice/core/model/task/Task.kt index b7ff72f5..f1e20226 100644 --- a/core/model/src/main/java/com/easyhz/noffice/core/model/task/Task.kt +++ b/core/model/src/main/java/com/easyhz/noffice/core/model/task/Task.kt @@ -4,6 +4,7 @@ import kotlinx.serialization.Serializable @Serializable data class Task( + val id: Int, val content: String, val isDone: Boolean ) diff --git a/data/announcement/src/main/java/com/easyhz/noffice/data/announcement/di/repository/AnnouncementRepositoryModule.kt b/data/announcement/src/main/java/com/easyhz/noffice/data/announcement/di/repository/AnnouncementRepositoryModule.kt index a1bcfa8e..96e72149 100644 --- a/data/announcement/src/main/java/com/easyhz/noffice/data/announcement/di/repository/AnnouncementRepositoryModule.kt +++ b/data/announcement/src/main/java/com/easyhz/noffice/data/announcement/di/repository/AnnouncementRepositoryModule.kt @@ -11,7 +11,7 @@ import dagger.hilt.components.SingletonComponent @InstallIn(SingletonComponent::class) interface AnnouncementRepositoryModule { @Binds - fun bindPlaceRepository( + fun bindAnnouncementRepository( announceRepositoryImpl: AnnounceRepositoryImpl ): AnnounceRepository } \ No newline at end of file diff --git a/data/announcement/src/main/java/com/easyhz/noffice/data/announcement/mapper/task/TaskMapper.kt b/data/announcement/src/main/java/com/easyhz/noffice/data/announcement/mapper/task/TaskMapper.kt new file mode 100644 index 00000000..37c92420 --- /dev/null +++ b/data/announcement/src/main/java/com/easyhz/noffice/data/announcement/mapper/task/TaskMapper.kt @@ -0,0 +1,10 @@ +package com.easyhz.noffice.data.announcement.mapper.task + +import com.easyhz.noffice.core.model.task.Task +import com.easyhz.noffice.core.network.model.response.task.TaskResponse + +fun TaskResponse.toModel(): Task = Task( + id = this.id, + content = this.content, + isDone = false +) \ No newline at end of file diff --git a/data/announcement/src/main/java/com/easyhz/noffice/data/announcement/repository/announcement/AnnounceRepository.kt b/data/announcement/src/main/java/com/easyhz/noffice/data/announcement/repository/announcement/AnnounceRepository.kt index 4cc2d617..6907cc12 100644 --- a/data/announcement/src/main/java/com/easyhz/noffice/data/announcement/repository/announcement/AnnounceRepository.kt +++ b/data/announcement/src/main/java/com/easyhz/noffice/data/announcement/repository/announcement/AnnounceRepository.kt @@ -2,8 +2,10 @@ package com.easyhz.noffice.data.announcement.repository.announcement import com.easyhz.noffice.core.model.announcement.Announcement import com.easyhz.noffice.core.model.announcement.param.AnnouncementParam +import com.easyhz.noffice.core.model.task.Task interface AnnounceRepository { suspend fun createAnnouncement(param: AnnouncementParam): Result suspend fun fetchAnnouncement(announcementId: Int): Result + suspend fun fetchAnnouncementTask(announcementId: Int): Result> } \ No newline at end of file diff --git a/data/announcement/src/main/java/com/easyhz/noffice/data/announcement/repository/announcement/AnnounceRepositoryImpl.kt b/data/announcement/src/main/java/com/easyhz/noffice/data/announcement/repository/announcement/AnnounceRepositoryImpl.kt index 6d329534..7a7ba6e2 100644 --- a/data/announcement/src/main/java/com/easyhz/noffice/data/announcement/repository/announcement/AnnounceRepositoryImpl.kt +++ b/data/announcement/src/main/java/com/easyhz/noffice/data/announcement/repository/announcement/AnnounceRepositoryImpl.kt @@ -2,10 +2,12 @@ package com.easyhz.noffice.data.announcement.repository.announcement import com.easyhz.noffice.core.model.announcement.Announcement import com.easyhz.noffice.core.model.announcement.param.AnnouncementParam +import com.easyhz.noffice.core.model.task.Task import com.easyhz.noffice.core.network.api.announcement.AnnouncementService import com.easyhz.noffice.core.network.util.toResult import com.easyhz.noffice.data.announcement.mapper.announcement.toModel import com.easyhz.noffice.data.announcement.mapper.announcement.toRequest +import com.easyhz.noffice.data.announcement.mapper.task.toModel import javax.inject.Inject class AnnounceRepositoryImpl @Inject constructor( @@ -18,4 +20,9 @@ class AnnounceRepositoryImpl @Inject constructor( override suspend fun fetchAnnouncement(announcementId: Int): Result = announceService.fetchAnnouncement(announcementId).toResult().map { it.toModel() } + + override suspend fun fetchAnnouncementTask(announcementId: Int): Result> { + return announceService.fetchAnnouncementTask(announcementId).toResult() + .map { it.tasks.map { item -> item.toModel() } } + } } \ No newline at end of file diff --git a/domain/announcement/src/main/java/com/easyhz/noffice/domain/announcement/usecase/task/FetchAnnouncementTaskUseCase.kt b/domain/announcement/src/main/java/com/easyhz/noffice/domain/announcement/usecase/task/FetchAnnouncementTaskUseCase.kt new file mode 100644 index 00000000..6b955c6e --- /dev/null +++ b/domain/announcement/src/main/java/com/easyhz/noffice/domain/announcement/usecase/task/FetchAnnouncementTaskUseCase.kt @@ -0,0 +1,14 @@ +package com.easyhz.noffice.domain.announcement.usecase.task + +import com.easyhz.noffice.core.common.base.BaseUseCase +import com.easyhz.noffice.core.model.task.Task +import com.easyhz.noffice.data.announcement.repository.announcement.AnnounceRepository +import javax.inject.Inject + +class FetchAnnouncementTaskUseCase @Inject constructor( + private val announcementRepository: AnnounceRepository +): BaseUseCase>() { + override suspend fun invoke(param: Int): Result> { + return announcementRepository.fetchAnnouncementTask(param) + } +} \ No newline at end of file diff --git a/feature/announcement/src/main/java/com/easyhz/noffice/feature/announcement/component/detail/TaskListField.kt b/feature/announcement/src/main/java/com/easyhz/noffice/feature/announcement/component/detail/TaskListField.kt index e5c7d62f..930841a2 100644 --- a/feature/announcement/src/main/java/com/easyhz/noffice/feature/announcement/component/detail/TaskListField.kt +++ b/feature/announcement/src/main/java/com/easyhz/noffice/feature/announcement/component/detail/TaskListField.kt @@ -56,7 +56,7 @@ internal fun LazyListScope.taskListField( ) } } - itemsIndexed(taskList, key = { _, task -> task.content }) { index, task -> + itemsIndexed(taskList, key = { _, task -> task.id }) { index, task -> TaskItem( modifier = Modifier .background(White), diff --git a/feature/announcement/src/main/java/com/easyhz/noffice/feature/announcement/contract/detail/DetailState.kt b/feature/announcement/src/main/java/com/easyhz/noffice/feature/announcement/contract/detail/DetailState.kt index 685bbdec..52086dca 100644 --- a/feature/announcement/src/main/java/com/easyhz/noffice/feature/announcement/contract/detail/DetailState.kt +++ b/feature/announcement/src/main/java/com/easyhz/noffice/feature/announcement/contract/detail/DetailState.kt @@ -14,6 +14,7 @@ data class DetailState( val canGoBack: Boolean, val announcement: Announcement, val organizationInformation: OrganizationInformation, + val taskList: List ): UiState() { companion object { fun init() = DetailState( @@ -44,6 +45,7 @@ data class DetailState( hasStandbyMember = false, role = MemberType.MEMBER ), + taskList = emptyList() ) fun DetailState.updateDetailTitle( diff --git a/feature/announcement/src/main/java/com/easyhz/noffice/feature/announcement/screen/creation/CreationViewModel.kt b/feature/announcement/src/main/java/com/easyhz/noffice/feature/announcement/screen/creation/CreationViewModel.kt index 576f4b64..b5ab2ca2 100644 --- a/feature/announcement/src/main/java/com/easyhz/noffice/feature/announcement/screen/creation/CreationViewModel.kt +++ b/feature/announcement/src/main/java/com/easyhz/noffice/feature/announcement/screen/creation/CreationViewModel.kt @@ -86,6 +86,7 @@ class CreationViewModel @Inject constructor( profileImageUrl = "", tasks = taskListState?.map { Task( + id = -1, content = it, isDone = true ) diff --git a/feature/announcement/src/main/java/com/easyhz/noffice/feature/announcement/screen/detail/AnnouncementDetailScreen.kt b/feature/announcement/src/main/java/com/easyhz/noffice/feature/announcement/screen/detail/AnnouncementDetailScreen.kt index 865ac3cd..7f57ec70 100644 --- a/feature/announcement/src/main/java/com/easyhz/noffice/feature/announcement/screen/detail/AnnouncementDetailScreen.kt +++ b/feature/announcement/src/main/java/com/easyhz/noffice/feature/announcement/screen/detail/AnnouncementDetailScreen.kt @@ -150,7 +150,7 @@ fun AnnouncementDetailScreen( ) taskListField( - taskList = emptyList() // FIXME + taskList = uiState.taskList ) { viewModel.postIntent(DetailIntent.CheckTask(it)) } diff --git a/feature/announcement/src/main/java/com/easyhz/noffice/feature/announcement/screen/detail/AnnouncementDetailViewModel.kt b/feature/announcement/src/main/java/com/easyhz/noffice/feature/announcement/screen/detail/AnnouncementDetailViewModel.kt index 8d9c07ef..6839c596 100644 --- a/feature/announcement/src/main/java/com/easyhz/noffice/feature/announcement/screen/detail/AnnouncementDetailViewModel.kt +++ b/feature/announcement/src/main/java/com/easyhz/noffice/feature/announcement/screen/detail/AnnouncementDetailViewModel.kt @@ -5,6 +5,7 @@ import com.easyhz.noffice.core.common.base.BaseViewModel import com.easyhz.noffice.core.model.announcement.Announcement import com.easyhz.noffice.core.model.organization.OrganizationInformation import com.easyhz.noffice.domain.announcement.usecase.announcement.FetchAnnouncementUseCase +import com.easyhz.noffice.domain.announcement.usecase.task.FetchAnnouncementTaskUseCase import com.easyhz.noffice.domain.organization.usecase.organization.FetchOrganizationUseCase import com.easyhz.noffice.feature.announcement.contract.detail.DetailIntent import com.easyhz.noffice.feature.announcement.contract.detail.DetailSideEffect @@ -18,7 +19,8 @@ import javax.inject.Inject @HiltViewModel class AnnouncementDetailViewModel @Inject constructor( private val fetchOrganizationUseCase: FetchOrganizationUseCase, - private val fetchAnnouncementUseCase: FetchAnnouncementUseCase + private val fetchAnnouncementUseCase: FetchAnnouncementUseCase, + private val fetchAnnouncementTaskUseCase: FetchAnnouncementTaskUseCase, ) : BaseViewModel( initialState = DetailState.init() ) { @@ -74,11 +76,10 @@ class AnnouncementDetailViewModel @Inject constructor( private fun fetchData(organizationId: Int, id: Int) = viewModelScope.launch { val organizationDeferred = async { fetchOrganization(organizationId) } val announcementDeferred = async { fetchAnnouncement(id) } - + fetchAnnouncementTask(id) val organizationResult = organizationDeferred.await() val announcementResult = announcementDeferred.await() - // 상태 변경을 한 번에 모아서 처리 reduce { copy( organizationInformation = organizationResult.getOrNull() ?: organizationInformation, @@ -95,6 +96,12 @@ class AnnouncementDetailViewModel @Inject constructor( return fetchAnnouncementUseCase(id) } + private fun fetchAnnouncementTask(id: Int) = viewModelScope.launch { + fetchAnnouncementTaskUseCase.invoke(id).onSuccess { + reduce { copy(taskList = it) } + } + } + private fun navigateToUp() { postSideEffect { DetailSideEffect.NavigateToUp } }