Skip to content

Commit

Permalink
Merge pull request #116 from Team-Notitime/feat/home/64-task-api
Browse files Browse the repository at this point in the history
Feat/home/64 task api
  • Loading branch information
easyhz authored Aug 21, 2024
2 parents 54d2606 + 3b6dadb commit 1634f92
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import kotlinx.serialization.Serializable

@Serializable
data class Task(
val id: Int,
val content: String,
val isDone: Boolean
)
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import dagger.hilt.components.SingletonComponent
@InstallIn(SingletonComponent::class)
interface AnnouncementRepositoryModule {
@Binds
fun bindPlaceRepository(
fun bindAnnouncementRepository(
announceRepositoryImpl: AnnounceRepositoryImpl
): AnnounceRepository
}
Original file line number Diff line number Diff line change
@@ -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
)
Original file line number Diff line number Diff line change
Expand Up @@ -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<Announcement>
suspend fun fetchAnnouncement(announcementId: Int): Result<Announcement>
suspend fun fetchAnnouncementTask(announcementId: Int): Result<List<Task>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -18,4 +20,9 @@ class AnnounceRepositoryImpl @Inject constructor(

override suspend fun fetchAnnouncement(announcementId: Int): Result<Announcement> =
announceService.fetchAnnouncement(announcementId).toResult().map { it.toModel() }

override suspend fun fetchAnnouncementTask(announcementId: Int): Result<List<Task>> {
return announceService.fetchAnnouncementTask(announcementId).toResult()
.map { it.tasks.map { item -> item.toModel() } }
}
}
Original file line number Diff line number Diff line change
@@ -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<Int, List<Task>>() {
override suspend fun invoke(param: Int): Result<List<Task>> {
return announcementRepository.fetchAnnouncementTask(param)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ data class DetailState(
val canGoBack: Boolean,
val announcement: Announcement,
val organizationInformation: OrganizationInformation,
val taskList: List<Task>
): UiState() {
companion object {
fun init() = DetailState(
Expand Down Expand Up @@ -44,6 +45,7 @@ data class DetailState(
hasStandbyMember = false,
role = MemberType.MEMBER
),
taskList = emptyList()
)

fun DetailState.updateDetailTitle(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class CreationViewModel @Inject constructor(
profileImageUrl = "",
tasks = taskListState?.map {
Task(
id = -1,
content = it,
isDone = true
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ fun AnnouncementDetailScreen(
)

taskListField(
taskList = emptyList() // FIXME
taskList = uiState.taskList
) {
viewModel.postIntent(DetailIntent.CheckTask(it))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<DetailState, DetailIntent, DetailSideEffect>(
initialState = DetailState.init()
) {
Expand Down Expand Up @@ -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,
Expand All @@ -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 }
}
Expand Down

0 comments on commit 1634f92

Please sign in to comment.