From b6856145df57cc7ca2f1d84b4fc6c59d1cd5e25c Mon Sep 17 00:00:00 2001 From: beom84 Date: Mon, 20 Jan 2025 02:50:37 +0900 Subject: [PATCH 01/16] =?UTF-8?q?[feat]=20#46=20=EC=98=A4=EB=8A=98=20?= =?UTF-8?q?=ED=95=A0=EC=9D=BC/=EB=B0=80=EB=A6=B0=20=EA=B3=B5=EB=B6=80=20+?= =?UTF-8?q?=20=EC=A0=95=EB=A0=AC=20API=20=EC=97=B0=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../remote/TodayOrdersRemoteDataSource.kt | 23 + .../data/dto/request/RequestTodayOrdersDto.kt | 16 + .../dto/response/ResponseTodayOrdersDto.kt | 65 ++ .../repositoryImpl/PieceRepositoryImpl.kt | 30 + .../bbangzip/data/service/PieceService.kt | 18 + .../android/bbangzip/di/RepositoryModule.kt | 6 + .../org/android/bbangzip/di/ServiceModule.kt | 8 + .../org/android/bbangzip/di/UseCaseModule.kt | 7 + .../repository/remote/PieceRepository.kt | 14 + .../domain/usecase/FetchToInfoUseCase.kt | 21 + .../presentation/ui/todo/TodoContract.kt | 2 +- .../presentation/ui/todo/TodoViewModel.kt | 565 ++++++++++-------- 12 files changed, 520 insertions(+), 255 deletions(-) create mode 100644 app/src/main/java/org/android/bbangzip/data/datasource/remote/TodayOrdersRemoteDataSource.kt create mode 100644 app/src/main/java/org/android/bbangzip/data/dto/request/RequestTodayOrdersDto.kt create mode 100644 app/src/main/java/org/android/bbangzip/data/dto/response/ResponseTodayOrdersDto.kt create mode 100644 app/src/main/java/org/android/bbangzip/data/repositoryImpl/PieceRepositoryImpl.kt create mode 100644 app/src/main/java/org/android/bbangzip/data/service/PieceService.kt create mode 100644 app/src/main/java/org/android/bbangzip/domain/repository/remote/PieceRepository.kt create mode 100644 app/src/main/java/org/android/bbangzip/domain/usecase/FetchToInfoUseCase.kt diff --git a/app/src/main/java/org/android/bbangzip/data/datasource/remote/TodayOrdersRemoteDataSource.kt b/app/src/main/java/org/android/bbangzip/data/datasource/remote/TodayOrdersRemoteDataSource.kt new file mode 100644 index 00000000..00a8ce0a --- /dev/null +++ b/app/src/main/java/org/android/bbangzip/data/datasource/remote/TodayOrdersRemoteDataSource.kt @@ -0,0 +1,23 @@ +package org.android.bbangzip.data.datasource.remote + +import org.android.bbangzip.data.dto.response.ResponseTodayOrdersDto +import org.android.bbangzip.data.service.PieceService +import org.android.bbangzip.data.util.base.BaseResponse +import javax.inject.Inject + +class TodayOrdersRemoteDataSource @Inject +constructor( + private val pieceService: PieceService, +) { + suspend fun getTodoInfo( + area: String, + year: Int, + semester: String, + sortOption: String + ): BaseResponse = pieceService.getTodoInfo( + area = area, + year = year, + semester = semester, + sortOption = sortOption + ) +} diff --git a/app/src/main/java/org/android/bbangzip/data/dto/request/RequestTodayOrdersDto.kt b/app/src/main/java/org/android/bbangzip/data/dto/request/RequestTodayOrdersDto.kt new file mode 100644 index 00000000..55cf4009 --- /dev/null +++ b/app/src/main/java/org/android/bbangzip/data/dto/request/RequestTodayOrdersDto.kt @@ -0,0 +1,16 @@ +package org.android.bbangzip.data.dto.request + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class RequestTodayOrdersDto( + @SerialName("area") + val area: String, + @SerialName("year") + val year: Int, + @SerialName("semester") + val semester: String, + @SerialName("sortOption") + val sortOption: String, +) diff --git a/app/src/main/java/org/android/bbangzip/data/dto/response/ResponseTodayOrdersDto.kt b/app/src/main/java/org/android/bbangzip/data/dto/response/ResponseTodayOrdersDto.kt new file mode 100644 index 00000000..59062694 --- /dev/null +++ b/app/src/main/java/org/android/bbangzip/data/dto/response/ResponseTodayOrdersDto.kt @@ -0,0 +1,65 @@ +package org.android.bbangzip.data.dto.response + + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +import org.android.bbangzip.domain.model.ToDoCardEntity +import org.android.bbangzip.domain.model.ToDoInfoEntity + +@Serializable +data class ResponseTodayOrdersDto( + @SerialName("completeCount") + val completeCount: Int, + @SerialName("todoPieceStoList") + val todayList: List, + @SerialName("pendingCount") + val pendingCount: Int, + @SerialName("toadyCount") + val todayCount: Int, +) { + fun toTodoInfoEntity() = + ToDoInfoEntity( + todoList = todayList.map { todoItem -> + todoItem.toTodoCardEntity() + }, + pendingCount = pendingCount, + remainingStudyCount = todayCount, + completeCount = completeCount + ) +} + + +@Serializable +data class TodoInfo( + @SerialName("deadline") + val deadline: String, + @SerialName("examName") + val examName: String, + @SerialName("finishPage") + val finishPage: Int, + @SerialName("isFinished") + val isFinished: Boolean, + @SerialName("pieceId") + val pieceId: Int, + @SerialName("remainingDays") + val remainingDays: Int, + @SerialName("startPage") + val startPage: Int, + @SerialName("studyContents") + val studyContents: String, + @SerialName("subjectName") + val subjectName: String +) { + fun toTodoCardEntity() = + ToDoCardEntity( + pieceId = pieceId, + subjectName = subjectName, + examName = examName, + studyContents = studyContents, + startPage = startPage, + finishPage = finishPage, + deadline = deadline, + remainingDays = remainingDays, + isFinished = isFinished + ) +} \ No newline at end of file diff --git a/app/src/main/java/org/android/bbangzip/data/repositoryImpl/PieceRepositoryImpl.kt b/app/src/main/java/org/android/bbangzip/data/repositoryImpl/PieceRepositoryImpl.kt new file mode 100644 index 00000000..62079d21 --- /dev/null +++ b/app/src/main/java/org/android/bbangzip/data/repositoryImpl/PieceRepositoryImpl.kt @@ -0,0 +1,30 @@ +package org.android.bbangzip.data.repositoryImpl + +import org.android.bbangzip.data.datasource.remote.TodayOrdersRemoteDataSource +import org.android.bbangzip.data.dto.request.RequestTodayOrdersDto +import org.android.bbangzip.domain.model.ToDoInfoEntity +import org.android.bbangzip.domain.repository.remote.PieceRepository +import javax.inject.Inject + +class PieceRepositoryImpl +@Inject +constructor( + private val todayOrdersRemoteDateSource: TodayOrdersRemoteDataSource, +) : PieceRepository { + override suspend fun getTodoInfo( + area: String, + year: Int, + semester: String, + sortOption: String + ): Result = + runCatching { + todayOrdersRemoteDateSource.getTodoInfo( + area = area, + year = year, + semester = semester, + sortOption = sortOption + ).data.toTodoInfoEntity() + } + +} + diff --git a/app/src/main/java/org/android/bbangzip/data/service/PieceService.kt b/app/src/main/java/org/android/bbangzip/data/service/PieceService.kt new file mode 100644 index 00000000..0fd473ee --- /dev/null +++ b/app/src/main/java/org/android/bbangzip/data/service/PieceService.kt @@ -0,0 +1,18 @@ +package org.android.bbangzip.data.service + +import org.android.bbangzip.data.dto.request.RequestTodayOrdersDto +import org.android.bbangzip.data.dto.response.ResponseTodayOrdersDto +import org.android.bbangzip.data.util.base.BaseResponse +import retrofit2.http.Body +import retrofit2.http.GET +import retrofit2.http.Query + +interface PieceService { + @GET("/api/v1/pieces/today/orders") + suspend fun getTodoInfo( + @Query("area") area: String, + @Query("year") year: Int, + @Query("semester") semester: String, + @Query("sortOption") sortOption: String + ): BaseResponse +} \ No newline at end of file diff --git a/app/src/main/java/org/android/bbangzip/di/RepositoryModule.kt b/app/src/main/java/org/android/bbangzip/di/RepositoryModule.kt index bb00e482..ab165248 100644 --- a/app/src/main/java/org/android/bbangzip/di/RepositoryModule.kt +++ b/app/src/main/java/org/android/bbangzip/di/RepositoryModule.kt @@ -5,9 +5,11 @@ import dagger.Module import dagger.hilt.InstallIn import dagger.hilt.components.SingletonComponent import org.android.bbangzip.data.repositoryImpl.DummyRepositoryImpl +import org.android.bbangzip.data.repositoryImpl.PieceRepositoryImpl import org.android.bbangzip.data.repositoryImpl.UserRepositoryImpl import org.android.bbangzip.domain.repository.local.UserRepository import org.android.bbangzip.domain.repository.remote.DummyRepository +import org.android.bbangzip.domain.repository.remote.PieceRepository import javax.inject.Singleton @Module @@ -20,4 +22,8 @@ abstract class RepositoryModule { @Binds @Singleton abstract fun bindsUserRepository(repositoryImpl: UserRepositoryImpl): UserRepository + + @Binds + @Singleton + abstract fun bindsPieceRepository(repositoryImpl: PieceRepositoryImpl): PieceRepository } diff --git a/app/src/main/java/org/android/bbangzip/di/ServiceModule.kt b/app/src/main/java/org/android/bbangzip/di/ServiceModule.kt index a2e4635d..4c03402b 100644 --- a/app/src/main/java/org/android/bbangzip/di/ServiceModule.kt +++ b/app/src/main/java/org/android/bbangzip/di/ServiceModule.kt @@ -5,6 +5,7 @@ import dagger.Provides import dagger.hilt.InstallIn import dagger.hilt.components.SingletonComponent import org.android.bbangzip.data.service.DummyService +import org.android.bbangzip.data.service.PieceService import retrofit2.Retrofit import javax.inject.Singleton @@ -17,4 +18,11 @@ object ServiceModule { @BbangZip retrofit: Retrofit, ): DummyService = retrofit.create(DummyService::class.java) + + @Provides + @Singleton + fun providePieceService( + @BbangZip retrofit: Retrofit, + ): PieceService = + retrofit.create(PieceService::class.java) } diff --git a/app/src/main/java/org/android/bbangzip/di/UseCaseModule.kt b/app/src/main/java/org/android/bbangzip/di/UseCaseModule.kt index 179067e7..208a78ec 100644 --- a/app/src/main/java/org/android/bbangzip/di/UseCaseModule.kt +++ b/app/src/main/java/org/android/bbangzip/di/UseCaseModule.kt @@ -5,7 +5,9 @@ import dagger.Provides import dagger.hilt.InstallIn import dagger.hilt.components.SingletonComponent import org.android.bbangzip.domain.repository.remote.DummyRepository +import org.android.bbangzip.domain.repository.remote.PieceRepository import org.android.bbangzip.domain.usecase.FetchDummyUseCase +import org.android.bbangzip.domain.usecase.GetToInfoUseCase import javax.inject.Singleton @Module @@ -15,4 +17,9 @@ class UseCaseModule { @Singleton fun providesDummyFetchUseCase(dummyRepository: DummyRepository): FetchDummyUseCase = FetchDummyUseCase(dummyRepository = dummyRepository) + + @Provides + @Singleton + fun providesTodoInfoFetchUseCase(pieceRepository: PieceRepository): GetToInfoUseCase = + GetToInfoUseCase(pieceRepository = pieceRepository) } diff --git a/app/src/main/java/org/android/bbangzip/domain/repository/remote/PieceRepository.kt b/app/src/main/java/org/android/bbangzip/domain/repository/remote/PieceRepository.kt new file mode 100644 index 00000000..224db2bd --- /dev/null +++ b/app/src/main/java/org/android/bbangzip/domain/repository/remote/PieceRepository.kt @@ -0,0 +1,14 @@ +package org.android.bbangzip.domain.repository.remote + +import org.android.bbangzip.data.dto.request.RequestTodayOrdersDto +import org.android.bbangzip.domain.model.ToDoInfoEntity + +interface PieceRepository { + suspend fun getTodoInfo( + area: String, + year: Int, + semester: String, + sortOption: String + ): Result +} + diff --git a/app/src/main/java/org/android/bbangzip/domain/usecase/FetchToInfoUseCase.kt b/app/src/main/java/org/android/bbangzip/domain/usecase/FetchToInfoUseCase.kt new file mode 100644 index 00000000..a25abfa9 --- /dev/null +++ b/app/src/main/java/org/android/bbangzip/domain/usecase/FetchToInfoUseCase.kt @@ -0,0 +1,21 @@ +package org.android.bbangzip.domain.usecase + +import org.android.bbangzip.domain.model.ToDoInfoEntity +import org.android.bbangzip.domain.repository.remote.PieceRepository + +class GetToInfoUseCase( + private val pieceRepository: PieceRepository +) { + suspend operator fun invoke( + area: String, + year: Int, + semester: String, + sortOption: String + ): Result = + pieceRepository.getTodoInfo( + area = area, + year = year, + semester = semester, + sortOption = sortOption + ) +} \ No newline at end of file diff --git a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoContract.kt b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoContract.kt index 7d03204a..75e17154 100644 --- a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoContract.kt +++ b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoContract.kt @@ -131,7 +131,7 @@ class TodoContract { val selectedFilterItem: ToDoFilterType = ToDoFilterType.RECENT, val selectedItemList: List = listOf(), val revertCompleteBottomSheetState: Boolean = false, - val screenType: ToDoScreenType = ToDoScreenType.EMPTY, + val screenType: ToDoScreenType = ToDoScreenType.DEFAULT, ) : BaseContract.State, Parcelable { override fun toParcelable(): Parcelable = this } diff --git a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoViewModel.kt b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoViewModel.kt index 76852b20..121a8f3b 100644 --- a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoViewModel.kt +++ b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoViewModel.kt @@ -3,321 +3,378 @@ package org.android.bbangzip.presentation.ui.todo import android.os.Parcelable import androidx.lifecycle.SavedStateHandle import dagger.hilt.android.lifecycle.HiltViewModel +import org.android.bbangzip.data.dto.request.RequestTodayOrdersDto +import org.android.bbangzip.domain.repository.remote.PieceRepository +import org.android.bbangzip.domain.usecase.GetToInfoUseCase import org.android.bbangzip.presentation.component.card.BbangZipCardState +import org.android.bbangzip.presentation.model.card.ToDoCardModel import org.android.bbangzip.presentation.type.ToDoScreenType import org.android.bbangzip.presentation.util.base.BaseViewModel +import timber.log.Timber import javax.inject.Inject @HiltViewModel class TodoViewModel - @Inject - constructor( - savedStateHandle: SavedStateHandle, - ) : BaseViewModel( - savedStateHandle = savedStateHandle, - ) { - override fun createInitialState(savedState: Parcelable?): TodoContract.TodoState { - return savedState as? TodoContract.TodoState ?: TodoContract.TodoState() - } - - init { - setEvent(TodoContract.TodoEvent.Initialize) - } - - override fun handleEvent(event: TodoContract.TodoEvent) { - when (event) { - // ToDoInfo Fetch - is TodoContract.TodoEvent.FetchToDoInfo -> - updateState( - TodoContract.TodoReduce.UpdateToDoInfo( - pendingCount = event.pendingCount, - remainingStudyCount = event.remainingStudyCount, - completeCount = event.completeCount, - todoList = event.todoList, - ), - ) +@Inject +constructor( + private val getToInfoUseCase: GetToInfoUseCase, + savedStateHandle: SavedStateHandle, +) : BaseViewModel( + savedStateHandle = savedStateHandle, +) { + override fun createInitialState(savedState: Parcelable?): TodoContract.TodoState { + return savedState as? TodoContract.TodoState ?: TodoContract.TodoState() + } - TodoContract.TodoEvent.Initialize -> launch { initDataLoad() } + init { + setEvent(TodoContract.TodoEvent.Initialize) + } - // Filter BottomSheet - is TodoContract.TodoEvent.OnFilterBottomSheetItemClicked -> { - updateState(TodoContract.TodoReduce.UpdateFilterType(selectedFilter = event.selectedFilterItem)) - updateState( - TodoContract.TodoReduce.UpdateToDoFilterBottomSheetState( - todoFilterBottomSheetState = false, - ), - ) - setSideEffect(TodoContract.TodoSideEffect.ShowSnackBar("${event.selectedFilterItem.filter}으로 정렬했어요")) - // TODO index를 이용해 서버로 FetchInfo 보내주기 다시 정렬하기 ㅋㅋ - } + override fun handleEvent(event: TodoContract.TodoEvent) { + when (event) { + // ToDoInfo Fetch + is TodoContract.TodoEvent.FetchToDoInfo -> + updateState( + TodoContract.TodoReduce.UpdateToDoInfo( + pendingCount = event.pendingCount, + remainingStudyCount = event.remainingStudyCount, + completeCount = event.completeCount, + todoList = event.todoList, + ), + ) - TodoContract.TodoEvent.OnFilterBottomSheetDismissRequest -> - updateState( - TodoContract.TodoReduce.UpdateToDoFilterBottomSheetState( - todoFilterBottomSheetState = false, - ), - ) + TodoContract.TodoEvent.Initialize -> launch { initDataLoad() } - TodoContract.TodoEvent.OnFilterIconClicked -> { - updateState( - TodoContract.TodoReduce.UpdateToDoFilterBottomSheetState( - todoFilterBottomSheetState = true, - ), - ) - } + // Filter BottomSheet + is TodoContract.TodoEvent.OnFilterBottomSheetItemClicked -> { + updateState(TodoContract.TodoReduce.UpdateFilterType(selectedFilter = event.selectedFilterItem)) + updateState( + TodoContract.TodoReduce.UpdateToDoFilterBottomSheetState( + todoFilterBottomSheetState = false, + ), + ) + setSideEffect(TodoContract.TodoSideEffect.ShowSnackBar("${event.selectedFilterItem.filter}으로 정렬했어요")) + // TODO index를 이용해 서버로 FetchInfo 보내주기 다시 정렬하기 ㅋㅋ + } - // revertComplete BottomSheet - is TodoContract.TodoEvent.OnRevertCompleteBottomSheetApproveButtonClicked -> { - updateState( - TodoContract.TodoReduce.UpdateCardState( - pieceId = event.pieceId, - cardState = BbangZipCardState.DEFAULT, - ), - ) - updateState( - TodoContract.TodoReduce.UpdateRevertCompleteBottomSheetState( - revertCompleteBottomSheetState = false, - ), - ) - updateState( - TodoContract.TodoReduce.UpdateToDoCount( - completeCount = currentUiState.completeCount - 1, - remainingStudyCount = currentUiState.remainingStudyCount + 1, - ), - ) - updateState(TodoContract.TodoReduce.ResetSelectedItemList) - setSideEffect(TodoContract.TodoSideEffect.ShowSnackBar("미완료 상태로 되돌려졌어요!")) - // TODO pieceId 사영헤사 서버로 쏘기 미완료 APT - } + TodoContract.TodoEvent.OnFilterBottomSheetDismissRequest -> + updateState( + TodoContract.TodoReduce.UpdateToDoFilterBottomSheetState( + todoFilterBottomSheetState = false, + ), + ) - TodoContract.TodoEvent.OnRevertCompleteBottomSheetDismissButtonClicked -> { - updateState( - TodoContract.TodoReduce.UpdateRevertCompleteBottomSheetState( - revertCompleteBottomSheetState = false, - ), - ) - updateState(TodoContract.TodoReduce.ResetSelectedItemList) - } + TodoContract.TodoEvent.OnFilterIconClicked -> { + updateState( + TodoContract.TodoReduce.UpdateToDoFilterBottomSheetState( + todoFilterBottomSheetState = true, + ), + ) + } - TodoContract.TodoEvent.OnRevertCompleteBottomSheetDismissRequest -> { - updateState( - TodoContract.TodoReduce.UpdateRevertCompleteBottomSheetState( - revertCompleteBottomSheetState = false, - ), - ) - updateState(TodoContract.TodoReduce.ResetSelectedItemList) - } + // revertComplete BottomSheet + is TodoContract.TodoEvent.OnRevertCompleteBottomSheetApproveButtonClicked -> { + updateState( + TodoContract.TodoReduce.UpdateCardState( + pieceId = event.pieceId, + cardState = BbangZipCardState.DEFAULT, + ), + ) + updateState( + TodoContract.TodoReduce.UpdateRevertCompleteBottomSheetState( + revertCompleteBottomSheetState = false, + ), + ) + updateState( + TodoContract.TodoReduce.UpdateToDoCount( + completeCount = currentUiState.completeCount - 1, + remainingStudyCount = currentUiState.remainingStudyCount + 1, + ), + ) + updateState(TodoContract.TodoReduce.ResetSelectedItemList) + setSideEffect(TodoContract.TodoSideEffect.ShowSnackBar("미완료 상태로 되돌려졌어요!")) + // TODO pieceId 사영헤사 서버로 쏘기 미완료 APT + } - // Delete - is TodoContract.TodoEvent.OnDeleteScreenCardClicked -> { - when (event.cardState) { - BbangZipCardState.CHECKED -> { - updateState(TodoContract.TodoReduce.UpdateSelectedItemList(pieceId = event.pieceId)) - updateState( - TodoContract.TodoReduce.UpdateCardState( - pieceId = event.pieceId, - cardState = event.cardState, - ), - ) - } + TodoContract.TodoEvent.OnRevertCompleteBottomSheetDismissButtonClicked -> { + updateState( + TodoContract.TodoReduce.UpdateRevertCompleteBottomSheetState( + revertCompleteBottomSheetState = false, + ), + ) + updateState(TodoContract.TodoReduce.ResetSelectedItemList) + } - BbangZipCardState.CHECKABLE -> { - updateState(TodoContract.TodoReduce.DeleteSelectedItemList(pieceId = event.pieceId)) - updateState( - TodoContract.TodoReduce.UpdateCardState( - pieceId = event.pieceId, - cardState = event.cardState, - ), - ) - } + TodoContract.TodoEvent.OnRevertCompleteBottomSheetDismissRequest -> { + updateState( + TodoContract.TodoReduce.UpdateRevertCompleteBottomSheetState( + revertCompleteBottomSheetState = false, + ), + ) + updateState(TodoContract.TodoReduce.ResetSelectedItemList) + } - else -> { - setSideEffect(TodoContract.TodoSideEffect.ShowSnackBar("이미 완료한 일은 삭제할 수 없어요!")) - } - } - } - // Default - is TodoContract.TodoEvent.OnDefaultScreenCardClicked -> { - if (event.cardState == BbangZipCardState.COMPLETE) { + // Delete + is TodoContract.TodoEvent.OnDeleteScreenCardClicked -> { + when (event.cardState) { + BbangZipCardState.CHECKED -> { + updateState(TodoContract.TodoReduce.UpdateSelectedItemList(pieceId = event.pieceId)) updateState( TodoContract.TodoReduce.UpdateCardState( pieceId = event.pieceId, cardState = event.cardState, ), ) + } + + BbangZipCardState.CHECKABLE -> { + updateState(TodoContract.TodoReduce.DeleteSelectedItemList(pieceId = event.pieceId)) updateState( - TodoContract.TodoReduce.UpdateToDoCount( - completeCount = currentUiState.completeCount + 1, - remainingStudyCount = currentUiState.remainingStudyCount - 1, - ), - ) - TodoContract.TodoSideEffect.ShowSnackBar("공부완료 ! 오늘의 빵굽기 성공!") - } else { - updateState( - TodoContract.TodoReduce.UpdateRevertCompleteBottomSheetState( - revertCompleteBottomSheetState = true, + TodoContract.TodoReduce.UpdateCardState( + pieceId = event.pieceId, + cardState = event.cardState, ), ) - updateState(TodoContract.TodoReduce.UpdateSelectedItemList(pieceId = event.pieceId)) } - // TODO 서버로 pieceId 이용해서 완료 API 쏘기 - } - TodoContract.TodoEvent.OnDeleteIconClicked -> { - updateState(TodoContract.TodoReduce.UpdateScreenType(screenType = ToDoScreenType.DELETE)) + else -> { + setSideEffect(TodoContract.TodoSideEffect.ShowSnackBar("이미 완료한 일은 삭제할 수 없어요!")) + } + } + } + // Default + is TodoContract.TodoEvent.OnDefaultScreenCardClicked -> { + if (event.cardState == BbangZipCardState.COMPLETE) { updateState( - TodoContract.TodoReduce.UpdateToDoListCardState( - previousCardState = BbangZipCardState.DEFAULT, - nextCardState = BbangZipCardState.CHECKABLE, + TodoContract.TodoReduce.UpdateCardState( + pieceId = event.pieceId, + cardState = event.cardState, ), ) - } - - TodoContract.TodoEvent.OnItemDeleteButtonClicked -> { - // TODO setlectedItemlist 사용해서 서버로 삭제한 card API 전송 updateState( TodoContract.TodoReduce.UpdateToDoCount( - completeCount = currentUiState.completeCount, - remainingStudyCount = currentUiState.remainingStudyCount - currentUiState.selectedItemList.size, + completeCount = currentUiState.completeCount + 1, + remainingStudyCount = currentUiState.remainingStudyCount - 1, ), ) - if (currentUiState.remainingStudyCount != 0) { - updateState(TodoContract.TodoReduce.DeleteToDoListItems) - updateState( - TodoContract.TodoReduce.UpdateToDoListCardState( - previousCardState = BbangZipCardState.CHECKABLE, - nextCardState = BbangZipCardState.DEFAULT, - ), - ) - updateState(TodoContract.TodoReduce.UpdateScreenType(screenType = ToDoScreenType.DEFAULT)) - } else { - updateState(TodoContract.TodoReduce.UpdateScreenType(screenType = ToDoScreenType.EMPTY)) - } - updateState(TodoContract.TodoReduce.ResetSelectedItemList) - setSideEffect(TodoContract.TodoSideEffect.ShowSnackBar("오늘 할 공부를 삭제했어요")) - } -// 통과 - TodoContract.TodoEvent.OnCloseIconClicked -> { + TodoContract.TodoSideEffect.ShowSnackBar("공부완료 ! 오늘의 빵굽기 성공!") + } else { updateState( - TodoContract.TodoReduce.UpdateToDoListCardState( - previousCardState = BbangZipCardState.CHECKABLE, - nextCardState = BbangZipCardState.DEFAULT, + TodoContract.TodoReduce.UpdateRevertCompleteBottomSheetState( + revertCompleteBottomSheetState = true, ), ) + updateState(TodoContract.TodoReduce.UpdateSelectedItemList(pieceId = event.pieceId)) + } + // TODO 서버로 pieceId 이용해서 완료 API 쏘기 + } + + TodoContract.TodoEvent.OnDeleteIconClicked -> { + updateState(TodoContract.TodoReduce.UpdateScreenType(screenType = ToDoScreenType.DELETE)) + updateState( + TodoContract.TodoReduce.UpdateToDoListCardState( + previousCardState = BbangZipCardState.DEFAULT, + nextCardState = BbangZipCardState.CHECKABLE, + ), + ) + } + + TodoContract.TodoEvent.OnItemDeleteButtonClicked -> { + // TODO setlectedItemlist 사용해서 서버로 삭제한 card API 전송 + updateState( + TodoContract.TodoReduce.UpdateToDoCount( + completeCount = currentUiState.completeCount, + remainingStudyCount = currentUiState.remainingStudyCount - currentUiState.selectedItemList.size, + ), + ) + if (currentUiState.remainingStudyCount != 0) { + updateState(TodoContract.TodoReduce.DeleteToDoListItems) updateState( TodoContract.TodoReduce.UpdateToDoListCardState( - previousCardState = BbangZipCardState.CHECKED, + previousCardState = BbangZipCardState.CHECKABLE, nextCardState = BbangZipCardState.DEFAULT, ), ) - updateState(TodoContract.TodoReduce.ResetSelectedItemList) updateState(TodoContract.TodoReduce.UpdateScreenType(screenType = ToDoScreenType.DEFAULT)) + } else { + updateState(TodoContract.TodoReduce.UpdateScreenType(screenType = ToDoScreenType.EMPTY)) } - - // 화면 이동 - TodoContract.TodoEvent.OnAddStudyButtonClicked -> setSideEffect(TodoContract.TodoSideEffect.NavigateToAddToDo) - TodoContract.TodoEvent.OnAddPendingStudyButtonClicked -> setSideEffect(TodoContract.TodoSideEffect.NavigateToAddPendingToDo) + updateState(TodoContract.TodoReduce.ResetSelectedItemList) + setSideEffect(TodoContract.TodoSideEffect.ShowSnackBar("오늘 할 공부를 삭제했어요")) + } +// 통과 + TodoContract.TodoEvent.OnCloseIconClicked -> { + updateState( + TodoContract.TodoReduce.UpdateToDoListCardState( + previousCardState = BbangZipCardState.CHECKABLE, + nextCardState = BbangZipCardState.DEFAULT, + ), + ) + updateState( + TodoContract.TodoReduce.UpdateToDoListCardState( + previousCardState = BbangZipCardState.CHECKED, + nextCardState = BbangZipCardState.DEFAULT, + ), + ) + updateState(TodoContract.TodoReduce.ResetSelectedItemList) + updateState(TodoContract.TodoReduce.UpdateScreenType(screenType = ToDoScreenType.DEFAULT)) } + + // 화면 이동 + TodoContract.TodoEvent.OnAddStudyButtonClicked -> setSideEffect(TodoContract.TodoSideEffect.NavigateToAddToDo) + TodoContract.TodoEvent.OnAddPendingStudyButtonClicked -> setSideEffect(TodoContract.TodoSideEffect.NavigateToAddPendingToDo) } + } - override fun reduceState( - state: TodoContract.TodoState, - reduce: TodoContract.TodoReduce, - ): TodoContract.TodoState { - return when (reduce) { - // ToDoInfo Fetch - is TodoContract.TodoReduce.UpdateToDoInfo -> - state.copy( - pendingCount = reduce.pendingCount, - completeCount = reduce.completeCount, - remainingStudyCount = reduce.remainingStudyCount, - todoList = reduce.todoList, - ) + override fun reduceState( + state: TodoContract.TodoState, + reduce: TodoContract.TodoReduce, + ): TodoContract.TodoState { + return when (reduce) { + // ToDoInfo Fetch + is TodoContract.TodoReduce.UpdateToDoInfo -> + state.copy( + pendingCount = reduce.pendingCount, + completeCount = reduce.completeCount, + remainingStudyCount = reduce.remainingStudyCount, + todoList = reduce.todoList, + ) - // List - is TodoContract.TodoReduce.UpdateCardState -> - state.copy( - todoList = - state.todoList.map { item -> - if (item.pieceId == reduce.pieceId) item.copy(cardState = reduce.cardState) else item - }, - ) + // List + is TodoContract.TodoReduce.UpdateCardState -> + state.copy( + todoList = + state.todoList.map { item -> + if (item.pieceId == reduce.pieceId) item.copy(cardState = reduce.cardState) else item + }, + ) - is TodoContract.TodoReduce.UpdateToDoListCardState -> - state.copy( - todoList = - state.todoList.map { item -> - if (item.cardState == reduce.previousCardState) { - item.copy(cardState = reduce.nextCardState) - } else { - item - } - }, - ) + is TodoContract.TodoReduce.UpdateToDoListCardState -> + state.copy( + todoList = + state.todoList.map { item -> + if (item.cardState == reduce.previousCardState) { + item.copy(cardState = reduce.nextCardState) + } else { + item + } + }, + ) - is TodoContract.TodoReduce.DeleteToDoListItems -> { - val pieceIdSet = currentUiState.selectedItemList.toSet() - state.copy( - todoList = - state.todoList.filter { item -> - item.pieceId !in pieceIdSet - }, - ) - } + is TodoContract.TodoReduce.DeleteToDoListItems -> { + val pieceIdSet = currentUiState.selectedItemList.toSet() + state.copy( + todoList = + state.todoList.filter { item -> + item.pieceId !in pieceIdSet + }, + ) + } - // Revert BottomSheet - is TodoContract.TodoReduce.UpdateRevertCompleteBottomSheetState -> - state.copy( - revertCompleteBottomSheetState = reduce.revertCompleteBottomSheetState, - ) + // Revert BottomSheet + is TodoContract.TodoReduce.UpdateRevertCompleteBottomSheetState -> + state.copy( + revertCompleteBottomSheetState = reduce.revertCompleteBottomSheetState, + ) - is TodoContract.TodoReduce.UpdateSelectedItemList -> - state.copy( - selectedItemList = state.selectedItemList.plus(reduce.pieceId), - ) + is TodoContract.TodoReduce.UpdateSelectedItemList -> + state.copy( + selectedItemList = state.selectedItemList.plus(reduce.pieceId), + ) - is TodoContract.TodoReduce.DeleteSelectedItemList -> - state.copy( - selectedItemList = state.selectedItemList.minus(reduce.pieceId), - ) + is TodoContract.TodoReduce.DeleteSelectedItemList -> + state.copy( + selectedItemList = state.selectedItemList.minus(reduce.pieceId), + ) - // Filter BottomSheet - is TodoContract.TodoReduce.UpdateToDoFilterBottomSheetState -> - state.copy( - todoFilterBottomSheetState = reduce.todoFilterBottomSheetState, - ) + // Filter BottomSheet + is TodoContract.TodoReduce.UpdateToDoFilterBottomSheetState -> + state.copy( + todoFilterBottomSheetState = reduce.todoFilterBottomSheetState, + ) - is TodoContract.TodoReduce.UpdateFilterType -> - state.copy( - selectedFilterItem = reduce.selectedFilter, - ) + is TodoContract.TodoReduce.UpdateFilterType -> + state.copy( + selectedFilterItem = reduce.selectedFilter, + ) - // ToDoCount - is TodoContract.TodoReduce.UpdateToDoCount -> { - state.copy( - completeCount = reduce.completeCount, - remainingStudyCount = reduce.remainingStudyCount, - ) - } + // ToDoCount + is TodoContract.TodoReduce.UpdateToDoCount -> { + state.copy( + completeCount = reduce.completeCount, + remainingStudyCount = reduce.remainingStudyCount, + ) + } - is TodoContract.TodoReduce.UpdatePendingToDoCount -> - state.copy( - pendingCount = reduce.pendingCount, - ) + is TodoContract.TodoReduce.UpdatePendingToDoCount -> + state.copy( + pendingCount = reduce.pendingCount, + ) - // ScreenType - is TodoContract.TodoReduce.UpdateScreenType -> - state.copy( - screenType = reduce.screenType, - ) + // ScreenType + is TodoContract.TodoReduce.UpdateScreenType -> + state.copy( + screenType = reduce.screenType, + ) - TodoContract.TodoReduce.ResetSelectedItemList -> - state.copy( - selectedItemList = listOf(), + TodoContract.TodoReduce.ResetSelectedItemList -> + state.copy( + selectedItemList = listOf(), + ) + } + } + + private suspend fun initDataLoad() { + getToDoInfo( + area = "todo", + year = 2025, + semester = "1", + sortOption = "recent" + ) + } + + private suspend fun getToDoInfo( + area: String, + year: Int, + semester: String, + sortOption: String + ) { + getToInfoUseCase( + area = area, + year = year, + semester = semester, + sortOption = sortOption + ) + .onSuccess { data -> + Timber.tag("ㅋㅋ").d("server viewmodel") + updateState( + TodoContract.TodoReduce.UpdateToDoInfo( + todoList = data.todoList.map { item -> + ToDoCardModel( + pieceId = item.pieceId, + subjectName = item.subjectName, + examName = item.examName, + studyContents = item.studyContents, + startPage = item.startPage, + finishPage = item.finishPage, + deadline = item.deadline, + remainingDays = item.remainingDays, + cardState = if (item.isFinished) BbangZipCardState.COMPLETE else BbangZipCardState.DEFAULT + ) + }, + pendingCount = data.pendingCount, + remainingStudyCount = data.remainingStudyCount, + completeCount = data.completeCount ) + ) + } + .onFailure { message -> + Timber.run { + tag("ㅋㅋ").d("server viewmodel fail") + tag("ㅋㅋ").d(message.message) + } + } - } - private fun initDataLoad() { - } } +} From 66c373d226a1ba76b12d22b36ee2f436e1e1af3f Mon Sep 17 00:00:00 2001 From: beom84 Date: Mon, 20 Jan 2025 02:58:13 +0900 Subject: [PATCH 02/16] =?UTF-8?q?[feat]=20#46=20=EC=98=A4=EB=8A=98=20?= =?UTF-8?q?=ED=95=A0=EC=9D=BC/=EB=B0=80=EB=A6=B0=20=EA=B3=B5=EB=B6=80=20+?= =?UTF-8?q?=20=EC=A0=95=EB=A0=AC=20API=20=EC=97=B0=EB=8F=99=20=EC=84=B1?= =?UTF-8?q?=EA=B3=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/dto/request/RequestTodayOrdersDto.kt | 16 ---------------- .../data/dto/response/ResponseTodayOrdersDto.kt | 2 +- .../data/repositoryImpl/PieceRepositoryImpl.kt | 1 - .../bbangzip/data/service/PieceService.kt | 1 - .../bbangzip/data/util/base/BaseResponse.kt | 3 +-- .../domain/repository/remote/PieceRepository.kt | 1 - .../presentation/ui/todo/TodoContract.kt | 2 ++ .../presentation/ui/todo/TodoViewModel.kt | 6 ++++-- 8 files changed, 8 insertions(+), 24 deletions(-) delete mode 100644 app/src/main/java/org/android/bbangzip/data/dto/request/RequestTodayOrdersDto.kt diff --git a/app/src/main/java/org/android/bbangzip/data/dto/request/RequestTodayOrdersDto.kt b/app/src/main/java/org/android/bbangzip/data/dto/request/RequestTodayOrdersDto.kt deleted file mode 100644 index 55cf4009..00000000 --- a/app/src/main/java/org/android/bbangzip/data/dto/request/RequestTodayOrdersDto.kt +++ /dev/null @@ -1,16 +0,0 @@ -package org.android.bbangzip.data.dto.request - -import kotlinx.serialization.SerialName -import kotlinx.serialization.Serializable - -@Serializable -data class RequestTodayOrdersDto( - @SerialName("area") - val area: String, - @SerialName("year") - val year: Int, - @SerialName("semester") - val semester: String, - @SerialName("sortOption") - val sortOption: String, -) diff --git a/app/src/main/java/org/android/bbangzip/data/dto/response/ResponseTodayOrdersDto.kt b/app/src/main/java/org/android/bbangzip/data/dto/response/ResponseTodayOrdersDto.kt index 59062694..1779be0f 100644 --- a/app/src/main/java/org/android/bbangzip/data/dto/response/ResponseTodayOrdersDto.kt +++ b/app/src/main/java/org/android/bbangzip/data/dto/response/ResponseTodayOrdersDto.kt @@ -14,7 +14,7 @@ data class ResponseTodayOrdersDto( val todayList: List, @SerialName("pendingCount") val pendingCount: Int, - @SerialName("toadyCount") + @SerialName("todayCount") val todayCount: Int, ) { fun toTodoInfoEntity() = diff --git a/app/src/main/java/org/android/bbangzip/data/repositoryImpl/PieceRepositoryImpl.kt b/app/src/main/java/org/android/bbangzip/data/repositoryImpl/PieceRepositoryImpl.kt index 62079d21..5ed6dc7b 100644 --- a/app/src/main/java/org/android/bbangzip/data/repositoryImpl/PieceRepositoryImpl.kt +++ b/app/src/main/java/org/android/bbangzip/data/repositoryImpl/PieceRepositoryImpl.kt @@ -1,7 +1,6 @@ package org.android.bbangzip.data.repositoryImpl import org.android.bbangzip.data.datasource.remote.TodayOrdersRemoteDataSource -import org.android.bbangzip.data.dto.request.RequestTodayOrdersDto import org.android.bbangzip.domain.model.ToDoInfoEntity import org.android.bbangzip.domain.repository.remote.PieceRepository import javax.inject.Inject diff --git a/app/src/main/java/org/android/bbangzip/data/service/PieceService.kt b/app/src/main/java/org/android/bbangzip/data/service/PieceService.kt index 0fd473ee..a9e92507 100644 --- a/app/src/main/java/org/android/bbangzip/data/service/PieceService.kt +++ b/app/src/main/java/org/android/bbangzip/data/service/PieceService.kt @@ -1,6 +1,5 @@ package org.android.bbangzip.data.service -import org.android.bbangzip.data.dto.request.RequestTodayOrdersDto import org.android.bbangzip.data.dto.response.ResponseTodayOrdersDto import org.android.bbangzip.data.util.base.BaseResponse import retrofit2.http.Body diff --git a/app/src/main/java/org/android/bbangzip/data/util/base/BaseResponse.kt b/app/src/main/java/org/android/bbangzip/data/util/base/BaseResponse.kt index 989b602d..b305ad2b 100644 --- a/app/src/main/java/org/android/bbangzip/data/util/base/BaseResponse.kt +++ b/app/src/main/java/org/android/bbangzip/data/util/base/BaseResponse.kt @@ -9,6 +9,5 @@ data class BaseResponse( val code: String, @SerialName("data") val data: T, - @SerialName("message") - val message: String, + ) diff --git a/app/src/main/java/org/android/bbangzip/domain/repository/remote/PieceRepository.kt b/app/src/main/java/org/android/bbangzip/domain/repository/remote/PieceRepository.kt index 224db2bd..f99a4ea3 100644 --- a/app/src/main/java/org/android/bbangzip/domain/repository/remote/PieceRepository.kt +++ b/app/src/main/java/org/android/bbangzip/domain/repository/remote/PieceRepository.kt @@ -1,6 +1,5 @@ package org.android.bbangzip.domain.repository.remote -import org.android.bbangzip.data.dto.request.RequestTodayOrdersDto import org.android.bbangzip.domain.model.ToDoInfoEntity interface PieceRepository { diff --git a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoContract.kt b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoContract.kt index 75e17154..a7468679 100644 --- a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoContract.kt +++ b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoContract.kt @@ -166,6 +166,7 @@ class TodoContract { val pendingCount: Int, val remainingStudyCount: Int, val completeCount: Int, + val screenType: ToDoScreenType ) : TodoEvent data class OnFilterBottomSheetItemClicked( @@ -190,6 +191,7 @@ class TodoContract { val pendingCount: Int, val remainingStudyCount: Int, val completeCount: Int, + val screenType: ToDoScreenType ) : TodoReduce data object DeleteToDoListItems : TodoReduce diff --git a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoViewModel.kt b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoViewModel.kt index 121a8f3b..7fd68c7f 100644 --- a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoViewModel.kt +++ b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoViewModel.kt @@ -3,7 +3,6 @@ package org.android.bbangzip.presentation.ui.todo import android.os.Parcelable import androidx.lifecycle.SavedStateHandle import dagger.hilt.android.lifecycle.HiltViewModel -import org.android.bbangzip.data.dto.request.RequestTodayOrdersDto import org.android.bbangzip.domain.repository.remote.PieceRepository import org.android.bbangzip.domain.usecase.GetToInfoUseCase import org.android.bbangzip.presentation.component.card.BbangZipCardState @@ -40,6 +39,7 @@ constructor( remainingStudyCount = event.remainingStudyCount, completeCount = event.completeCount, todoList = event.todoList, + screenType = event.screenType ), ) @@ -238,6 +238,7 @@ constructor( completeCount = reduce.completeCount, remainingStudyCount = reduce.remainingStudyCount, todoList = reduce.todoList, + screenType = reduce.screenType ) // List @@ -364,7 +365,8 @@ constructor( }, pendingCount = data.pendingCount, remainingStudyCount = data.remainingStudyCount, - completeCount = data.completeCount + completeCount = data.completeCount, + screenType = if (data.todoList.isEmpty()) ToDoScreenType.EMPTY else ToDoScreenType.DEFAULT ) ) } From 5d281ef8211dfb54436b8a9c032bf4cc2bddb23c Mon Sep 17 00:00:00 2001 From: beom84 Date: Mon, 20 Jan 2025 15:18:11 +0900 Subject: [PATCH 03/16] =?UTF-8?q?[feat]=20#46=20=EC=98=A4=EB=8A=98=20?= =?UTF-8?q?=ED=95=A0=20=EA=B3=B5=EB=B6=80=20=EC=B6=94=EA=B0=80=20API=20?= =?UTF-8?q?=EC=97=B0=EB=8F=99=20=EC=84=B1=EA=B3=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../remote/DummyRemoteDataSource.kt | 2 +- .../remote/TodayOrdersRemoteDataSource.kt | 2 +- .../datasource/remote/TodoRemoteDataSource.kt | 22 ++ .../data/dto/request/RequestMarkDoneDto.kt | 10 + .../dto/response/ResponseTodayOrdersDto.kt | 2 +- .../data/dto/response/ResponseTodoDto.kt | 53 ++++ .../repositoryImpl/DummyRepositoryImpl.kt | 4 +- .../repositoryImpl/PieceRepositoryImpl.kt | 17 +- .../bbangzip/data/service/DummyService.kt | 2 +- .../bbangzip/data/service/PieceService.kt | 17 +- .../bbangzip/data/util/base/BaseResponse.kt | 9 +- .../org/android/bbangzip/di/UseCaseModule.kt | 6 + .../bbangzip/domain/model/ToDoCardEntity.kt | 10 +- .../bbangzip/domain/model/ToDoInfoEntity.kt | 8 +- .../repository/remote/DummyRepository.kt | 2 +- .../repository/remote/PieceRepository.kt | 6 + .../domain/usecase/FetchDummyUseCase.kt | 2 +- .../domain/usecase/GetAddTodoListUseCase.kt | 19 ++ ...chToInfoUseCase.kt => GetToInfoUseCase.kt} | 0 .../presentation/ui/dummy/DummyViewModel.kt | 8 +- .../presentation/ui/todo/TodoContract.kt | 4 +- .../presentation/ui/todo/TodoViewModel.kt | 68 ++--- .../ui/todo/todoadd/TodoAddContract.kt | 5 + .../ui/todo/todoadd/TodoAddViewModel.kt | 250 +++++++++++------- .../util/constant/DateConstants.kt | 1 + .../util/constant/ToDoConstants.kt | 5 + 26 files changed, 382 insertions(+), 152 deletions(-) create mode 100644 app/src/main/java/org/android/bbangzip/data/datasource/remote/TodoRemoteDataSource.kt create mode 100644 app/src/main/java/org/android/bbangzip/data/dto/request/RequestMarkDoneDto.kt create mode 100644 app/src/main/java/org/android/bbangzip/data/dto/response/ResponseTodoDto.kt create mode 100644 app/src/main/java/org/android/bbangzip/domain/usecase/GetAddTodoListUseCase.kt rename app/src/main/java/org/android/bbangzip/domain/usecase/{FetchToInfoUseCase.kt => GetToInfoUseCase.kt} (100%) create mode 100644 app/src/main/java/org/android/bbangzip/presentation/util/constant/ToDoConstants.kt diff --git a/app/src/main/java/org/android/bbangzip/data/datasource/remote/DummyRemoteDataSource.kt b/app/src/main/java/org/android/bbangzip/data/datasource/remote/DummyRemoteDataSource.kt index 8b140499..2bc254d8 100644 --- a/app/src/main/java/org/android/bbangzip/data/datasource/remote/DummyRemoteDataSource.kt +++ b/app/src/main/java/org/android/bbangzip/data/datasource/remote/DummyRemoteDataSource.kt @@ -10,5 +10,5 @@ class DummyRemoteDataSource constructor( private val dummyService: DummyService, ) { - suspend fun getDummyData(): BaseResponse = dummyService.getDummy() + suspend fun getDummyData(): BaseResponse = dummyService.getDummy() } diff --git a/app/src/main/java/org/android/bbangzip/data/datasource/remote/TodayOrdersRemoteDataSource.kt b/app/src/main/java/org/android/bbangzip/data/datasource/remote/TodayOrdersRemoteDataSource.kt index 00a8ce0a..02a72c28 100644 --- a/app/src/main/java/org/android/bbangzip/data/datasource/remote/TodayOrdersRemoteDataSource.kt +++ b/app/src/main/java/org/android/bbangzip/data/datasource/remote/TodayOrdersRemoteDataSource.kt @@ -14,7 +14,7 @@ constructor( year: Int, semester: String, sortOption: String - ): BaseResponse = pieceService.getTodoInfo( + ): BaseResponse = pieceService.getTodoInfo( area = area, year = year, semester = semester, diff --git a/app/src/main/java/org/android/bbangzip/data/datasource/remote/TodoRemoteDataSource.kt b/app/src/main/java/org/android/bbangzip/data/datasource/remote/TodoRemoteDataSource.kt new file mode 100644 index 00000000..ea31ae9d --- /dev/null +++ b/app/src/main/java/org/android/bbangzip/data/datasource/remote/TodoRemoteDataSource.kt @@ -0,0 +1,22 @@ +package org.android.bbangzip.data.datasource.remote + +import org.android.bbangzip.data.dto.response.ResponseTodayOrdersDto +import org.android.bbangzip.data.dto.response.ResponseTodoDto +import org.android.bbangzip.data.service.PieceService +import org.android.bbangzip.data.util.base.BaseResponse +import javax.inject.Inject + +class TodoRemoteDataSource @Inject +constructor( + private val pieceService: PieceService, +) { + suspend fun getAddTodolist( + year: Int, + semester: String, + sortOption: String + ): BaseResponse = pieceService.getAddTodoList( + year = year, + semester = semester, + sortOption = sortOption + ) +} diff --git a/app/src/main/java/org/android/bbangzip/data/dto/request/RequestMarkDoneDto.kt b/app/src/main/java/org/android/bbangzip/data/dto/request/RequestMarkDoneDto.kt new file mode 100644 index 00000000..989155d9 --- /dev/null +++ b/app/src/main/java/org/android/bbangzip/data/dto/request/RequestMarkDoneDto.kt @@ -0,0 +1,10 @@ +package org.android.bbangzip.data.dto.request + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class RequestMarkDoneDto( + @SerialName("isFinished") + val isFinished: Boolean, +) diff --git a/app/src/main/java/org/android/bbangzip/data/dto/response/ResponseTodayOrdersDto.kt b/app/src/main/java/org/android/bbangzip/data/dto/response/ResponseTodayOrdersDto.kt index 1779be0f..8a56d6d9 100644 --- a/app/src/main/java/org/android/bbangzip/data/dto/response/ResponseTodayOrdersDto.kt +++ b/app/src/main/java/org/android/bbangzip/data/dto/response/ResponseTodayOrdersDto.kt @@ -10,7 +10,7 @@ import org.android.bbangzip.domain.model.ToDoInfoEntity data class ResponseTodayOrdersDto( @SerialName("completeCount") val completeCount: Int, - @SerialName("todoPieceStoList") + @SerialName("todoPiecesList") val todayList: List, @SerialName("pendingCount") val pendingCount: Int, diff --git a/app/src/main/java/org/android/bbangzip/data/dto/response/ResponseTodoDto.kt b/app/src/main/java/org/android/bbangzip/data/dto/response/ResponseTodoDto.kt new file mode 100644 index 00000000..f3d8e408 --- /dev/null +++ b/app/src/main/java/org/android/bbangzip/data/dto/response/ResponseTodoDto.kt @@ -0,0 +1,53 @@ +package org.android.bbangzip.data.dto.response + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +import org.android.bbangzip.domain.model.ToDoCardEntity +import org.android.bbangzip.domain.model.ToDoInfoEntity + +@Serializable +data class ResponseTodoDto( + @SerialName("todoCount") + val todoCount: Int, + @SerialName("todoList") + val todoList: List +) { + fun toTodoCardInfoEntity() = + ToDoInfoEntity( + todoList = todoList.map { todoItem -> + todoItem.toTodoCardEntity() + }, + ) +} + +@Serializable +data class TodoCardInfo( + @SerialName("deadline") + val deadline: String, + @SerialName("examName") + val examName: String, + @SerialName("finishPage") + val finishPage: Int, + @SerialName("pieceId") + val pieceId: Int, + @SerialName("remainingDays") + val remainingDays: Int, + @SerialName("startPage") + val startPage: Int, + @SerialName("studyContents") + val studyContents: String, + @SerialName("subjectName") + val subjectName: String +) { + fun toTodoCardEntity() = + ToDoCardEntity( + pieceId = pieceId, + subjectName = subjectName, + examName = examName, + studyContents = studyContents, + startPage = startPage, + finishPage = finishPage, + deadline = deadline, + remainingDays = remainingDays, + ) +} \ No newline at end of file diff --git a/app/src/main/java/org/android/bbangzip/data/repositoryImpl/DummyRepositoryImpl.kt b/app/src/main/java/org/android/bbangzip/data/repositoryImpl/DummyRepositoryImpl.kt index d8534d2f..0c4d3197 100644 --- a/app/src/main/java/org/android/bbangzip/data/repositoryImpl/DummyRepositoryImpl.kt +++ b/app/src/main/java/org/android/bbangzip/data/repositoryImpl/DummyRepositoryImpl.kt @@ -10,8 +10,8 @@ class DummyRepositoryImpl constructor( private val dummyRemoteDataSource: DummyRemoteDataSource, ) : DummyRepository { - override suspend fun fetchDummy(): Result = + override suspend fun fetchDummy(): Result = runCatching { - dummyRemoteDataSource.getDummyData().data.toDummyEntity() + dummyRemoteDataSource.getDummyData().data?.toDummyEntity() } } diff --git a/app/src/main/java/org/android/bbangzip/data/repositoryImpl/PieceRepositoryImpl.kt b/app/src/main/java/org/android/bbangzip/data/repositoryImpl/PieceRepositoryImpl.kt index 5ed6dc7b..d3fe9d5a 100644 --- a/app/src/main/java/org/android/bbangzip/data/repositoryImpl/PieceRepositoryImpl.kt +++ b/app/src/main/java/org/android/bbangzip/data/repositoryImpl/PieceRepositoryImpl.kt @@ -1,6 +1,7 @@ package org.android.bbangzip.data.repositoryImpl import org.android.bbangzip.data.datasource.remote.TodayOrdersRemoteDataSource +import org.android.bbangzip.data.datasource.remote.TodoRemoteDataSource import org.android.bbangzip.domain.model.ToDoInfoEntity import org.android.bbangzip.domain.repository.remote.PieceRepository import javax.inject.Inject @@ -9,6 +10,7 @@ class PieceRepositoryImpl @Inject constructor( private val todayOrdersRemoteDateSource: TodayOrdersRemoteDataSource, + private val todoRemoteDataSource: TodoRemoteDataSource ) : PieceRepository { override suspend fun getTodoInfo( area: String, @@ -22,8 +24,21 @@ constructor( year = year, semester = semester, sortOption = sortOption - ).data.toTodoInfoEntity() + ).data?.toTodoInfoEntity() ?: ToDoInfoEntity() } + override suspend fun getAddTodoList( + year: Int, + semester: String, + sortOption: String + ): Result = + runCatching { + todoRemoteDataSource.getAddTodolist( + year = year, + semester = semester, + sortOption = sortOption + ).data?.toTodoCardInfoEntity() ?: ToDoInfoEntity() + } } + diff --git a/app/src/main/java/org/android/bbangzip/data/service/DummyService.kt b/app/src/main/java/org/android/bbangzip/data/service/DummyService.kt index 1f44f9d6..241b6dfd 100644 --- a/app/src/main/java/org/android/bbangzip/data/service/DummyService.kt +++ b/app/src/main/java/org/android/bbangzip/data/service/DummyService.kt @@ -8,5 +8,5 @@ import retrofit2.http.GET interface DummyService { @GET("$VERSION/$DUMMY") - suspend fun getDummy(): BaseResponse + suspend fun getDummy(): BaseResponse } diff --git a/app/src/main/java/org/android/bbangzip/data/service/PieceService.kt b/app/src/main/java/org/android/bbangzip/data/service/PieceService.kt index a9e92507..0da38618 100644 --- a/app/src/main/java/org/android/bbangzip/data/service/PieceService.kt +++ b/app/src/main/java/org/android/bbangzip/data/service/PieceService.kt @@ -1,8 +1,8 @@ package org.android.bbangzip.data.service import org.android.bbangzip.data.dto.response.ResponseTodayOrdersDto +import org.android.bbangzip.data.dto.response.ResponseTodoDto import org.android.bbangzip.data.util.base.BaseResponse -import retrofit2.http.Body import retrofit2.http.GET import retrofit2.http.Query @@ -13,5 +13,18 @@ interface PieceService { @Query("year") year: Int, @Query("semester") semester: String, @Query("sortOption") sortOption: String - ): BaseResponse + ): BaseResponse + +// @POST("/api/v1/pieces/{pieceId}/mark-done") +// suspend fun postCompleteCardId( +// @Path("pieceId") pieceId: Int, +// @Body requestMarkDoneDto: RequestMarkDoneDto +// ) + + @GET("/api/v1/pieces/todo") + suspend fun getAddTodoList( + @Query("year") year: Int, + @Query("semester") semester: String, + @Query("sortOption") sortOption: String + ): BaseResponse } \ No newline at end of file diff --git a/app/src/main/java/org/android/bbangzip/data/util/base/BaseResponse.kt b/app/src/main/java/org/android/bbangzip/data/util/base/BaseResponse.kt index b305ad2b..e6b879bc 100644 --- a/app/src/main/java/org/android/bbangzip/data/util/base/BaseResponse.kt +++ b/app/src/main/java/org/android/bbangzip/data/util/base/BaseResponse.kt @@ -6,8 +6,9 @@ import kotlinx.serialization.Serializable @Serializable data class BaseResponse( @SerialName("code") - val code: String, + val code: String? = null, @SerialName("data") - val data: T, - -) + val data: T? = null, + @SerialName("message") + val message: String? = null +) \ No newline at end of file diff --git a/app/src/main/java/org/android/bbangzip/di/UseCaseModule.kt b/app/src/main/java/org/android/bbangzip/di/UseCaseModule.kt index 208a78ec..2f1c6b04 100644 --- a/app/src/main/java/org/android/bbangzip/di/UseCaseModule.kt +++ b/app/src/main/java/org/android/bbangzip/di/UseCaseModule.kt @@ -7,6 +7,7 @@ import dagger.hilt.components.SingletonComponent import org.android.bbangzip.domain.repository.remote.DummyRepository import org.android.bbangzip.domain.repository.remote.PieceRepository import org.android.bbangzip.domain.usecase.FetchDummyUseCase +import org.android.bbangzip.domain.usecase.GetAddTodoListUseCase import org.android.bbangzip.domain.usecase.GetToInfoUseCase import javax.inject.Singleton @@ -22,4 +23,9 @@ class UseCaseModule { @Singleton fun providesTodoInfoFetchUseCase(pieceRepository: PieceRepository): GetToInfoUseCase = GetToInfoUseCase(pieceRepository = pieceRepository) + + @Provides + @Singleton + fun providesAddTodoListFetchUseCase(pieceRepository: PieceRepository): GetAddTodoListUseCase = + GetAddTodoListUseCase(pieceRepository = pieceRepository) } diff --git a/app/src/main/java/org/android/bbangzip/domain/model/ToDoCardEntity.kt b/app/src/main/java/org/android/bbangzip/domain/model/ToDoCardEntity.kt index bae34da7..a717eab8 100644 --- a/app/src/main/java/org/android/bbangzip/domain/model/ToDoCardEntity.kt +++ b/app/src/main/java/org/android/bbangzip/domain/model/ToDoCardEntity.kt @@ -1,13 +1,13 @@ package org.android.bbangzip.domain.model data class ToDoCardEntity( - val pieceId: Int, + val pieceId: Int = 0, val subjectName: String = "", val examName: String = "", val studyContents: String, - val startPage: Int, - val finishPage: Int, - val deadline: String, - val remainingDays: Int, + val startPage: Int = 0, + val finishPage: Int= 0, + val deadline: String = "", + val remainingDays: Int = 0, val isFinished: Boolean = false, ) diff --git a/app/src/main/java/org/android/bbangzip/domain/model/ToDoInfoEntity.kt b/app/src/main/java/org/android/bbangzip/domain/model/ToDoInfoEntity.kt index edd5fb72..5f9e1ef5 100644 --- a/app/src/main/java/org/android/bbangzip/domain/model/ToDoInfoEntity.kt +++ b/app/src/main/java/org/android/bbangzip/domain/model/ToDoInfoEntity.kt @@ -1,8 +1,8 @@ package org.android.bbangzip.domain.model data class ToDoInfoEntity( - val todoList: List, - val pendingCount: Int, - val remainingStudyCount: Int, - val completeCount: Int, + val todoList: List = listOf(), + val pendingCount: Int = 0, + val remainingStudyCount: Int = 0, + val completeCount: Int = 0, ) diff --git a/app/src/main/java/org/android/bbangzip/domain/repository/remote/DummyRepository.kt b/app/src/main/java/org/android/bbangzip/domain/repository/remote/DummyRepository.kt index 02c1a867..614b30e6 100644 --- a/app/src/main/java/org/android/bbangzip/domain/repository/remote/DummyRepository.kt +++ b/app/src/main/java/org/android/bbangzip/domain/repository/remote/DummyRepository.kt @@ -3,5 +3,5 @@ package org.android.bbangzip.domain.repository.remote import org.android.bbangzip.domain.model.DummyEntity interface DummyRepository { - suspend fun fetchDummy(): Result + suspend fun fetchDummy(): Result } diff --git a/app/src/main/java/org/android/bbangzip/domain/repository/remote/PieceRepository.kt b/app/src/main/java/org/android/bbangzip/domain/repository/remote/PieceRepository.kt index f99a4ea3..5b13413b 100644 --- a/app/src/main/java/org/android/bbangzip/domain/repository/remote/PieceRepository.kt +++ b/app/src/main/java/org/android/bbangzip/domain/repository/remote/PieceRepository.kt @@ -9,5 +9,11 @@ interface PieceRepository { semester: String, sortOption: String ): Result + + suspend fun getAddTodoList( + year: Int, + semester: String, + sortOption: String + ): Result } diff --git a/app/src/main/java/org/android/bbangzip/domain/usecase/FetchDummyUseCase.kt b/app/src/main/java/org/android/bbangzip/domain/usecase/FetchDummyUseCase.kt index c844ec1f..94b93fe5 100644 --- a/app/src/main/java/org/android/bbangzip/domain/usecase/FetchDummyUseCase.kt +++ b/app/src/main/java/org/android/bbangzip/domain/usecase/FetchDummyUseCase.kt @@ -6,6 +6,6 @@ import org.android.bbangzip.domain.repository.remote.DummyRepository class FetchDummyUseCase( private val dummyRepository: DummyRepository, ) { - suspend operator fun invoke(): Result = + suspend operator fun invoke(): Result = dummyRepository.fetchDummy() } diff --git a/app/src/main/java/org/android/bbangzip/domain/usecase/GetAddTodoListUseCase.kt b/app/src/main/java/org/android/bbangzip/domain/usecase/GetAddTodoListUseCase.kt new file mode 100644 index 00000000..ec983b2e --- /dev/null +++ b/app/src/main/java/org/android/bbangzip/domain/usecase/GetAddTodoListUseCase.kt @@ -0,0 +1,19 @@ +package org.android.bbangzip.domain.usecase + +import org.android.bbangzip.domain.model.ToDoInfoEntity +import org.android.bbangzip.domain.repository.remote.PieceRepository + +class GetAddTodoListUseCase( + private val pieceRepository: PieceRepository +) { + suspend operator fun invoke( + year: Int, + semester: String, + sortOption: String + ): Result = + pieceRepository.getAddTodoList( + year = year, + semester = semester, + sortOption = sortOption + ) +} \ No newline at end of file diff --git a/app/src/main/java/org/android/bbangzip/domain/usecase/FetchToInfoUseCase.kt b/app/src/main/java/org/android/bbangzip/domain/usecase/GetToInfoUseCase.kt similarity index 100% rename from app/src/main/java/org/android/bbangzip/domain/usecase/FetchToInfoUseCase.kt rename to app/src/main/java/org/android/bbangzip/domain/usecase/GetToInfoUseCase.kt diff --git a/app/src/main/java/org/android/bbangzip/presentation/ui/dummy/DummyViewModel.kt b/app/src/main/java/org/android/bbangzip/presentation/ui/dummy/DummyViewModel.kt index c1ec8f5a..e754f5c6 100644 --- a/app/src/main/java/org/android/bbangzip/presentation/ui/dummy/DummyViewModel.kt +++ b/app/src/main/java/org/android/bbangzip/presentation/ui/dummy/DummyViewModel.kt @@ -75,8 +75,8 @@ class DummyViewModel updateState( DummyContract.DummyReduce.UpdateDummy( Dummy( - dummyA = data.dummyName, - dummyB = data.dummyName + "이런 식으로 넣어요", + dummyA = "data.dummyName", + dummyB = "data.dummyName" + "이런 식으로 넣어요", ), ), ) @@ -90,8 +90,8 @@ class DummyViewModel updateState( DummyContract.DummyReduce.UpdateDummy( Dummy( - dummyA = data.dummyName, - dummyB = data.dummyName + "이런 식으로 넣어요", + dummyA = "data!!dummyName,", + dummyB = data!!.dummyName + "이런 식으로 넣어요", ), ), ) diff --git a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoContract.kt b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoContract.kt index a7468679..0b8a6cba 100644 --- a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoContract.kt +++ b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoContract.kt @@ -125,13 +125,13 @@ class TodoContract { ), ), val pendingCount: Int = 10, - val remainingStudyCount: Int = 5, + val remainingStudyCount: Int = 0, val completeCount: Int = 5, val todoFilterBottomSheetState: Boolean = false, val selectedFilterItem: ToDoFilterType = ToDoFilterType.RECENT, val selectedItemList: List = listOf(), val revertCompleteBottomSheetState: Boolean = false, - val screenType: ToDoScreenType = ToDoScreenType.DEFAULT, + val screenType: ToDoScreenType = ToDoScreenType.EMPTY, ) : BaseContract.State, Parcelable { override fun toParcelable(): Parcelable = this } diff --git a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoViewModel.kt b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoViewModel.kt index 7fd68c7f..b044ece8 100644 --- a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoViewModel.kt +++ b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoViewModel.kt @@ -2,13 +2,15 @@ package org.android.bbangzip.presentation.ui.todo import android.os.Parcelable import androidx.lifecycle.SavedStateHandle +import androidx.lifecycle.viewModelScope import dagger.hilt.android.lifecycle.HiltViewModel -import org.android.bbangzip.domain.repository.remote.PieceRepository +import kotlinx.coroutines.launch import org.android.bbangzip.domain.usecase.GetToInfoUseCase import org.android.bbangzip.presentation.component.card.BbangZipCardState import org.android.bbangzip.presentation.model.card.ToDoCardModel import org.android.bbangzip.presentation.type.ToDoScreenType import org.android.bbangzip.presentation.util.base.BaseViewModel +import org.android.bbangzip.presentation.util.constant.ToDoConstants import timber.log.Timber import javax.inject.Inject @@ -26,7 +28,7 @@ constructor( } init { - setEvent(TodoContract.TodoEvent.Initialize) +// setEvent(TodoContract.TodoEvent.Initialize) } override fun handleEvent(event: TodoContract.TodoEvent) { @@ -47,11 +49,14 @@ constructor( // Filter BottomSheet is TodoContract.TodoEvent.OnFilterBottomSheetItemClicked -> { + viewModelScope.launch { + getToDoInfo(area = ToDoConstants.AREA, year = 2025, semester = "1학기", sortOption = event.selectedFilterItem.id) + } updateState(TodoContract.TodoReduce.UpdateFilterType(selectedFilter = event.selectedFilterItem)) updateState( TodoContract.TodoReduce.UpdateToDoFilterBottomSheetState( todoFilterBottomSheetState = false, - ), + ) ) setSideEffect(TodoContract.TodoSideEffect.ShowSnackBar("${event.selectedFilterItem.filter}으로 정렬했어요")) // TODO index를 이용해 서버로 FetchInfo 보내주기 다시 정렬하기 ㅋㅋ @@ -329,8 +334,8 @@ constructor( getToDoInfo( area = "todo", year = 2025, - semester = "1", - sortOption = "recent" + semester = "1학기", + sortOption = currentUiState.selectedFilterItem.id ) } @@ -345,38 +350,35 @@ constructor( year = year, semester = semester, sortOption = sortOption - ) - .onSuccess { data -> - Timber.tag("ㅋㅋ").d("server viewmodel") - updateState( - TodoContract.TodoReduce.UpdateToDoInfo( - todoList = data.todoList.map { item -> - ToDoCardModel( - pieceId = item.pieceId, - subjectName = item.subjectName, - examName = item.examName, - studyContents = item.studyContents, - startPage = item.startPage, - finishPage = item.finishPage, - deadline = item.deadline, - remainingDays = item.remainingDays, - cardState = if (item.isFinished) BbangZipCardState.COMPLETE else BbangZipCardState.DEFAULT - ) - }, - pendingCount = data.pendingCount, - remainingStudyCount = data.remainingStudyCount, - completeCount = data.completeCount, - screenType = if (data.todoList.isEmpty()) ToDoScreenType.EMPTY else ToDoScreenType.DEFAULT - ) + ).onSuccess { data -> + Timber.tag("ㅋㅋ").d("server viewmodel") + updateState( + TodoContract.TodoReduce.UpdateToDoInfo( + todoList = data.todoList.map { item -> + ToDoCardModel( + pieceId = item.pieceId, + subjectName = item.subjectName, + examName = item.examName, + studyContents = item.studyContents, + startPage = item.startPage, + finishPage = item.finishPage, + deadline = item.deadline, + remainingDays = item.remainingDays, + cardState = if (item.isFinished) BbangZipCardState.COMPLETE else BbangZipCardState.DEFAULT + ) + }, + pendingCount = data.pendingCount, + remainingStudyCount = data.remainingStudyCount, + completeCount = data.completeCount, + screenType = if (data.todoList.isEmpty()) ToDoScreenType.EMPTY else ToDoScreenType.DEFAULT ) - } - .onFailure { message -> + ) + } + .onFailure { error -> Timber.run { tag("ㅋㅋ").d("server viewmodel fail") - tag("ㅋㅋ").d(message.message) + tag("ㅋㅋ").d(error.message) } - } - } } diff --git a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/todoadd/TodoAddContract.kt b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/todoadd/TodoAddContract.kt index da372a70..1f0bc485 100644 --- a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/todoadd/TodoAddContract.kt +++ b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/todoadd/TodoAddContract.kt @@ -5,6 +5,7 @@ import kotlinx.parcelize.Parcelize import org.android.bbangzip.presentation.component.card.BbangZipCardState import org.android.bbangzip.presentation.model.card.ToDoCardModel import org.android.bbangzip.presentation.type.ToDoFilterType +import org.android.bbangzip.presentation.type.ToDoScreenType import org.android.bbangzip.presentation.util.base.BaseContract class TodoAddContract { @@ -149,6 +150,10 @@ class TodoAddContract { sealed interface TodoAddReduce : BaseContract.Reduce { data object ResetSelectedItemList : TodoAddReduce + data class UpdateToDoList( + val todoList: List, + ): TodoAddReduce + data class UpdateSelectedItemList( val pieceId: Int, ) : TodoAddReduce diff --git a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/todoadd/TodoAddViewModel.kt b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/todoadd/TodoAddViewModel.kt index 680d17fa..ed166160 100644 --- a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/todoadd/TodoAddViewModel.kt +++ b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/todoadd/TodoAddViewModel.kt @@ -2,122 +2,194 @@ package org.android.bbangzip.presentation.ui.todo.todoadd import android.os.Parcelable import androidx.lifecycle.SavedStateHandle +import androidx.lifecycle.viewModelScope import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.launch +import org.android.bbangzip.domain.usecase.GetAddTodoListUseCase import org.android.bbangzip.presentation.component.card.BbangZipCardState +import org.android.bbangzip.presentation.model.card.ToDoCardModel import org.android.bbangzip.presentation.util.base.BaseViewModel +import timber.log.Timber import javax.inject.Inject @HiltViewModel class TodoAddViewModel - @Inject - constructor( - savedStateHandle: SavedStateHandle, - ) : BaseViewModel( - savedStateHandle = savedStateHandle, - ) { - override fun createInitialState(savedState: Parcelable?): TodoAddContract.TodoAddState { - return savedState as? TodoAddContract.TodoAddState ?: TodoAddContract.TodoAddState() - } +@Inject +constructor( + private val getAddTodoListUseCase: GetAddTodoListUseCase, + savedStateHandle: SavedStateHandle, +) : BaseViewModel( + savedStateHandle = savedStateHandle, +) { + override fun createInitialState(savedState: Parcelable?): TodoAddContract.TodoAddState { + return savedState as? TodoAddContract.TodoAddState ?: TodoAddContract.TodoAddState() + } - override fun handleEvent(event: TodoAddContract.TodoAddEvent) { - when (event) { - TodoAddContract.TodoAddEvent.Initialize -> TODO() + init { + setEvent(TodoAddContract.TodoAddEvent.Initialize) + } - TodoAddContract.TodoAddEvent.OnBackIconClicked -> { - updateState(TodoAddContract.TodoAddReduce.ResetSelectedItemList) - setSideEffect(TodoAddContract.TodoAddSideEffect.NavigateToBack) - } + override fun handleEvent(event: TodoAddContract.TodoAddEvent) { + when (event) { + TodoAddContract.TodoAddEvent.Initialize -> launch { initDataLoad() } - TodoAddContract.TodoAddEvent.OnFilterBottomSheetDismissRequest -> - updateState( - TodoAddContract.TodoAddReduce.UpdateToDoFilterBottomSheetState( - todoFilterBottomSheetState = false, - ), + TodoAddContract.TodoAddEvent.OnBackIconClicked -> { + updateState(TodoAddContract.TodoAddReduce.ResetSelectedItemList) + setSideEffect(TodoAddContract.TodoAddSideEffect.NavigateToBack) + } + + TodoAddContract.TodoAddEvent.OnFilterBottomSheetDismissRequest -> + updateState( + TodoAddContract.TodoAddReduce.UpdateToDoFilterBottomSheetState( + todoFilterBottomSheetState = false, + ), + ) + + TodoAddContract.TodoAddEvent.OnFilterIconClicked -> + updateState( + TodoAddContract.TodoAddReduce.UpdateToDoFilterBottomSheetState( + todoFilterBottomSheetState = true, + ), + ) + + is TodoAddContract.TodoAddEvent.OnFilterBottomSheetItemClicked -> { + viewModelScope.launch { + getAddTodoList( + year = 2025, + semester = "1학기", + sortOption = event.selectedFilterItem.id ) + }.isCompleted + updateState(TodoAddContract.TodoAddReduce.UpdateFilterType(selectedFilter = event.selectedFilterItem)) + updateState( + TodoAddContract.TodoAddReduce.UpdateToDoFilterBottomSheetState( + todoFilterBottomSheetState = false, + ), + ) + setSideEffect(TodoAddContract.TodoAddSideEffect.ShowTodoAddSnackBar("${event.selectedFilterItem.filter}으로 정렬했어요")) + // TODO 받아오고 다시 정렬해야됨 ㅋㅋ + } - TodoAddContract.TodoAddEvent.OnFilterIconClicked -> + TodoAddContract.TodoAddEvent.OnItemPlusButtonClicked -> { + // TODO 서버로 보내기 + setSideEffect(TodoAddContract.TodoAddSideEffect.NavigateToToDo) + setSideEffect(TodoAddContract.TodoAddSideEffect.ShowSnackBar("오늘 할 공부를 추가했어요!")) + } + + is TodoAddContract.TodoAddEvent.OnToDoCardClicked -> { + if (event.cardState == BbangZipCardState.CHECKED) { + updateState(TodoAddContract.TodoAddReduce.UpdateSelectedItemList(pieceId = event.pieceId)) updateState( - TodoAddContract.TodoAddReduce.UpdateToDoFilterBottomSheetState( - todoFilterBottomSheetState = true, + TodoAddContract.TodoAddReduce.UpdateCardState( + pieceId = event.pieceId, + cardState = event.cardState, ), ) - - is TodoAddContract.TodoAddEvent.OnFilterBottomSheetItemClicked -> { - updateState(TodoAddContract.TodoAddReduce.UpdateFilterType(selectedFilter = event.selectedFilterItem)) + } else { + updateState(TodoAddContract.TodoAddReduce.DeleteSelectedItemList(pieceId = event.pieceId)) updateState( - TodoAddContract.TodoAddReduce.UpdateToDoFilterBottomSheetState( - todoFilterBottomSheetState = false, + TodoAddContract.TodoAddReduce.UpdateCardState( + pieceId = event.pieceId, + cardState = event.cardState, ), ) - setSideEffect(TodoAddContract.TodoAddSideEffect.ShowTodoAddSnackBar("${event.selectedFilterItem.filter}으로 정렬했어요")) - // TODO 받아오고 다시 정렬해야됨 ㅋㅋ - } - - TodoAddContract.TodoAddEvent.OnItemPlusButtonClicked -> { - // TODO 서버로 보내기 - setSideEffect(TodoAddContract.TodoAddSideEffect.NavigateToToDo) - setSideEffect(TodoAddContract.TodoAddSideEffect.ShowSnackBar("오늘 할 공부를 추가했어요!")) - } - - is TodoAddContract.TodoAddEvent.OnToDoCardClicked -> { - if (event.cardState == BbangZipCardState.CHECKED) { - updateState(TodoAddContract.TodoAddReduce.UpdateSelectedItemList(pieceId = event.pieceId)) - updateState( - TodoAddContract.TodoAddReduce.UpdateCardState( - pieceId = event.pieceId, - cardState = event.cardState, - ), - ) - } else { - updateState(TodoAddContract.TodoAddReduce.DeleteSelectedItemList(pieceId = event.pieceId)) - updateState( - TodoAddContract.TodoAddReduce.UpdateCardState( - pieceId = event.pieceId, - cardState = event.cardState, - ), - ) - } } } } + } - override fun reduceState( - state: TodoAddContract.TodoAddState, - reduce: TodoAddContract.TodoAddReduce, - ): TodoAddContract.TodoAddState { - return when (reduce) { - TodoAddContract.TodoAddReduce.ResetSelectedItemList -> - state.copy( - selectedItemList = listOf(), - ) + override fun reduceState( + state: TodoAddContract.TodoAddState, + reduce: TodoAddContract.TodoAddReduce, + ): TodoAddContract.TodoAddState { + return when (reduce) { + TodoAddContract.TodoAddReduce.ResetSelectedItemList -> + state.copy( + selectedItemList = listOf(), + ) - is TodoAddContract.TodoAddReduce.UpdateCardState -> - state.copy( - todoList = - state.todoList.map { item -> - if (item.pieceId == reduce.pieceId) item.copy(cardState = reduce.cardState) else item - }, - ) - is TodoAddContract.TodoAddReduce.UpdateFilterType -> - state.copy( - selectedFilter = reduce.selectedFilter, - ) + is TodoAddContract.TodoAddReduce.UpdateCardState -> + state.copy( + todoList = + state.todoList.map { item -> + if (item.pieceId == reduce.pieceId) item.copy(cardState = reduce.cardState) else item + }, + ) - is TodoAddContract.TodoAddReduce.UpdateSelectedItemList -> - state.copy( - selectedItemList = state.selectedItemList.plus(reduce.pieceId), - ) + is TodoAddContract.TodoAddReduce.UpdateFilterType -> + state.copy( + selectedFilter = reduce.selectedFilter, + ) - is TodoAddContract.TodoAddReduce.UpdateToDoFilterBottomSheetState -> - state.copy( - todoFilterBottomSheetState = reduce.todoFilterBottomSheetState, - ) + is TodoAddContract.TodoAddReduce.UpdateSelectedItemList -> + state.copy( + selectedItemList = state.selectedItemList.plus(reduce.pieceId), + ) + + is TodoAddContract.TodoAddReduce.UpdateToDoFilterBottomSheetState -> + state.copy( + todoFilterBottomSheetState = reduce.todoFilterBottomSheetState, + ) + + is TodoAddContract.TodoAddReduce.DeleteSelectedItemList -> + state.copy( + selectedItemList = state.selectedItemList.minus(reduce.pieceId), + ) + + is TodoAddContract.TodoAddReduce.UpdateToDoList -> + state.copy( + todoList = reduce.todoList + ) + } + } - is TodoAddContract.TodoAddReduce.DeleteSelectedItemList -> - state.copy( - selectedItemList = state.selectedItemList.minus(reduce.pieceId), + private suspend fun initDataLoad() { + getAddTodoList( + year = 2025, + semester = "1학기", + sortOption = currentUiState.selectedFilter.id + ) + } + + private suspend fun getAddTodoList( + year: Int, + semester: String, + sortOption: String + ) { + getAddTodoListUseCase( + year = year, + semester = semester, + sortOption = sortOption + ) + .onSuccess { data -> + Timber.tag("ㅋㅋ").d("server viewmodel") + updateState( + TodoAddContract.TodoAddReduce.UpdateToDoList( + todoList = data.todoList.map { item -> + ToDoCardModel( + pieceId = item.pieceId, + subjectName = item.subjectName, + examName = item.examName, + studyContents = item.studyContents, + startPage = item.startPage, + finishPage = item.finishPage, + deadline = item.deadline, + remainingDays = item.remainingDays, + cardState = if (currentUiState.selectedItemList.toSet() + .contains(item.pieceId) + ) BbangZipCardState.CHECKED else BbangZipCardState.CHECKABLE + ) + }, ) + ) + } + .onFailure { error -> + Timber.run { + tag("ㅋㅋ").d(error.message) + } + } - } } +} + diff --git a/app/src/main/java/org/android/bbangzip/presentation/util/constant/DateConstants.kt b/app/src/main/java/org/android/bbangzip/presentation/util/constant/DateConstants.kt index 24dde950..ed1ef04e 100644 --- a/app/src/main/java/org/android/bbangzip/presentation/util/constant/DateConstants.kt +++ b/app/src/main/java/org/android/bbangzip/presentation/util/constant/DateConstants.kt @@ -7,3 +7,4 @@ object DateConstants { val YEARS_LIST = (YEAR_OF_TODAY..2028).map { it.toString() + "년" } val MONTHS_LIST = (1..12).map { it.toString() + "월" } } + diff --git a/app/src/main/java/org/android/bbangzip/presentation/util/constant/ToDoConstants.kt b/app/src/main/java/org/android/bbangzip/presentation/util/constant/ToDoConstants.kt new file mode 100644 index 00000000..9e50124b --- /dev/null +++ b/app/src/main/java/org/android/bbangzip/presentation/util/constant/ToDoConstants.kt @@ -0,0 +1,5 @@ +package org.android.bbangzip.presentation.util.constant + +object ToDoConstants { + const val AREA = "todo" +} \ No newline at end of file From c33d07dc73be83a08ff6e97291e3b7b88f9d6b99 Mon Sep 17 00:00:00 2001 From: beom84 Date: Mon, 20 Jan 2025 15:51:25 +0900 Subject: [PATCH 04/16] =?UTF-8?q?[feat]=20#46=20=EB=B0=80=EB=A6=B0=20?= =?UTF-8?q?=ED=95=A0=20=EC=9D=BC=20=EA=B3=B5=EB=B6=80=20=EC=B6=94=EA=B0=80?= =?UTF-8?q?=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=20API=20=EC=97=B0=EB=8F=99=20?= =?UTF-8?q?=EC=84=B1=EA=B3=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/ui/todo/TodoViewModel.kt | 4 +- .../pendingtodoadd/TodoAddPendingContract.kt | 5 + .../pendingtodoadd/TodoAddPendingViewModel.kt | 253 ++++++++++++------ .../util/constant/ToDoConstants.kt | 3 +- 4 files changed, 173 insertions(+), 92 deletions(-) diff --git a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoViewModel.kt b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoViewModel.kt index b044ece8..7035cacd 100644 --- a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoViewModel.kt +++ b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoViewModel.kt @@ -28,7 +28,7 @@ constructor( } init { -// setEvent(TodoContract.TodoEvent.Initialize) + setEvent(TodoContract.TodoEvent.Initialize) } override fun handleEvent(event: TodoContract.TodoEvent) { @@ -50,7 +50,7 @@ constructor( // Filter BottomSheet is TodoContract.TodoEvent.OnFilterBottomSheetItemClicked -> { viewModelScope.launch { - getToDoInfo(area = ToDoConstants.AREA, year = 2025, semester = "1학기", sortOption = event.selectedFilterItem.id) + getToDoInfo(area = ToDoConstants.TODO, year = 2025, semester = "1학기", sortOption = event.selectedFilterItem.id) } updateState(TodoContract.TodoReduce.UpdateFilterType(selectedFilter = event.selectedFilterItem)) updateState( diff --git a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/pendingtodoadd/TodoAddPendingContract.kt b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/pendingtodoadd/TodoAddPendingContract.kt index 7d96f5e1..639da0c7 100644 --- a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/pendingtodoadd/TodoAddPendingContract.kt +++ b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/pendingtodoadd/TodoAddPendingContract.kt @@ -5,6 +5,7 @@ import kotlinx.parcelize.Parcelize import org.android.bbangzip.presentation.component.card.BbangZipCardState import org.android.bbangzip.presentation.model.card.ToDoCardModel import org.android.bbangzip.presentation.type.ToDoFilterType +import org.android.bbangzip.presentation.ui.todo.todoadd.TodoAddContract.TodoAddReduce import org.android.bbangzip.presentation.util.base.BaseContract class TodoAddPendingContract { @@ -157,6 +158,10 @@ class TodoAddPendingContract { val todoFilterBottomSheetState: Boolean, ) : TodoAddPendingReduce + data class UpdateToDoList( + val todoList: List, + ): TodoAddPendingReduce + data class UpdateFilterType( val selectedFilter: ToDoFilterType, ) : TodoAddPendingReduce diff --git a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/pendingtodoadd/TodoAddPendingViewModel.kt b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/pendingtodoadd/TodoAddPendingViewModel.kt index ec6c525f..10a1f2d2 100644 --- a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/pendingtodoadd/TodoAddPendingViewModel.kt +++ b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/pendingtodoadd/TodoAddPendingViewModel.kt @@ -2,122 +2,197 @@ package org.android.bbangzip.presentation.ui.todo.pendingtodoadd import android.os.Parcelable import androidx.lifecycle.SavedStateHandle +import androidx.lifecycle.viewModelScope import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.launch +import org.android.bbangzip.domain.usecase.GetToInfoUseCase import org.android.bbangzip.presentation.component.card.BbangZipCardState +import org.android.bbangzip.presentation.model.card.ToDoCardModel import org.android.bbangzip.presentation.util.base.BaseViewModel +import org.android.bbangzip.presentation.util.constant.ToDoConstants +import timber.log.Timber import javax.inject.Inject @HiltViewModel class TodoAddPendingViewModel - @Inject - constructor( - savedStateHandle: SavedStateHandle, - ) : BaseViewModel( - savedStateHandle = savedStateHandle, - ) { - override fun createInitialState(savedState: Parcelable?): TodoAddPendingContract.TodoAddPendingState { - return savedState as? TodoAddPendingContract.TodoAddPendingState ?: TodoAddPendingContract.TodoAddPendingState() - } +@Inject +constructor( + private val getToInfoUseCase: GetToInfoUseCase, + savedStateHandle: SavedStateHandle, +) : BaseViewModel( + savedStateHandle = savedStateHandle, +) { + override fun createInitialState(savedState: Parcelable?): TodoAddPendingContract.TodoAddPendingState { + return savedState as? TodoAddPendingContract.TodoAddPendingState ?: TodoAddPendingContract.TodoAddPendingState() + } - override fun handleEvent(event: TodoAddPendingContract.TodoAddPendingEvent) { - when (event) { - TodoAddPendingContract.TodoAddPendingEvent.Initialize -> TODO() + init { + setEvent(TodoAddPendingContract.TodoAddPendingEvent.Initialize) + } - TodoAddPendingContract.TodoAddPendingEvent.OnBackIconClicked -> { - updateState(TodoAddPendingContract.TodoAddPendingReduce.ResetSelectedItemList) - setSideEffect(TodoAddPendingContract.TodoAddPendingSideEffect.NavigateToBack) - } + override fun handleEvent(event: TodoAddPendingContract.TodoAddPendingEvent) { + when (event) { + TodoAddPendingContract.TodoAddPendingEvent.Initialize -> launch { initDataLoad() } - TodoAddPendingContract.TodoAddPendingEvent.OnFilterBottomSheetDismissRequest -> - updateState( - TodoAddPendingContract.TodoAddPendingReduce.UpdateToDoFilterBottomSheetState( - todoFilterBottomSheetState = false, - ), - ) + TodoAddPendingContract.TodoAddPendingEvent.OnBackIconClicked -> { + updateState(TodoAddPendingContract.TodoAddPendingReduce.ResetSelectedItemList) + setSideEffect(TodoAddPendingContract.TodoAddPendingSideEffect.NavigateToBack) + } + + TodoAddPendingContract.TodoAddPendingEvent.OnFilterBottomSheetDismissRequest -> + updateState( + TodoAddPendingContract.TodoAddPendingReduce.UpdateToDoFilterBottomSheetState( + todoFilterBottomSheetState = false, + ), + ) + + TodoAddPendingContract.TodoAddPendingEvent.OnFilterIconClicked -> + updateState( + TodoAddPendingContract.TodoAddPendingReduce.UpdateToDoFilterBottomSheetState( + todoFilterBottomSheetState = true, + ), + ) - TodoAddPendingContract.TodoAddPendingEvent.OnFilterIconClicked -> + is TodoAddPendingContract.TodoAddPendingEvent.OnFilterBottomSheetItemClicked -> { + updateState(TodoAddPendingContract.TodoAddPendingReduce.UpdateFilterType(selectedFilter = event.selectedFilterItem)) + updateState( + TodoAddPendingContract.TodoAddPendingReduce.UpdateToDoFilterBottomSheetState( + todoFilterBottomSheetState = false, + ), + ) + setSideEffect(TodoAddPendingContract.TodoAddPendingSideEffect.ShowTodoAddSnackBar("${event.selectedFilterItem.filter}으로 정렬했어요")) + // TODO 받아오고 다시 정렬해야됨 ㅋㅋ + } + + TodoAddPendingContract.TodoAddPendingEvent.OnItemPlusButtonClicked -> { + // TODO 서버로 보내기 + setSideEffect(TodoAddPendingContract.TodoAddPendingSideEffect.NavigateToToDo) + setSideEffect(TodoAddPendingContract.TodoAddPendingSideEffect.ShowSnackBar("오늘 할 공부를 추가했어요!")) + } + + is TodoAddPendingContract.TodoAddPendingEvent.OnToDoCardClicked -> { + if (event.cardState == BbangZipCardState.CHECKED) { + updateState(TodoAddPendingContract.TodoAddPendingReduce.UpdateSelectedItemList(pieceId = event.pieceId)) updateState( - TodoAddPendingContract.TodoAddPendingReduce.UpdateToDoFilterBottomSheetState( - todoFilterBottomSheetState = true, + TodoAddPendingContract.TodoAddPendingReduce.UpdateCardState( + pieceId = event.pieceId, + cardState = event.cardState, ), ) - - is TodoAddPendingContract.TodoAddPendingEvent.OnFilterBottomSheetItemClicked -> { - updateState(TodoAddPendingContract.TodoAddPendingReduce.UpdateFilterType(selectedFilter = event.selectedFilterItem)) + } else { + updateState(TodoAddPendingContract.TodoAddPendingReduce.DeleteSelectedItemList(pieceId = event.pieceId)) updateState( - TodoAddPendingContract.TodoAddPendingReduce.UpdateToDoFilterBottomSheetState( - todoFilterBottomSheetState = false, + TodoAddPendingContract.TodoAddPendingReduce.UpdateCardState( + pieceId = event.pieceId, + cardState = event.cardState, ), ) - setSideEffect(TodoAddPendingContract.TodoAddPendingSideEffect.ShowTodoAddSnackBar("${event.selectedFilterItem.filter}으로 정렬했어요")) - // TODO 받아오고 다시 정렬해야됨 ㅋㅋ } + } + } + } - TodoAddPendingContract.TodoAddPendingEvent.OnItemPlusButtonClicked -> { - // TODO 서버로 보내기 - setSideEffect(TodoAddPendingContract.TodoAddPendingSideEffect.NavigateToToDo) - setSideEffect(TodoAddPendingContract.TodoAddPendingSideEffect.ShowSnackBar("오늘 할 공부를 추가했어요!")) - } + override fun reduceState( + state: TodoAddPendingContract.TodoAddPendingState, + reduce: TodoAddPendingContract.TodoAddPendingReduce, + ): TodoAddPendingContract.TodoAddPendingState { + return when (reduce) { + TodoAddPendingContract.TodoAddPendingReduce.ResetSelectedItemList -> + state.copy( + selectedItemList = listOf(), + ) - is TodoAddPendingContract.TodoAddPendingEvent.OnToDoCardClicked -> { - if (event.cardState == BbangZipCardState.CHECKED) { - updateState(TodoAddPendingContract.TodoAddPendingReduce.UpdateSelectedItemList(pieceId = event.pieceId)) - updateState( - TodoAddPendingContract.TodoAddPendingReduce.UpdateCardState( - pieceId = event.pieceId, - cardState = event.cardState, - ), - ) - } else { - updateState(TodoAddPendingContract.TodoAddPendingReduce.DeleteSelectedItemList(pieceId = event.pieceId)) - updateState( - TodoAddPendingContract.TodoAddPendingReduce.UpdateCardState( - pieceId = event.pieceId, - cardState = event.cardState, - ), - ) - } + is TodoAddPendingContract.TodoAddPendingReduce.UpdateCardState -> + state.copy( + todoList = + state.todoList.map { item -> + if (item.pieceId == reduce.pieceId) item.copy(cardState = reduce.cardState) else item + }, + ) + + is TodoAddPendingContract.TodoAddPendingReduce.UpdateFilterType -> { + viewModelScope.launch { + getToDoInfo( + area = ToDoConstants.PENDING, + year = 2025, + semester = "1학기", + sortOption = reduce.selectedFilter.id + ) } + state.copy( + selectedFilter = reduce.selectedFilter, + ) } - } - override fun reduceState( - state: TodoAddPendingContract.TodoAddPendingState, - reduce: TodoAddPendingContract.TodoAddPendingReduce, - ): TodoAddPendingContract.TodoAddPendingState { - return when (reduce) { - TodoAddPendingContract.TodoAddPendingReduce.ResetSelectedItemList -> - state.copy( - selectedItemList = listOf(), - ) + is TodoAddPendingContract.TodoAddPendingReduce.UpdateSelectedItemList -> + state.copy( + selectedItemList = state.selectedItemList.plus(reduce.pieceId), + ) - is TodoAddPendingContract.TodoAddPendingReduce.UpdateCardState -> - state.copy( - todoList = - state.todoList.map { item -> - if (item.pieceId == reduce.pieceId) item.copy(cardState = reduce.cardState) else item - }, - ) + is TodoAddPendingContract.TodoAddPendingReduce.UpdateToDoFilterBottomSheetState -> + state.copy( + todoFilterBottomSheetState = reduce.todoFilterBottomSheetState, + ) - is TodoAddPendingContract.TodoAddPendingReduce.UpdateFilterType -> - state.copy( - selectedFilter = reduce.selectedFilter, - ) + is TodoAddPendingContract.TodoAddPendingReduce.DeleteSelectedItemList -> + state.copy( + selectedItemList = state.selectedItemList.minus(reduce.pieceId), + ) - is TodoAddPendingContract.TodoAddPendingReduce.UpdateSelectedItemList -> - state.copy( - selectedItemList = state.selectedItemList.plus(reduce.pieceId), - ) + is TodoAddPendingContract.TodoAddPendingReduce.UpdateToDoList -> + state.copy( + todoList = reduce.todoList + ) + } + } - is TodoAddPendingContract.TodoAddPendingReduce.UpdateToDoFilterBottomSheetState -> - state.copy( - todoFilterBottomSheetState = reduce.todoFilterBottomSheetState, - ) + private suspend fun initDataLoad() { + getToDoInfo( + area = "todo", + year = 2025, + semester = "1학기", + sortOption = currentUiState.selectedFilter.id + ) + } - is TodoAddPendingContract.TodoAddPendingReduce.DeleteSelectedItemList -> - state.copy( - selectedItemList = state.selectedItemList.minus(reduce.pieceId), - ) - } + private suspend fun getToDoInfo( + area: String, + year: Int, + semester: String, + sortOption: String + ) { + getToInfoUseCase( + area = area, + year = year, + semester = semester, + sortOption = sortOption + ).onSuccess { data -> + Timber.tag("ㅋㅋ").d("server viewmodel") + updateState( + TodoAddPendingContract.TodoAddPendingReduce.UpdateToDoList( + todoList = data.todoList.map { item -> + ToDoCardModel( + pieceId = item.pieceId, + subjectName = item.subjectName, + examName = item.examName, + studyContents = item.studyContents, + startPage = item.startPage, + finishPage = item.finishPage, + deadline = item.deadline, + remainingDays = item.remainingDays, + cardState = if (currentUiState.selectedItemList.toSet() + .contains(item.pieceId) + ) BbangZipCardState.CHECKED else BbangZipCardState.CHECKABLE + ) + }, + ) + ) } + .onFailure { error -> + Timber.run { + tag("ㅋㅋ").d("server viewmodel fail") + tag("ㅋㅋ").d(error.message) + } + } } +} diff --git a/app/src/main/java/org/android/bbangzip/presentation/util/constant/ToDoConstants.kt b/app/src/main/java/org/android/bbangzip/presentation/util/constant/ToDoConstants.kt index 9e50124b..8654cada 100644 --- a/app/src/main/java/org/android/bbangzip/presentation/util/constant/ToDoConstants.kt +++ b/app/src/main/java/org/android/bbangzip/presentation/util/constant/ToDoConstants.kt @@ -1,5 +1,6 @@ package org.android.bbangzip.presentation.util.constant object ToDoConstants { - const val AREA = "todo" + const val TODO = "todo" + const val PENDING = "pending" } \ No newline at end of file From 78a002ff86185cf6dc2e16336b19a14a56c4edfc Mon Sep 17 00:00:00 2001 From: beom84 Date: Mon, 20 Jan 2025 18:40:19 +0900 Subject: [PATCH 05/16] =?UTF-8?q?[feat]=20#46=20=EC=98=A4=EB=8A=98=20?= =?UTF-8?q?=ED=95=A0=20=EA=B3=B5=EB=B6=80=20=EA=B0=90=EC=B6=94=EA=B8=B0=20?= =?UTF-8?q?API=20=EC=97=B0=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../datasource/remote/HideRemoteDataSource.kt | 15 +++++++++++++ .../data/dto/request/RequestHideDto.kt | 10 +++++++++ .../repositoryImpl/PieceRepositoryImpl.kt | 12 +++++++++- .../bbangzip/data/service/PieceService.kt | 8 +++++++ .../org/android/bbangzip/di/UseCaseModule.kt | 6 +++++ .../repository/remote/PieceRepository.kt | 5 +++++ .../domain/usecase/PostDeletedItemList.kt | 15 +++++++++++++ .../ui/navigator/MainNavigator.kt | 2 +- .../presentation/ui/todo/TodoContract.kt | 2 +- .../presentation/ui/todo/TodoViewModel.kt | 22 +++++++++++++++++-- 10 files changed, 92 insertions(+), 5 deletions(-) create mode 100644 app/src/main/java/org/android/bbangzip/data/datasource/remote/HideRemoteDataSource.kt create mode 100644 app/src/main/java/org/android/bbangzip/data/dto/request/RequestHideDto.kt create mode 100644 app/src/main/java/org/android/bbangzip/domain/usecase/PostDeletedItemList.kt diff --git a/app/src/main/java/org/android/bbangzip/data/datasource/remote/HideRemoteDataSource.kt b/app/src/main/java/org/android/bbangzip/data/datasource/remote/HideRemoteDataSource.kt new file mode 100644 index 00000000..c1a9df2f --- /dev/null +++ b/app/src/main/java/org/android/bbangzip/data/datasource/remote/HideRemoteDataSource.kt @@ -0,0 +1,15 @@ +package org.android.bbangzip.data.datasource.remote + +import org.android.bbangzip.data.dto.request.RequestHideDto +import org.android.bbangzip.data.service.PieceService +import org.android.bbangzip.data.util.base.BaseResponse +import javax.inject.Inject + +class HideRemoteDataSource @Inject +constructor( + private val pieceService: PieceService, +) { + suspend fun postDeletedItemList( + requestHideDto: RequestHideDto + ): BaseResponse = pieceService.postDeletedItemList(requestHideDto = requestHideDto) +} \ No newline at end of file diff --git a/app/src/main/java/org/android/bbangzip/data/dto/request/RequestHideDto.kt b/app/src/main/java/org/android/bbangzip/data/dto/request/RequestHideDto.kt new file mode 100644 index 00000000..b9921347 --- /dev/null +++ b/app/src/main/java/org/android/bbangzip/data/dto/request/RequestHideDto.kt @@ -0,0 +1,10 @@ +package org.android.bbangzip.data.dto.request + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class RequestHideDto( + @SerialName("pieceIds") + val pieceIds: List, +) diff --git a/app/src/main/java/org/android/bbangzip/data/repositoryImpl/PieceRepositoryImpl.kt b/app/src/main/java/org/android/bbangzip/data/repositoryImpl/PieceRepositoryImpl.kt index d3fe9d5a..0ed64cb4 100644 --- a/app/src/main/java/org/android/bbangzip/data/repositoryImpl/PieceRepositoryImpl.kt +++ b/app/src/main/java/org/android/bbangzip/data/repositoryImpl/PieceRepositoryImpl.kt @@ -1,7 +1,9 @@ package org.android.bbangzip.data.repositoryImpl +import org.android.bbangzip.data.datasource.remote.HideRemoteDataSource import org.android.bbangzip.data.datasource.remote.TodayOrdersRemoteDataSource import org.android.bbangzip.data.datasource.remote.TodoRemoteDataSource +import org.android.bbangzip.data.dto.request.RequestHideDto import org.android.bbangzip.domain.model.ToDoInfoEntity import org.android.bbangzip.domain.repository.remote.PieceRepository import javax.inject.Inject @@ -10,7 +12,8 @@ class PieceRepositoryImpl @Inject constructor( private val todayOrdersRemoteDateSource: TodayOrdersRemoteDataSource, - private val todoRemoteDataSource: TodoRemoteDataSource + private val todoRemoteDataSource: TodoRemoteDataSource, + private val hideRemoteDataSource: HideRemoteDataSource ) : PieceRepository { override suspend fun getTodoInfo( area: String, @@ -39,6 +42,13 @@ constructor( sortOption = sortOption ).data?.toTodoCardInfoEntity() ?: ToDoInfoEntity() } + + override suspend fun postDeletedItemList(requestHideDto: RequestHideDto): Result = + runCatching { + hideRemoteDataSource.postDeletedItemList( + requestHideDto = requestHideDto + ) + } } diff --git a/app/src/main/java/org/android/bbangzip/data/service/PieceService.kt b/app/src/main/java/org/android/bbangzip/data/service/PieceService.kt index 0da38618..f6781d61 100644 --- a/app/src/main/java/org/android/bbangzip/data/service/PieceService.kt +++ b/app/src/main/java/org/android/bbangzip/data/service/PieceService.kt @@ -1,9 +1,12 @@ package org.android.bbangzip.data.service +import org.android.bbangzip.data.dto.request.RequestHideDto import org.android.bbangzip.data.dto.response.ResponseTodayOrdersDto import org.android.bbangzip.data.dto.response.ResponseTodoDto import org.android.bbangzip.data.util.base.BaseResponse +import retrofit2.http.Body import retrofit2.http.GET +import retrofit2.http.POST import retrofit2.http.Query interface PieceService { @@ -27,4 +30,9 @@ interface PieceService { @Query("semester") semester: String, @Query("sortOption") sortOption: String ): BaseResponse + + @POST("/api/v1/pieces/hide") + suspend fun postDeletedItemList( + @Body requestHideDto: RequestHideDto + ): BaseResponse } \ No newline at end of file diff --git a/app/src/main/java/org/android/bbangzip/di/UseCaseModule.kt b/app/src/main/java/org/android/bbangzip/di/UseCaseModule.kt index 2f1c6b04..1860b9f2 100644 --- a/app/src/main/java/org/android/bbangzip/di/UseCaseModule.kt +++ b/app/src/main/java/org/android/bbangzip/di/UseCaseModule.kt @@ -9,6 +9,7 @@ import org.android.bbangzip.domain.repository.remote.PieceRepository import org.android.bbangzip.domain.usecase.FetchDummyUseCase import org.android.bbangzip.domain.usecase.GetAddTodoListUseCase import org.android.bbangzip.domain.usecase.GetToInfoUseCase +import org.android.bbangzip.domain.usecase.PostDeletedItemList import javax.inject.Singleton @Module @@ -28,4 +29,9 @@ class UseCaseModule { @Singleton fun providesAddTodoListFetchUseCase(pieceRepository: PieceRepository): GetAddTodoListUseCase = GetAddTodoListUseCase(pieceRepository = pieceRepository) + + @Provides + @Singleton + fun providesDeletedItemListPostUseCase(pieceRepository: PieceRepository): PostDeletedItemList = + PostDeletedItemList(pieceRepository = pieceRepository) } diff --git a/app/src/main/java/org/android/bbangzip/domain/repository/remote/PieceRepository.kt b/app/src/main/java/org/android/bbangzip/domain/repository/remote/PieceRepository.kt index 5b13413b..53248c1d 100644 --- a/app/src/main/java/org/android/bbangzip/domain/repository/remote/PieceRepository.kt +++ b/app/src/main/java/org/android/bbangzip/domain/repository/remote/PieceRepository.kt @@ -1,5 +1,6 @@ package org.android.bbangzip.domain.repository.remote +import org.android.bbangzip.data.dto.request.RequestHideDto import org.android.bbangzip.domain.model.ToDoInfoEntity interface PieceRepository { @@ -15,5 +16,9 @@ interface PieceRepository { semester: String, sortOption: String ): Result + + suspend fun postDeletedItemList( + requestHideDto: RequestHideDto + ) : Result } diff --git a/app/src/main/java/org/android/bbangzip/domain/usecase/PostDeletedItemList.kt b/app/src/main/java/org/android/bbangzip/domain/usecase/PostDeletedItemList.kt new file mode 100644 index 00000000..710fc25c --- /dev/null +++ b/app/src/main/java/org/android/bbangzip/domain/usecase/PostDeletedItemList.kt @@ -0,0 +1,15 @@ +package org.android.bbangzip.domain.usecase + +import org.android.bbangzip.data.dto.request.RequestHideDto +import org.android.bbangzip.domain.repository.remote.PieceRepository + +class PostDeletedItemList( + private val pieceRepository: PieceRepository +) { + suspend operator fun invoke( + requestHideDto: RequestHideDto + ): Result = + pieceRepository.postDeletedItemList( + requestHideDto= requestHideDto + ) +} \ No newline at end of file diff --git a/app/src/main/java/org/android/bbangzip/presentation/ui/navigator/MainNavigator.kt b/app/src/main/java/org/android/bbangzip/presentation/ui/navigator/MainNavigator.kt index 8e819bd2..d5e02f83 100644 --- a/app/src/main/java/org/android/bbangzip/presentation/ui/navigator/MainNavigator.kt +++ b/app/src/main/java/org/android/bbangzip/presentation/ui/navigator/MainNavigator.kt @@ -30,7 +30,7 @@ class MainNavigator( private val currentDestination: NavDestination? @Composable get() = navHostController.currentBackStackEntryAsState().value?.destination - val startDestination = LoginRoute + val startDestination = BottomNavigationType.TODO.route val currentBottomNavigationBarItem: BottomNavigationType? @Composable get() = diff --git a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoContract.kt b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoContract.kt index 870a33e8..a7468679 100644 --- a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoContract.kt +++ b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoContract.kt @@ -125,7 +125,7 @@ class TodoContract { ), ), val pendingCount: Int = 10, - val remainingStudyCount: Int = 0, + val remainingStudyCount: Int = 5, val completeCount: Int = 5, val todoFilterBottomSheetState: Boolean = false, val selectedFilterItem: ToDoFilterType = ToDoFilterType.RECENT, diff --git a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoViewModel.kt b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoViewModel.kt index 7035cacd..9e4471e1 100644 --- a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoViewModel.kt +++ b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoViewModel.kt @@ -5,7 +5,9 @@ import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.viewModelScope import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.launch +import org.android.bbangzip.data.dto.request.RequestHideDto import org.android.bbangzip.domain.usecase.GetToInfoUseCase +import org.android.bbangzip.domain.usecase.PostDeletedItemList import org.android.bbangzip.presentation.component.card.BbangZipCardState import org.android.bbangzip.presentation.model.card.ToDoCardModel import org.android.bbangzip.presentation.type.ToDoScreenType @@ -19,6 +21,7 @@ class TodoViewModel @Inject constructor( private val getToInfoUseCase: GetToInfoUseCase, + private val postDeletedItemList: PostDeletedItemList, savedStateHandle: SavedStateHandle, ) : BaseViewModel( savedStateHandle = savedStateHandle, @@ -50,7 +53,12 @@ constructor( // Filter BottomSheet is TodoContract.TodoEvent.OnFilterBottomSheetItemClicked -> { viewModelScope.launch { - getToDoInfo(area = ToDoConstants.TODO, year = 2025, semester = "1학기", sortOption = event.selectedFilterItem.id) + getToDoInfo( + area = ToDoConstants.TODO, + year = 2025, + semester = "1학기", + sortOption = event.selectedFilterItem.id + ) } updateState(TodoContract.TodoReduce.UpdateFilterType(selectedFilter = event.selectedFilterItem)) updateState( @@ -59,7 +67,6 @@ constructor( ) ) setSideEffect(TodoContract.TodoSideEffect.ShowSnackBar("${event.selectedFilterItem.filter}으로 정렬했어요")) - // TODO index를 이용해 서버로 FetchInfo 보내주기 다시 정렬하기 ㅋㅋ } TodoContract.TodoEvent.OnFilterBottomSheetDismissRequest -> @@ -186,6 +193,9 @@ constructor( TodoContract.TodoEvent.OnItemDeleteButtonClicked -> { // TODO setlectedItemlist 사용해서 서버로 삭제한 card API 전송 + viewModelScope.launch { + postDeletedItemList(selectedItemList = currentUiState.selectedItemList) + } updateState( TodoContract.TodoReduce.UpdateToDoCount( completeCount = currentUiState.completeCount, @@ -381,4 +391,12 @@ constructor( } } } + + private suspend fun postDeletedItemList( + selectedItemList: List + ) { + postDeletedItemList( + requestHideDto = RequestHideDto(pieceIds = selectedItemList) + ).onSuccess { } + } } From dad631fc1e35ed4f45b589f043d19f906cf6d5c7 Mon Sep 17 00:00:00 2001 From: beom84 Date: Mon, 20 Jan 2025 22:50:46 +0900 Subject: [PATCH 06/16] =?UTF-8?q?[feat]=20#46=20=EC=98=A4=EB=8A=98=20?= =?UTF-8?q?=ED=95=A0=20/=20=EB=B0=80=EB=A6=B0=20=ED=95=A0=20=EA=B3=B5?= =?UTF-8?q?=EB=B6=80=20=EC=B6=94=EA=B0=80=20API=20=EC=97=B0=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../remote/AssignToTodayRemoteDataSource.kt | 15 ++++ .../datasource/remote/HideRemoteDataSource.kt | 6 +- ...RequestHideDto.kt => RequestPieceIdDto.kt} | 2 +- .../dto/response/ResponseTodayOrdersDto.kt | 8 +-- .../repositoryImpl/PieceRepositoryImpl.kt | 38 ++++++++--- .../bbangzip/data/service/PieceService.kt | 12 +++- .../org/android/bbangzip/di/UseCaseModule.kt | 12 +++- .../repository/remote/PieceRepository.kt | 8 ++- .../usecase/PostAddTodoItemListUseCase.kt | 15 ++++ ...mList.kt => PostDeletedItemListUseCase.kt} | 8 +-- .../presentation/ui/todo/TodoContract.kt | 2 +- .../presentation/ui/todo/TodoRoute.kt | 23 ++++++- .../presentation/ui/todo/TodoViewModel.kt | 39 +++++------ .../pendingtodoadd/TodoAddPendingRoute.kt | 16 ++++- .../pendingtodoadd/TodoAddPendingViewModel.kt | 61 ++++++++++++----- .../ui/todo/todoadd/TodoAddRoute.kt | 16 ++++- .../ui/todo/todoadd/TodoAddViewModel.kt | 68 +++++++++++-------- 17 files changed, 250 insertions(+), 99 deletions(-) create mode 100644 app/src/main/java/org/android/bbangzip/data/datasource/remote/AssignToTodayRemoteDataSource.kt rename app/src/main/java/org/android/bbangzip/data/dto/request/{RequestHideDto.kt => RequestPieceIdDto.kt} (87%) create mode 100644 app/src/main/java/org/android/bbangzip/domain/usecase/PostAddTodoItemListUseCase.kt rename app/src/main/java/org/android/bbangzip/domain/usecase/{PostDeletedItemList.kt => PostDeletedItemListUseCase.kt} (59%) diff --git a/app/src/main/java/org/android/bbangzip/data/datasource/remote/AssignToTodayRemoteDataSource.kt b/app/src/main/java/org/android/bbangzip/data/datasource/remote/AssignToTodayRemoteDataSource.kt new file mode 100644 index 00000000..682ecefe --- /dev/null +++ b/app/src/main/java/org/android/bbangzip/data/datasource/remote/AssignToTodayRemoteDataSource.kt @@ -0,0 +1,15 @@ +package org.android.bbangzip.data.datasource.remote + +import org.android.bbangzip.data.dto.request.RequestPieceIdDto +import org.android.bbangzip.data.service.PieceService +import org.android.bbangzip.data.util.base.BaseResponse +import javax.inject.Inject + +class AssignToTodayRemoteDataSource @Inject +constructor( + private val pieceService: PieceService, +) { + suspend fun postDeletedItemList( + requestPieceIdDto: RequestPieceIdDto + ): BaseResponse? = pieceService.postAddTodoItemList(requestPieceIdDto = requestPieceIdDto) +} \ No newline at end of file diff --git a/app/src/main/java/org/android/bbangzip/data/datasource/remote/HideRemoteDataSource.kt b/app/src/main/java/org/android/bbangzip/data/datasource/remote/HideRemoteDataSource.kt index c1a9df2f..8754182a 100644 --- a/app/src/main/java/org/android/bbangzip/data/datasource/remote/HideRemoteDataSource.kt +++ b/app/src/main/java/org/android/bbangzip/data/datasource/remote/HideRemoteDataSource.kt @@ -1,6 +1,6 @@ package org.android.bbangzip.data.datasource.remote -import org.android.bbangzip.data.dto.request.RequestHideDto +import org.android.bbangzip.data.dto.request.RequestPieceIdDto import org.android.bbangzip.data.service.PieceService import org.android.bbangzip.data.util.base.BaseResponse import javax.inject.Inject @@ -10,6 +10,6 @@ constructor( private val pieceService: PieceService, ) { suspend fun postDeletedItemList( - requestHideDto: RequestHideDto - ): BaseResponse = pieceService.postDeletedItemList(requestHideDto = requestHideDto) + requestPieceIdDto: RequestPieceIdDto + ): BaseResponse? = pieceService.postDeletedItemList(requestPieceIdDto = requestPieceIdDto) } \ No newline at end of file diff --git a/app/src/main/java/org/android/bbangzip/data/dto/request/RequestHideDto.kt b/app/src/main/java/org/android/bbangzip/data/dto/request/RequestPieceIdDto.kt similarity index 87% rename from app/src/main/java/org/android/bbangzip/data/dto/request/RequestHideDto.kt rename to app/src/main/java/org/android/bbangzip/data/dto/request/RequestPieceIdDto.kt index b9921347..21ec1b6e 100644 --- a/app/src/main/java/org/android/bbangzip/data/dto/request/RequestHideDto.kt +++ b/app/src/main/java/org/android/bbangzip/data/dto/request/RequestPieceIdDto.kt @@ -4,7 +4,7 @@ import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable -data class RequestHideDto( +data class RequestPieceIdDto( @SerialName("pieceIds") val pieceIds: List, ) diff --git a/app/src/main/java/org/android/bbangzip/data/dto/response/ResponseTodayOrdersDto.kt b/app/src/main/java/org/android/bbangzip/data/dto/response/ResponseTodayOrdersDto.kt index 8a56d6d9..5b51f158 100644 --- a/app/src/main/java/org/android/bbangzip/data/dto/response/ResponseTodayOrdersDto.kt +++ b/app/src/main/java/org/android/bbangzip/data/dto/response/ResponseTodayOrdersDto.kt @@ -9,13 +9,13 @@ import org.android.bbangzip.domain.model.ToDoInfoEntity @Serializable data class ResponseTodayOrdersDto( @SerialName("completeCount") - val completeCount: Int, + val completeCount: Int?, @SerialName("todoPiecesList") val todayList: List, @SerialName("pendingCount") val pendingCount: Int, @SerialName("todayCount") - val todayCount: Int, + val todayCount: Int?, ) { fun toTodoInfoEntity() = ToDoInfoEntity( @@ -23,8 +23,8 @@ data class ResponseTodayOrdersDto( todoItem.toTodoCardEntity() }, pendingCount = pendingCount, - remainingStudyCount = todayCount, - completeCount = completeCount + remainingStudyCount = todayCount?:0, + completeCount = completeCount?:0 ) } diff --git a/app/src/main/java/org/android/bbangzip/data/repositoryImpl/PieceRepositoryImpl.kt b/app/src/main/java/org/android/bbangzip/data/repositoryImpl/PieceRepositoryImpl.kt index 0ed64cb4..50fa250e 100644 --- a/app/src/main/java/org/android/bbangzip/data/repositoryImpl/PieceRepositoryImpl.kt +++ b/app/src/main/java/org/android/bbangzip/data/repositoryImpl/PieceRepositoryImpl.kt @@ -1,9 +1,10 @@ package org.android.bbangzip.data.repositoryImpl +import org.android.bbangzip.data.datasource.remote.AssignToTodayRemoteDataSource import org.android.bbangzip.data.datasource.remote.HideRemoteDataSource import org.android.bbangzip.data.datasource.remote.TodayOrdersRemoteDataSource import org.android.bbangzip.data.datasource.remote.TodoRemoteDataSource -import org.android.bbangzip.data.dto.request.RequestHideDto +import org.android.bbangzip.data.dto.request.RequestPieceIdDto import org.android.bbangzip.domain.model.ToDoInfoEntity import org.android.bbangzip.domain.repository.remote.PieceRepository import javax.inject.Inject @@ -13,7 +14,8 @@ class PieceRepositoryImpl constructor( private val todayOrdersRemoteDateSource: TodayOrdersRemoteDataSource, private val todoRemoteDataSource: TodoRemoteDataSource, - private val hideRemoteDataSource: HideRemoteDataSource + private val hideRemoteDataSource: HideRemoteDataSource, + private val assignToTodayRemoteDataSource: AssignToTodayRemoteDataSource ) : PieceRepository { override suspend fun getTodoInfo( area: String, @@ -22,12 +24,16 @@ constructor( sortOption: String ): Result = runCatching { - todayOrdersRemoteDateSource.getTodoInfo( + val response = todayOrdersRemoteDateSource.getTodoInfo( area = area, year = year, semester = semester, sortOption = sortOption - ).data?.toTodoInfoEntity() ?: ToDoInfoEntity() + ) + + val responseData = response.data ?: throw IllegalStateException(response.message ?: "Null Error") + + responseData.toTodoInfoEntity() } override suspend fun getAddTodoList( @@ -36,18 +42,32 @@ constructor( sortOption: String ): Result = runCatching { - todoRemoteDataSource.getAddTodolist( + val response = todoRemoteDataSource.getAddTodolist( year = year, semester = semester, sortOption = sortOption - ).data?.toTodoCardInfoEntity() ?: ToDoInfoEntity() + ) + + val responseData = response.data ?: throw IllegalStateException(response.message ?: "Null Error") + + responseData.toTodoCardInfoEntity() } - override suspend fun postDeletedItemList(requestHideDto: RequestHideDto): Result = + override suspend fun postDeletedItemList(requestPieceIdDto: RequestPieceIdDto): Result = + runCatching { + val response = hideRemoteDataSource.postDeletedItemList( + requestPieceIdDto = requestPieceIdDto + ) + response?:Result.success(Unit) + } + + + override suspend fun postAddTodoItemList(requestPieceIdDto: RequestPieceIdDto): Result = runCatching { - hideRemoteDataSource.postDeletedItemList( - requestHideDto = requestHideDto + val response =assignToTodayRemoteDataSource.postDeletedItemList( + requestPieceIdDto = requestPieceIdDto ) + response?:Result.success(Unit) } } diff --git a/app/src/main/java/org/android/bbangzip/data/service/PieceService.kt b/app/src/main/java/org/android/bbangzip/data/service/PieceService.kt index f6781d61..6d3c32b6 100644 --- a/app/src/main/java/org/android/bbangzip/data/service/PieceService.kt +++ b/app/src/main/java/org/android/bbangzip/data/service/PieceService.kt @@ -1,6 +1,6 @@ package org.android.bbangzip.data.service -import org.android.bbangzip.data.dto.request.RequestHideDto +import org.android.bbangzip.data.dto.request.RequestPieceIdDto import org.android.bbangzip.data.dto.response.ResponseTodayOrdersDto import org.android.bbangzip.data.dto.response.ResponseTodoDto import org.android.bbangzip.data.util.base.BaseResponse @@ -33,6 +33,12 @@ interface PieceService { @POST("/api/v1/pieces/hide") suspend fun postDeletedItemList( - @Body requestHideDto: RequestHideDto - ): BaseResponse + @Body requestPieceIdDto: RequestPieceIdDto + ): BaseResponse? + + @POST("/api/v1/pieces/assign-to-today") + suspend fun postAddTodoItemList( + @Body requestPieceIdDto: RequestPieceIdDto + + ): BaseResponse? } \ No newline at end of file diff --git a/app/src/main/java/org/android/bbangzip/di/UseCaseModule.kt b/app/src/main/java/org/android/bbangzip/di/UseCaseModule.kt index 1860b9f2..b9f0852d 100644 --- a/app/src/main/java/org/android/bbangzip/di/UseCaseModule.kt +++ b/app/src/main/java/org/android/bbangzip/di/UseCaseModule.kt @@ -9,7 +9,8 @@ import org.android.bbangzip.domain.repository.remote.PieceRepository import org.android.bbangzip.domain.usecase.FetchDummyUseCase import org.android.bbangzip.domain.usecase.GetAddTodoListUseCase import org.android.bbangzip.domain.usecase.GetToInfoUseCase -import org.android.bbangzip.domain.usecase.PostDeletedItemList +import org.android.bbangzip.domain.usecase.PostAddTodoItemListUseCase +import org.android.bbangzip.domain.usecase.PostDeletedItemListUseCase import javax.inject.Singleton @Module @@ -32,6 +33,11 @@ class UseCaseModule { @Provides @Singleton - fun providesDeletedItemListPostUseCase(pieceRepository: PieceRepository): PostDeletedItemList = - PostDeletedItemList(pieceRepository = pieceRepository) + fun providesDeletedItemListPostUseCase(pieceRepository: PieceRepository): PostDeletedItemListUseCase = + PostDeletedItemListUseCase(pieceRepository = pieceRepository) + + @Provides + @Singleton + fun providesAddTodoItemListPostUseCase(pieceRepository: PieceRepository): PostAddTodoItemListUseCase = + PostAddTodoItemListUseCase(pieceRepository = pieceRepository) } diff --git a/app/src/main/java/org/android/bbangzip/domain/repository/remote/PieceRepository.kt b/app/src/main/java/org/android/bbangzip/domain/repository/remote/PieceRepository.kt index 53248c1d..736f7e26 100644 --- a/app/src/main/java/org/android/bbangzip/domain/repository/remote/PieceRepository.kt +++ b/app/src/main/java/org/android/bbangzip/domain/repository/remote/PieceRepository.kt @@ -1,6 +1,6 @@ package org.android.bbangzip.domain.repository.remote -import org.android.bbangzip.data.dto.request.RequestHideDto +import org.android.bbangzip.data.dto.request.RequestPieceIdDto import org.android.bbangzip.domain.model.ToDoInfoEntity interface PieceRepository { @@ -18,7 +18,11 @@ interface PieceRepository { ): Result suspend fun postDeletedItemList( - requestHideDto: RequestHideDto + requestPieceIdDto: RequestPieceIdDto + ) : Result + + suspend fun postAddTodoItemList( + requestPieceIdDto: RequestPieceIdDto ) : Result } diff --git a/app/src/main/java/org/android/bbangzip/domain/usecase/PostAddTodoItemListUseCase.kt b/app/src/main/java/org/android/bbangzip/domain/usecase/PostAddTodoItemListUseCase.kt new file mode 100644 index 00000000..e97f6f7d --- /dev/null +++ b/app/src/main/java/org/android/bbangzip/domain/usecase/PostAddTodoItemListUseCase.kt @@ -0,0 +1,15 @@ +package org.android.bbangzip.domain.usecase + +import org.android.bbangzip.data.dto.request.RequestPieceIdDto +import org.android.bbangzip.domain.repository.remote.PieceRepository + +class PostAddTodoItemListUseCase( + private val pieceRepository: PieceRepository +) { + suspend operator fun invoke( + requestPieceIdDto: RequestPieceIdDto + ): Result = + pieceRepository.postAddTodoItemList( + requestPieceIdDto= requestPieceIdDto + ) +} \ No newline at end of file diff --git a/app/src/main/java/org/android/bbangzip/domain/usecase/PostDeletedItemList.kt b/app/src/main/java/org/android/bbangzip/domain/usecase/PostDeletedItemListUseCase.kt similarity index 59% rename from app/src/main/java/org/android/bbangzip/domain/usecase/PostDeletedItemList.kt rename to app/src/main/java/org/android/bbangzip/domain/usecase/PostDeletedItemListUseCase.kt index 710fc25c..88f8104f 100644 --- a/app/src/main/java/org/android/bbangzip/domain/usecase/PostDeletedItemList.kt +++ b/app/src/main/java/org/android/bbangzip/domain/usecase/PostDeletedItemListUseCase.kt @@ -1,15 +1,15 @@ package org.android.bbangzip.domain.usecase -import org.android.bbangzip.data.dto.request.RequestHideDto +import org.android.bbangzip.data.dto.request.RequestPieceIdDto import org.android.bbangzip.domain.repository.remote.PieceRepository -class PostDeletedItemList( +class PostDeletedItemListUseCase( private val pieceRepository: PieceRepository ) { suspend operator fun invoke( - requestHideDto: RequestHideDto + requestPieceIdDto: RequestPieceIdDto ): Result = pieceRepository.postDeletedItemList( - requestHideDto= requestHideDto + requestPieceIdDto= requestPieceIdDto ) } \ No newline at end of file diff --git a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoContract.kt b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoContract.kt index a7468679..95e6b0cc 100644 --- a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoContract.kt +++ b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoContract.kt @@ -131,7 +131,7 @@ class TodoContract { val selectedFilterItem: ToDoFilterType = ToDoFilterType.RECENT, val selectedItemList: List = listOf(), val revertCompleteBottomSheetState: Boolean = false, - val screenType: ToDoScreenType = ToDoScreenType.DEFAULT, + val screenType: ToDoScreenType = ToDoScreenType.EMPTY, ) : BaseContract.State, Parcelable { override fun toParcelable(): Parcelable = this } diff --git a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoRoute.kt b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoRoute.kt index 4857eeef..edb76677 100644 --- a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoRoute.kt +++ b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoRoute.kt @@ -1,16 +1,25 @@ package org.android.bbangzip.presentation.ui.todo +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.material3.CircularProgressIndicator import androidx.compose.material3.SnackbarHostState import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier import androidx.hilt.navigation.compose.hiltViewModel +import androidx.lifecycle.Lifecycle +import androidx.lifecycle.compose.LifecycleEventEffect import androidx.lifecycle.compose.collectAsStateWithLifecycle import kotlinx.coroutines.delay import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.launch +import org.android.bbangzip.ui.theme.BbangZipTheme import java.time.LocalDateTime import java.time.format.DateTimeFormatter import java.util.Locale @@ -49,6 +58,10 @@ fun TodoRoute( } } + LifecycleEventEffect(Lifecycle.Event.ON_RESUME) { + viewModel.setEvent(TodoContract.TodoEvent.Initialize) + } + when (success) { true -> TodoScreen( @@ -98,6 +111,14 @@ fun TodoRoute( }, ) - false -> Text("땡!") + false -> + Box( + modifier = Modifier + .fillMaxSize() + .background(color = BbangZipTheme.colors.staticWhite_FFFFFF), + contentAlignment = Alignment.Center + ) { + CircularProgressIndicator(color = BbangZipTheme.colors.backgroundAccent_FFDAA0) + } } } diff --git a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoViewModel.kt b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoViewModel.kt index 9e4471e1..034fe863 100644 --- a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoViewModel.kt +++ b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoViewModel.kt @@ -5,9 +5,9 @@ import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.viewModelScope import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.launch -import org.android.bbangzip.data.dto.request.RequestHideDto +import org.android.bbangzip.data.dto.request.RequestPieceIdDto import org.android.bbangzip.domain.usecase.GetToInfoUseCase -import org.android.bbangzip.domain.usecase.PostDeletedItemList +import org.android.bbangzip.domain.usecase.PostDeletedItemListUseCase import org.android.bbangzip.presentation.component.card.BbangZipCardState import org.android.bbangzip.presentation.model.card.ToDoCardModel import org.android.bbangzip.presentation.type.ToDoScreenType @@ -20,8 +20,8 @@ import javax.inject.Inject class TodoViewModel @Inject constructor( - private val getToInfoUseCase: GetToInfoUseCase, - private val postDeletedItemList: PostDeletedItemList, + private val getTodoInfoUseCase: GetToInfoUseCase, + private val postDeletedItemListUseCase: PostDeletedItemListUseCase, savedStateHandle: SavedStateHandle, ) : BaseViewModel( savedStateHandle = savedStateHandle, @@ -53,12 +53,7 @@ constructor( // Filter BottomSheet is TodoContract.TodoEvent.OnFilterBottomSheetItemClicked -> { viewModelScope.launch { - getToDoInfo( - area = ToDoConstants.TODO, - year = 2025, - semester = "1학기", - sortOption = event.selectedFilterItem.id - ) + initDataLoad() } updateState(TodoContract.TodoReduce.UpdateFilterType(selectedFilter = event.selectedFilterItem)) updateState( @@ -202,7 +197,12 @@ constructor( remainingStudyCount = currentUiState.remainingStudyCount - currentUiState.selectedItemList.size, ), ) - if (currentUiState.remainingStudyCount != 0) { + updateState( + TodoContract.TodoReduce.UpdatePendingToDoCount( + pendingCount = currentUiState.pendingCount + currentUiState.selectedItemList.size + ), + ) + if (currentUiState.remainingStudyCount - currentUiState.selectedItemList.size != 0) { updateState(TodoContract.TodoReduce.DeleteToDoListItems) updateState( TodoContract.TodoReduce.UpdateToDoListCardState( @@ -342,7 +342,7 @@ constructor( private suspend fun initDataLoad() { getToDoInfo( - area = "todo", + area = ToDoConstants.TODO, year = 2025, semester = "1학기", sortOption = currentUiState.selectedFilterItem.id @@ -355,13 +355,13 @@ constructor( semester: String, sortOption: String ) { - getToInfoUseCase( + getTodoInfoUseCase( area = area, year = year, semester = semester, sortOption = sortOption ).onSuccess { data -> - Timber.tag("ㅋㅋ").d("server viewmodel") + Timber.tag("todayOrders").d("server viewmodel") updateState( TodoContract.TodoReduce.UpdateToDoInfo( todoList = data.todoList.map { item -> @@ -385,18 +385,15 @@ constructor( ) } .onFailure { error -> - Timber.run { - tag("ㅋㅋ").d("server viewmodel fail") - tag("ㅋㅋ").d(error.message) - } + Timber.tag("todayOrders").d(error.message) } } private suspend fun postDeletedItemList( selectedItemList: List ) { - postDeletedItemList( - requestHideDto = RequestHideDto(pieceIds = selectedItemList) - ).onSuccess { } + postDeletedItemListUseCase( + requestPieceIdDto = RequestPieceIdDto(pieceIds = selectedItemList) + ).onSuccess { } } } diff --git a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/pendingtodoadd/TodoAddPendingRoute.kt b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/pendingtodoadd/TodoAddPendingRoute.kt index 996e2123..3eaa003f 100644 --- a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/pendingtodoadd/TodoAddPendingRoute.kt +++ b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/pendingtodoadd/TodoAddPendingRoute.kt @@ -1,16 +1,23 @@ package org.android.bbangzip.presentation.ui.todo.pendingtodoadd +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.material3.CircularProgressIndicator import androidx.compose.material3.SnackbarHostState import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.remember +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle import kotlinx.coroutines.delay import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.launch +import org.android.bbangzip.ui.theme.BbangZipTheme @Composable fun TodoAddPendingRoute( @@ -81,6 +88,13 @@ fun TodoAddPendingRoute( ) false -> - Text("땡!") + Box( + modifier = Modifier + .fillMaxSize() + .background(color = BbangZipTheme.colors.staticWhite_FFFFFF), + contentAlignment = Alignment.Center + ) { + CircularProgressIndicator(color = BbangZipTheme.colors.backgroundAccent_FFDAA0) + } } } diff --git a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/pendingtodoadd/TodoAddPendingViewModel.kt b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/pendingtodoadd/TodoAddPendingViewModel.kt index 10a1f2d2..861b20b4 100644 --- a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/pendingtodoadd/TodoAddPendingViewModel.kt +++ b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/pendingtodoadd/TodoAddPendingViewModel.kt @@ -5,7 +5,9 @@ import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.viewModelScope import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.launch +import org.android.bbangzip.data.dto.request.RequestPieceIdDto import org.android.bbangzip.domain.usecase.GetToInfoUseCase +import org.android.bbangzip.domain.usecase.PostAddTodoItemListUseCase import org.android.bbangzip.presentation.component.card.BbangZipCardState import org.android.bbangzip.presentation.model.card.ToDoCardModel import org.android.bbangzip.presentation.util.base.BaseViewModel @@ -17,13 +19,15 @@ import javax.inject.Inject class TodoAddPendingViewModel @Inject constructor( - private val getToInfoUseCase: GetToInfoUseCase, + private val getTodoInfoUseCase: GetToInfoUseCase, + private val postAddTodoItemListUseCase: PostAddTodoItemListUseCase, savedStateHandle: SavedStateHandle, ) : BaseViewModel( savedStateHandle = savedStateHandle, ) { override fun createInitialState(savedState: Parcelable?): TodoAddPendingContract.TodoAddPendingState { - return savedState as? TodoAddPendingContract.TodoAddPendingState ?: TodoAddPendingContract.TodoAddPendingState() + return savedState as? TodoAddPendingContract.TodoAddPendingState + ?: TodoAddPendingContract.TodoAddPendingState() } init { @@ -54,7 +58,11 @@ constructor( ) is TodoAddPendingContract.TodoAddPendingEvent.OnFilterBottomSheetItemClicked -> { - updateState(TodoAddPendingContract.TodoAddPendingReduce.UpdateFilterType(selectedFilter = event.selectedFilterItem)) + updateState( + TodoAddPendingContract.TodoAddPendingReduce.UpdateFilterType( + selectedFilter = event.selectedFilterItem + ) + ) updateState( TodoAddPendingContract.TodoAddPendingReduce.UpdateToDoFilterBottomSheetState( todoFilterBottomSheetState = false, @@ -65,14 +73,20 @@ constructor( } TodoAddPendingContract.TodoAddPendingEvent.OnItemPlusButtonClicked -> { - // TODO 서버로 보내기 + viewModelScope.launch { + postAddTodoItemList(selectedItemList = currentUiState.selectedItemList) + } setSideEffect(TodoAddPendingContract.TodoAddPendingSideEffect.NavigateToToDo) setSideEffect(TodoAddPendingContract.TodoAddPendingSideEffect.ShowSnackBar("오늘 할 공부를 추가했어요!")) } is TodoAddPendingContract.TodoAddPendingEvent.OnToDoCardClicked -> { if (event.cardState == BbangZipCardState.CHECKED) { - updateState(TodoAddPendingContract.TodoAddPendingReduce.UpdateSelectedItemList(pieceId = event.pieceId)) + updateState( + TodoAddPendingContract.TodoAddPendingReduce.UpdateSelectedItemList( + pieceId = event.pieceId + ) + ) updateState( TodoAddPendingContract.TodoAddPendingReduce.UpdateCardState( pieceId = event.pieceId, @@ -80,7 +94,11 @@ constructor( ), ) } else { - updateState(TodoAddPendingContract.TodoAddPendingReduce.DeleteSelectedItemList(pieceId = event.pieceId)) + updateState( + TodoAddPendingContract.TodoAddPendingReduce.DeleteSelectedItemList( + pieceId = event.pieceId + ) + ) updateState( TodoAddPendingContract.TodoAddPendingReduce.UpdateCardState( pieceId = event.pieceId, @@ -148,7 +166,7 @@ constructor( private suspend fun initDataLoad() { getToDoInfo( - area = "todo", + area = ToDoConstants.PENDING, year = 2025, semester = "1학기", sortOption = currentUiState.selectedFilter.id @@ -161,13 +179,13 @@ constructor( semester: String, sortOption: String ) { - getToInfoUseCase( + getTodoInfoUseCase( area = area, year = year, semester = semester, sortOption = sortOption ).onSuccess { data -> - Timber.tag("ㅋㅋ").d("server viewmodel") + Timber.tag("todayOrders").d("${currentUiState.selectedItemList}") updateState( TodoAddPendingContract.TodoAddPendingReduce.UpdateToDoList( todoList = data.todoList.map { item -> @@ -180,19 +198,26 @@ constructor( finishPage = item.finishPage, deadline = item.deadline, remainingDays = item.remainingDays, - cardState = if (currentUiState.selectedItemList.toSet() - .contains(item.pieceId) - ) BbangZipCardState.CHECKED else BbangZipCardState.CHECKABLE + cardState = BbangZipCardState.CHECKABLE ) }, ) ) + }.onFailure { error -> + Timber.tag("todayOrders").e(error.message) + } + } + + private suspend fun postAddTodoItemList( + selectedItemList: List + ) { + postAddTodoItemListUseCase( + requestPieceIdDto = RequestPieceIdDto(pieceIds = selectedItemList) + ).onSuccess { + Timber.tag("postAdd").d("성공") + }.onFailure { error -> + Timber.tag("postAdd").d(error.message) } - .onFailure { error -> - Timber.run { - tag("ㅋㅋ").d("server viewmodel fail") - tag("ㅋㅋ").d(error.message) - } - } } } + diff --git a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/todoadd/TodoAddRoute.kt b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/todoadd/TodoAddRoute.kt index 4fc91755..71015d28 100644 --- a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/todoadd/TodoAddRoute.kt +++ b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/todoadd/TodoAddRoute.kt @@ -1,16 +1,23 @@ package org.android.bbangzip.presentation.ui.todo.todoadd +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.material3.CircularProgressIndicator import androidx.compose.material3.SnackbarHostState import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.remember +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle import kotlinx.coroutines.delay import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.launch +import org.android.bbangzip.ui.theme.BbangZipTheme @Composable fun TodoAddRoute( @@ -81,6 +88,13 @@ fun TodoAddRoute( ) false -> - Text("땡!") + Box( + modifier = Modifier + .fillMaxSize() + .background(color = BbangZipTheme.colors.staticWhite_FFFFFF), + contentAlignment = Alignment.Center + ) { + CircularProgressIndicator(color = BbangZipTheme.colors.backgroundAccent_FFDAA0) + } } } diff --git a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/todoadd/TodoAddViewModel.kt b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/todoadd/TodoAddViewModel.kt index ed166160..36b05581 100644 --- a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/todoadd/TodoAddViewModel.kt +++ b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/todoadd/TodoAddViewModel.kt @@ -5,7 +5,9 @@ import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.viewModelScope import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.launch +import org.android.bbangzip.data.dto.request.RequestPieceIdDto import org.android.bbangzip.domain.usecase.GetAddTodoListUseCase +import org.android.bbangzip.domain.usecase.PostAddTodoItemListUseCase import org.android.bbangzip.presentation.component.card.BbangZipCardState import org.android.bbangzip.presentation.model.card.ToDoCardModel import org.android.bbangzip.presentation.util.base.BaseViewModel @@ -17,6 +19,7 @@ class TodoAddViewModel @Inject constructor( private val getAddTodoListUseCase: GetAddTodoListUseCase, + private val postAddTodoItemListUseCase: PostAddTodoItemListUseCase, savedStateHandle: SavedStateHandle, ) : BaseViewModel( savedStateHandle = savedStateHandle, @@ -59,7 +62,7 @@ constructor( semester = "1학기", sortOption = event.selectedFilterItem.id ) - }.isCompleted + } updateState(TodoAddContract.TodoAddReduce.UpdateFilterType(selectedFilter = event.selectedFilterItem)) updateState( TodoAddContract.TodoAddReduce.UpdateToDoFilterBottomSheetState( @@ -72,6 +75,9 @@ constructor( TodoAddContract.TodoAddEvent.OnItemPlusButtonClicked -> { // TODO 서버로 보내기 + viewModelScope.launch { + postAddTodoItemList(selectedItemList = currentUiState.selectedItemList) + } setSideEffect(TodoAddContract.TodoAddSideEffect.NavigateToToDo) setSideEffect(TodoAddContract.TodoAddSideEffect.ShowSnackBar("오늘 할 공부를 추가했어요!")) } @@ -161,35 +167,43 @@ constructor( year = year, semester = semester, sortOption = sortOption - ) - .onSuccess { data -> - Timber.tag("ㅋㅋ").d("server viewmodel") - updateState( - TodoAddContract.TodoAddReduce.UpdateToDoList( - todoList = data.todoList.map { item -> - ToDoCardModel( - pieceId = item.pieceId, - subjectName = item.subjectName, - examName = item.examName, - studyContents = item.studyContents, - startPage = item.startPage, - finishPage = item.finishPage, - deadline = item.deadline, - remainingDays = item.remainingDays, - cardState = if (currentUiState.selectedItemList.toSet() - .contains(item.pieceId) - ) BbangZipCardState.CHECKED else BbangZipCardState.CHECKABLE - ) - }, - ) + ).onSuccess { data -> + Timber.tag("todo").d("server viewmodel") + updateState( + TodoAddContract.TodoAddReduce.UpdateToDoList( + todoList = data.todoList.map { item -> + ToDoCardModel( + pieceId = item.pieceId, + subjectName = item.subjectName, + examName = item.examName, + studyContents = item.studyContents, + startPage = item.startPage, + finishPage = item.finishPage, + deadline = item.deadline, + remainingDays = item.remainingDays, + cardState = if (currentUiState.selectedItemList.toSet() + .contains(item.pieceId) + ) BbangZipCardState.CHECKED else BbangZipCardState.CHECKABLE + ) + }, ) - } + ) + } .onFailure { error -> - Timber.run { - tag("ㅋㅋ").d(error.message) - } - + Timber.tag("todo").d(error.message) } } + + private suspend fun postAddTodoItemList( + selectedItemList: List + ) { + postAddTodoItemListUseCase( + requestPieceIdDto = RequestPieceIdDto(pieceIds = selectedItemList) + ).onSuccess { + Timber.tag("assignToToday").d("server viewmodel") + }.onFailure { error -> + Timber.tag("assignToToday").d(error.message) + } + } } From 4c222f638f379b4000aee214a2be6ec37e9a669c Mon Sep 17 00:00:00 2001 From: beom84 Date: Mon, 20 Jan 2025 23:37:20 +0900 Subject: [PATCH 07/16] =?UTF-8?q?[feat]=20#46=20=EA=B3=B5=EB=B6=80=20?= =?UTF-8?q?=EC=A1=B0=EA=B0=81=20=EC=99=84=EB=A3=8C=20API=20=EC=97=B0?= =?UTF-8?q?=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../remote/AssignToTodayRemoteDataSource.kt | 2 +- .../datasource/remote/HideRemoteDataSource.kt | 2 +- .../remote/MarkDoneRemoteDataStore.kt | 16 +++++++ .../data/dto/response/ResponseMarkDoneDto.kt | 44 +++++++++++++++++++ .../repositoryImpl/PieceRepositoryImpl.kt | 26 ++++++++--- .../bbangzip/data/service/PieceService.kt | 17 ++++--- .../org/android/bbangzip/di/UseCaseModule.kt | 6 +++ .../domain/model/BadgeCardListEntity.kt | 13 ++++++ .../repository/remote/PieceRepository.kt | 7 +++ .../usecase/PostCompleteCardIdUseCase.kt | 18 ++++++++ .../presentation/ui/todo/TodoViewModel.kt | 28 +++++++++++- 11 files changed, 162 insertions(+), 17 deletions(-) create mode 100644 app/src/main/java/org/android/bbangzip/data/datasource/remote/MarkDoneRemoteDataStore.kt create mode 100644 app/src/main/java/org/android/bbangzip/data/dto/response/ResponseMarkDoneDto.kt create mode 100644 app/src/main/java/org/android/bbangzip/domain/model/BadgeCardListEntity.kt create mode 100644 app/src/main/java/org/android/bbangzip/domain/usecase/PostCompleteCardIdUseCase.kt diff --git a/app/src/main/java/org/android/bbangzip/data/datasource/remote/AssignToTodayRemoteDataSource.kt b/app/src/main/java/org/android/bbangzip/data/datasource/remote/AssignToTodayRemoteDataSource.kt index 682ecefe..9b0ef1bb 100644 --- a/app/src/main/java/org/android/bbangzip/data/datasource/remote/AssignToTodayRemoteDataSource.kt +++ b/app/src/main/java/org/android/bbangzip/data/datasource/remote/AssignToTodayRemoteDataSource.kt @@ -11,5 +11,5 @@ constructor( ) { suspend fun postDeletedItemList( requestPieceIdDto: RequestPieceIdDto - ): BaseResponse? = pieceService.postAddTodoItemList(requestPieceIdDto = requestPieceIdDto) + ): BaseResponse = pieceService.postAddTodoItemList(requestPieceIdDto = requestPieceIdDto) } \ No newline at end of file diff --git a/app/src/main/java/org/android/bbangzip/data/datasource/remote/HideRemoteDataSource.kt b/app/src/main/java/org/android/bbangzip/data/datasource/remote/HideRemoteDataSource.kt index 8754182a..9dfda49e 100644 --- a/app/src/main/java/org/android/bbangzip/data/datasource/remote/HideRemoteDataSource.kt +++ b/app/src/main/java/org/android/bbangzip/data/datasource/remote/HideRemoteDataSource.kt @@ -11,5 +11,5 @@ constructor( ) { suspend fun postDeletedItemList( requestPieceIdDto: RequestPieceIdDto - ): BaseResponse? = pieceService.postDeletedItemList(requestPieceIdDto = requestPieceIdDto) + ): BaseResponse = pieceService.postDeletedItemList(requestPieceIdDto = requestPieceIdDto) } \ No newline at end of file diff --git a/app/src/main/java/org/android/bbangzip/data/datasource/remote/MarkDoneRemoteDataStore.kt b/app/src/main/java/org/android/bbangzip/data/datasource/remote/MarkDoneRemoteDataStore.kt new file mode 100644 index 00000000..8c003074 --- /dev/null +++ b/app/src/main/java/org/android/bbangzip/data/datasource/remote/MarkDoneRemoteDataStore.kt @@ -0,0 +1,16 @@ +package org.android.bbangzip.data.datasource.remote + +import org.android.bbangzip.data.dto.request.RequestMarkDoneDto +import org.android.bbangzip.data.dto.response.ResponseMarkDoneDto +import org.android.bbangzip.data.service.PieceService +import org.android.bbangzip.data.util.base.BaseResponse +import javax.inject.Inject + +class MarkDoneRemoteDataStore @Inject +constructor( + private val pieceService: PieceService, +) { + suspend fun postCompleteCardId( + pieceId:Int , requestMarkDoneDto: RequestMarkDoneDto + ): BaseResponse = pieceService.postCompleteCardId(pieceId = pieceId, requestMarkDoneDto = requestMarkDoneDto) +} diff --git a/app/src/main/java/org/android/bbangzip/data/dto/response/ResponseMarkDoneDto.kt b/app/src/main/java/org/android/bbangzip/data/dto/response/ResponseMarkDoneDto.kt new file mode 100644 index 00000000..3ab48018 --- /dev/null +++ b/app/src/main/java/org/android/bbangzip/data/dto/response/ResponseMarkDoneDto.kt @@ -0,0 +1,44 @@ +package org.android.bbangzip.data.dto.response + + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +import org.android.bbangzip.domain.model.BadgeCardEntity +import org.android.bbangzip.domain.model.BadgeCardListEntity + +@Serializable +data class ResponseMarkDoneDto( + @SerialName("badges") + val badges: List?, + @SerialName("completeCounts") + val completeCounts: Int, + @SerialName("todayCounts") + val todayCounts: Int +){ + fun toBadgeCardListEntity() = + BadgeCardListEntity( + badgeCardList = + badges?.map { item -> + item.toBadgeCardEntity() + } ?: listOf() + + + ) +} + +@Serializable +data class Badge( + @SerialName("badgeImage") + val badgeImage: String, + @SerialName("badgeName") + val badgeName: String, + @SerialName("hashTags") + val hashTags: List +){ + fun toBadgeCardEntity() = + BadgeCardEntity( + badgeImage = badgeImage, + badgeName = badgeName, + hashTags = hashTags + ) +} \ No newline at end of file diff --git a/app/src/main/java/org/android/bbangzip/data/repositoryImpl/PieceRepositoryImpl.kt b/app/src/main/java/org/android/bbangzip/data/repositoryImpl/PieceRepositoryImpl.kt index 50fa250e..57ca381d 100644 --- a/app/src/main/java/org/android/bbangzip/data/repositoryImpl/PieceRepositoryImpl.kt +++ b/app/src/main/java/org/android/bbangzip/data/repositoryImpl/PieceRepositoryImpl.kt @@ -2,9 +2,13 @@ package org.android.bbangzip.data.repositoryImpl import org.android.bbangzip.data.datasource.remote.AssignToTodayRemoteDataSource import org.android.bbangzip.data.datasource.remote.HideRemoteDataSource +import org.android.bbangzip.data.datasource.remote.MarkDoneRemoteDataStore import org.android.bbangzip.data.datasource.remote.TodayOrdersRemoteDataSource import org.android.bbangzip.data.datasource.remote.TodoRemoteDataSource +import org.android.bbangzip.data.dto.request.RequestMarkDoneDto import org.android.bbangzip.data.dto.request.RequestPieceIdDto +import org.android.bbangzip.domain.model.BadgeCardEntity +import org.android.bbangzip.domain.model.BadgeCardListEntity import org.android.bbangzip.domain.model.ToDoInfoEntity import org.android.bbangzip.domain.repository.remote.PieceRepository import javax.inject.Inject @@ -15,7 +19,8 @@ constructor( private val todayOrdersRemoteDateSource: TodayOrdersRemoteDataSource, private val todoRemoteDataSource: TodoRemoteDataSource, private val hideRemoteDataSource: HideRemoteDataSource, - private val assignToTodayRemoteDataSource: AssignToTodayRemoteDataSource + private val assignToTodayRemoteDataSource: AssignToTodayRemoteDataSource, + private val markDoneRemoteDataStore: MarkDoneRemoteDataStore ) : PieceRepository { override suspend fun getTodoInfo( area: String, @@ -54,20 +59,29 @@ constructor( } override suspend fun postDeletedItemList(requestPieceIdDto: RequestPieceIdDto): Result = - runCatching { - val response = hideRemoteDataSource.postDeletedItemList( + runCatching { + val response = hideRemoteDataSource.postDeletedItemList( requestPieceIdDto = requestPieceIdDto ) - response?:Result.success(Unit) + response } override suspend fun postAddTodoItemList(requestPieceIdDto: RequestPieceIdDto): Result = runCatching { - val response =assignToTodayRemoteDataSource.postDeletedItemList( + val response = assignToTodayRemoteDataSource.postDeletedItemList( requestPieceIdDto = requestPieceIdDto ) - response?:Result.success(Unit) + response + } + + override suspend fun postCompleteCardID(pieceId: Int, requestMarkDoneDto: RequestMarkDoneDto): Result = + runCatching { + val response = markDoneRemoteDataStore.postCompleteCardId( + pieceId = pieceId, requestMarkDoneDto = requestMarkDoneDto + ) + val responseData = response.data ?: throw IllegalStateException(response.message ?: "Null Error") + responseData.toBadgeCardListEntity() } } diff --git a/app/src/main/java/org/android/bbangzip/data/service/PieceService.kt b/app/src/main/java/org/android/bbangzip/data/service/PieceService.kt index 6d3c32b6..73a348b1 100644 --- a/app/src/main/java/org/android/bbangzip/data/service/PieceService.kt +++ b/app/src/main/java/org/android/bbangzip/data/service/PieceService.kt @@ -1,12 +1,15 @@ package org.android.bbangzip.data.service +import org.android.bbangzip.data.dto.request.RequestMarkDoneDto import org.android.bbangzip.data.dto.request.RequestPieceIdDto +import org.android.bbangzip.data.dto.response.ResponseMarkDoneDto import org.android.bbangzip.data.dto.response.ResponseTodayOrdersDto import org.android.bbangzip.data.dto.response.ResponseTodoDto import org.android.bbangzip.data.util.base.BaseResponse import retrofit2.http.Body import retrofit2.http.GET import retrofit2.http.POST +import retrofit2.http.Path import retrofit2.http.Query interface PieceService { @@ -18,11 +21,11 @@ interface PieceService { @Query("sortOption") sortOption: String ): BaseResponse -// @POST("/api/v1/pieces/{pieceId}/mark-done") -// suspend fun postCompleteCardId( -// @Path("pieceId") pieceId: Int, -// @Body requestMarkDoneDto: RequestMarkDoneDto -// ) + @POST("/api/v1/pieces/{pieceId}/mark-done") + suspend fun postCompleteCardId( + @Path("pieceId") pieceId: Int, + @Body requestMarkDoneDto: RequestMarkDoneDto + ):BaseResponse @GET("/api/v1/pieces/todo") suspend fun getAddTodoList( @@ -34,11 +37,11 @@ interface PieceService { @POST("/api/v1/pieces/hide") suspend fun postDeletedItemList( @Body requestPieceIdDto: RequestPieceIdDto - ): BaseResponse? + ): BaseResponse @POST("/api/v1/pieces/assign-to-today") suspend fun postAddTodoItemList( @Body requestPieceIdDto: RequestPieceIdDto - ): BaseResponse? + ): BaseResponse } \ No newline at end of file diff --git a/app/src/main/java/org/android/bbangzip/di/UseCaseModule.kt b/app/src/main/java/org/android/bbangzip/di/UseCaseModule.kt index b9f0852d..d572d2c8 100644 --- a/app/src/main/java/org/android/bbangzip/di/UseCaseModule.kt +++ b/app/src/main/java/org/android/bbangzip/di/UseCaseModule.kt @@ -10,6 +10,7 @@ import org.android.bbangzip.domain.usecase.FetchDummyUseCase import org.android.bbangzip.domain.usecase.GetAddTodoListUseCase import org.android.bbangzip.domain.usecase.GetToInfoUseCase import org.android.bbangzip.domain.usecase.PostAddTodoItemListUseCase +import org.android.bbangzip.domain.usecase.PostCompleteCardIdUseCase import org.android.bbangzip.domain.usecase.PostDeletedItemListUseCase import javax.inject.Singleton @@ -40,4 +41,9 @@ class UseCaseModule { @Singleton fun providesAddTodoItemListPostUseCase(pieceRepository: PieceRepository): PostAddTodoItemListUseCase = PostAddTodoItemListUseCase(pieceRepository = pieceRepository) + + @Provides + @Singleton + fun providesCompleteCardIdPostUseCase(pieceRepository: PieceRepository): PostCompleteCardIdUseCase = + PostCompleteCardIdUseCase(pieceRepository = pieceRepository) } diff --git a/app/src/main/java/org/android/bbangzip/domain/model/BadgeCardListEntity.kt b/app/src/main/java/org/android/bbangzip/domain/model/BadgeCardListEntity.kt new file mode 100644 index 00000000..416c0179 --- /dev/null +++ b/app/src/main/java/org/android/bbangzip/domain/model/BadgeCardListEntity.kt @@ -0,0 +1,13 @@ +package org.android.bbangzip.domain.model + +data class BadgeCardListEntity( + val badgeCardList : List +) + +data class BadgeCardEntity( + val badgeImage: String, + val badgeName: String, + val hashTags: List +) + + diff --git a/app/src/main/java/org/android/bbangzip/domain/repository/remote/PieceRepository.kt b/app/src/main/java/org/android/bbangzip/domain/repository/remote/PieceRepository.kt index 736f7e26..10b23bae 100644 --- a/app/src/main/java/org/android/bbangzip/domain/repository/remote/PieceRepository.kt +++ b/app/src/main/java/org/android/bbangzip/domain/repository/remote/PieceRepository.kt @@ -1,6 +1,8 @@ package org.android.bbangzip.domain.repository.remote +import org.android.bbangzip.data.dto.request.RequestMarkDoneDto import org.android.bbangzip.data.dto.request.RequestPieceIdDto +import org.android.bbangzip.domain.model.BadgeCardListEntity import org.android.bbangzip.domain.model.ToDoInfoEntity interface PieceRepository { @@ -24,5 +26,10 @@ interface PieceRepository { suspend fun postAddTodoItemList( requestPieceIdDto: RequestPieceIdDto ) : Result + + suspend fun postCompleteCardID( + pieceId:Int, + requestMarkDoneDto: RequestMarkDoneDto + ):Result } diff --git a/app/src/main/java/org/android/bbangzip/domain/usecase/PostCompleteCardIdUseCase.kt b/app/src/main/java/org/android/bbangzip/domain/usecase/PostCompleteCardIdUseCase.kt new file mode 100644 index 00000000..e1848849 --- /dev/null +++ b/app/src/main/java/org/android/bbangzip/domain/usecase/PostCompleteCardIdUseCase.kt @@ -0,0 +1,18 @@ +package org.android.bbangzip.domain.usecase + +import org.android.bbangzip.data.dto.request.RequestMarkDoneDto +import org.android.bbangzip.domain.model.BadgeCardListEntity +import org.android.bbangzip.domain.repository.remote.PieceRepository + +class PostCompleteCardIdUseCase( + private val pieceRepository: PieceRepository +) { + suspend operator fun invoke( + pieceId: Int, + requestMarkDoneDto: RequestMarkDoneDto + ): Result = + pieceRepository.postCompleteCardID( + pieceId = pieceId, + requestMarkDoneDto = requestMarkDoneDto + ) +} \ No newline at end of file diff --git a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoViewModel.kt b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoViewModel.kt index 034fe863..691bc276 100644 --- a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoViewModel.kt +++ b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoViewModel.kt @@ -5,8 +5,10 @@ import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.viewModelScope import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.launch +import org.android.bbangzip.data.dto.request.RequestMarkDoneDto import org.android.bbangzip.data.dto.request.RequestPieceIdDto import org.android.bbangzip.domain.usecase.GetToInfoUseCase +import org.android.bbangzip.domain.usecase.PostCompleteCardIdUseCase import org.android.bbangzip.domain.usecase.PostDeletedItemListUseCase import org.android.bbangzip.presentation.component.card.BbangZipCardState import org.android.bbangzip.presentation.model.card.ToDoCardModel @@ -22,6 +24,7 @@ class TodoViewModel constructor( private val getTodoInfoUseCase: GetToInfoUseCase, private val postDeletedItemListUseCase: PostDeletedItemListUseCase, + private val postCompleteCardIdUseCase: PostCompleteCardIdUseCase, savedStateHandle: SavedStateHandle, ) : BaseViewModel( savedStateHandle = savedStateHandle, @@ -164,6 +167,9 @@ constructor( remainingStudyCount = currentUiState.remainingStudyCount - 1, ), ) + viewModelScope.launch { + postCompleteCardId(pieceId = event.pieceId) + } TodoContract.TodoSideEffect.ShowSnackBar("공부완료 ! 오늘의 빵굽기 성공!") } else { updateState( @@ -385,7 +391,7 @@ constructor( ) } .onFailure { error -> - Timber.tag("todayOrders").d(error.message) + Timber.tag("todayOrders").d(error) } } @@ -394,6 +400,24 @@ constructor( ) { postDeletedItemListUseCase( requestPieceIdDto = RequestPieceIdDto(pieceIds = selectedItemList) - ).onSuccess { } + ).onSuccess { + Timber.tag("hide").e("삭제 성공!") + }.onFailure { + Timber.tag("hide").e("삭제 성공!") + + } + } + + private suspend fun postCompleteCardId( + pieceId: Int + ) { + postCompleteCardIdUseCase( + pieceId = pieceId, requestMarkDoneDto = RequestMarkDoneDto(isFinished = true) + ).onSuccess { + Timber.tag("markDone").e("완료 성공!") + }.onFailure { error -> + Timber.tag("markDone").e(error) + + } } } From c9672cb5e3b20384c4d2fcca8a999dc277955da9 Mon Sep 17 00:00:00 2001 From: beom84 Date: Tue, 21 Jan 2025 02:47:20 +0900 Subject: [PATCH 08/16] =?UTF-8?q?[feat]=20#46=20=EA=B3=B5=EB=B6=80=20?= =?UTF-8?q?=EC=A1=B0=EA=B0=81=20=EB=AF=B8=EC=99=84=EB=A3=8C=20API=20?= =?UTF-8?q?=EC=97=B0=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../remote/MarkUnDoneRemoteDataStore.kt | 16 +++++++++++ .../data/interceptor/AuthInterceptor.kt | 2 +- .../repositoryImpl/PieceRepositoryImpl.kt | 15 ++++++++-- .../bbangzip/data/service/PieceService.kt | 7 ++++- .../org/android/bbangzip/di/UseCaseModule.kt | 6 ++++ .../repository/remote/PieceRepository.kt | 5 ++++ .../usecase/PostUnCompleteCardIdUseCase.kt | 17 +++++++++++ .../presentation/ui/todo/TodoContract.kt | 2 +- .../presentation/ui/todo/TodoViewModel.kt | 28 ++++++++++++++++--- .../pendingtodoadd/TodoAddPendingViewModel.kt | 21 +++++++------- .../ui/todo/todoadd/TodoAddViewModel.kt | 6 ++-- 11 files changed, 101 insertions(+), 24 deletions(-) create mode 100644 app/src/main/java/org/android/bbangzip/data/datasource/remote/MarkUnDoneRemoteDataStore.kt create mode 100644 app/src/main/java/org/android/bbangzip/domain/usecase/PostUnCompleteCardIdUseCase.kt diff --git a/app/src/main/java/org/android/bbangzip/data/datasource/remote/MarkUnDoneRemoteDataStore.kt b/app/src/main/java/org/android/bbangzip/data/datasource/remote/MarkUnDoneRemoteDataStore.kt new file mode 100644 index 00000000..6880ba97 --- /dev/null +++ b/app/src/main/java/org/android/bbangzip/data/datasource/remote/MarkUnDoneRemoteDataStore.kt @@ -0,0 +1,16 @@ +package org.android.bbangzip.data.datasource.remote + +import org.android.bbangzip.data.dto.request.RequestMarkDoneDto +import org.android.bbangzip.data.service.PieceService +import org.android.bbangzip.data.util.base.BaseResponse +import javax.inject.Inject + +class MarkUnDoneRemoteDataStore @Inject +constructor( + private val pieceService: PieceService, +) { + suspend fun postUnCompleteCardId( + pieceId: Int, + requestMarkDoneDto: RequestMarkDoneDto + ): BaseResponse = pieceService.postUnCompleteCardId(pieceId = pieceId, requestMarkDoneDto = requestMarkDoneDto) +} \ No newline at end of file diff --git a/app/src/main/java/org/android/bbangzip/data/interceptor/AuthInterceptor.kt b/app/src/main/java/org/android/bbangzip/data/interceptor/AuthInterceptor.kt index 5058d3a2..122e28ac 100644 --- a/app/src/main/java/org/android/bbangzip/data/interceptor/AuthInterceptor.kt +++ b/app/src/main/java/org/android/bbangzip/data/interceptor/AuthInterceptor.kt @@ -23,6 +23,6 @@ class AuthInterceptor } companion object { - const val ACCESS_TOKEN = "accessToken" + const val ACCESS_TOKEN = "Authorization" } } diff --git a/app/src/main/java/org/android/bbangzip/data/repositoryImpl/PieceRepositoryImpl.kt b/app/src/main/java/org/android/bbangzip/data/repositoryImpl/PieceRepositoryImpl.kt index 57ca381d..b22a79ad 100644 --- a/app/src/main/java/org/android/bbangzip/data/repositoryImpl/PieceRepositoryImpl.kt +++ b/app/src/main/java/org/android/bbangzip/data/repositoryImpl/PieceRepositoryImpl.kt @@ -3,11 +3,11 @@ package org.android.bbangzip.data.repositoryImpl import org.android.bbangzip.data.datasource.remote.AssignToTodayRemoteDataSource import org.android.bbangzip.data.datasource.remote.HideRemoteDataSource import org.android.bbangzip.data.datasource.remote.MarkDoneRemoteDataStore +import org.android.bbangzip.data.datasource.remote.MarkUnDoneRemoteDataStore import org.android.bbangzip.data.datasource.remote.TodayOrdersRemoteDataSource import org.android.bbangzip.data.datasource.remote.TodoRemoteDataSource import org.android.bbangzip.data.dto.request.RequestMarkDoneDto import org.android.bbangzip.data.dto.request.RequestPieceIdDto -import org.android.bbangzip.domain.model.BadgeCardEntity import org.android.bbangzip.domain.model.BadgeCardListEntity import org.android.bbangzip.domain.model.ToDoInfoEntity import org.android.bbangzip.domain.repository.remote.PieceRepository @@ -20,7 +20,8 @@ constructor( private val todoRemoteDataSource: TodoRemoteDataSource, private val hideRemoteDataSource: HideRemoteDataSource, private val assignToTodayRemoteDataSource: AssignToTodayRemoteDataSource, - private val markDoneRemoteDataStore: MarkDoneRemoteDataStore + private val markDoneRemoteDataStore: MarkDoneRemoteDataStore, + private val markUnDoneRemoteDataStore: MarkUnDoneRemoteDataStore ) : PieceRepository { override suspend fun getTodoInfo( area: String, @@ -83,6 +84,16 @@ constructor( val responseData = response.data ?: throw IllegalStateException(response.message ?: "Null Error") responseData.toBadgeCardListEntity() } + + override suspend fun postUnCompleteCardId(pieceId: Int,requestMarkDoneDto: RequestMarkDoneDto): Result = + runCatching { + val response = markUnDoneRemoteDataStore.postUnCompleteCardId( + pieceId = pieceId, + requestMarkDoneDto = requestMarkDoneDto + ) + response + } } + diff --git a/app/src/main/java/org/android/bbangzip/data/service/PieceService.kt b/app/src/main/java/org/android/bbangzip/data/service/PieceService.kt index 73a348b1..53cb8dc3 100644 --- a/app/src/main/java/org/android/bbangzip/data/service/PieceService.kt +++ b/app/src/main/java/org/android/bbangzip/data/service/PieceService.kt @@ -27,6 +27,12 @@ interface PieceService { @Body requestMarkDoneDto: RequestMarkDoneDto ):BaseResponse + @POST("/api/v1/pieces/{pieceId}/mark-undone") + suspend fun postUnCompleteCardId( + @Path("pieceId") pieceId: Int, + @Body requestMarkDoneDto: RequestMarkDoneDto + ):BaseResponse + @GET("/api/v1/pieces/todo") suspend fun getAddTodoList( @Query("year") year: Int, @@ -42,6 +48,5 @@ interface PieceService { @POST("/api/v1/pieces/assign-to-today") suspend fun postAddTodoItemList( @Body requestPieceIdDto: RequestPieceIdDto - ): BaseResponse } \ No newline at end of file diff --git a/app/src/main/java/org/android/bbangzip/di/UseCaseModule.kt b/app/src/main/java/org/android/bbangzip/di/UseCaseModule.kt index d572d2c8..a0fd7b5a 100644 --- a/app/src/main/java/org/android/bbangzip/di/UseCaseModule.kt +++ b/app/src/main/java/org/android/bbangzip/di/UseCaseModule.kt @@ -12,6 +12,7 @@ import org.android.bbangzip.domain.usecase.GetToInfoUseCase import org.android.bbangzip.domain.usecase.PostAddTodoItemListUseCase import org.android.bbangzip.domain.usecase.PostCompleteCardIdUseCase import org.android.bbangzip.domain.usecase.PostDeletedItemListUseCase +import org.android.bbangzip.domain.usecase.PostUnCompleteCardIdUseCase import javax.inject.Singleton @Module @@ -46,4 +47,9 @@ class UseCaseModule { @Singleton fun providesCompleteCardIdPostUseCase(pieceRepository: PieceRepository): PostCompleteCardIdUseCase = PostCompleteCardIdUseCase(pieceRepository = pieceRepository) + + @Provides + @Singleton + fun providesUnCompleteCardIdPostUseCase(pieceRepository: PieceRepository): PostUnCompleteCardIdUseCase = + PostUnCompleteCardIdUseCase(pieceRepository = pieceRepository) } diff --git a/app/src/main/java/org/android/bbangzip/domain/repository/remote/PieceRepository.kt b/app/src/main/java/org/android/bbangzip/domain/repository/remote/PieceRepository.kt index 10b23bae..216f5c3c 100644 --- a/app/src/main/java/org/android/bbangzip/domain/repository/remote/PieceRepository.kt +++ b/app/src/main/java/org/android/bbangzip/domain/repository/remote/PieceRepository.kt @@ -31,5 +31,10 @@ interface PieceRepository { pieceId:Int, requestMarkDoneDto: RequestMarkDoneDto ):Result + + suspend fun postUnCompleteCardId( + pieceId:Int, + requestMarkDoneDto: RequestMarkDoneDto + ):Result } diff --git a/app/src/main/java/org/android/bbangzip/domain/usecase/PostUnCompleteCardIdUseCase.kt b/app/src/main/java/org/android/bbangzip/domain/usecase/PostUnCompleteCardIdUseCase.kt new file mode 100644 index 00000000..64918c48 --- /dev/null +++ b/app/src/main/java/org/android/bbangzip/domain/usecase/PostUnCompleteCardIdUseCase.kt @@ -0,0 +1,17 @@ +package org.android.bbangzip.domain.usecase + +import org.android.bbangzip.data.dto.request.RequestMarkDoneDto +import org.android.bbangzip.domain.repository.remote.PieceRepository + +class PostUnCompleteCardIdUseCase( + private val pieceRepository: PieceRepository +) { + suspend operator fun invoke( + pieceId: Int, + requestMarkDoneDto: RequestMarkDoneDto + ): Result = + pieceRepository.postUnCompleteCardId( + pieceId = pieceId, + requestMarkDoneDto = requestMarkDoneDto + ) +} \ No newline at end of file diff --git a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoContract.kt b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoContract.kt index 95e6b0cc..a7468679 100644 --- a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoContract.kt +++ b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoContract.kt @@ -131,7 +131,7 @@ class TodoContract { val selectedFilterItem: ToDoFilterType = ToDoFilterType.RECENT, val selectedItemList: List = listOf(), val revertCompleteBottomSheetState: Boolean = false, - val screenType: ToDoScreenType = ToDoScreenType.EMPTY, + val screenType: ToDoScreenType = ToDoScreenType.DEFAULT, ) : BaseContract.State, Parcelable { override fun toParcelable(): Parcelable = this } diff --git a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoViewModel.kt b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoViewModel.kt index 691bc276..5943fa54 100644 --- a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoViewModel.kt +++ b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoViewModel.kt @@ -10,6 +10,7 @@ import org.android.bbangzip.data.dto.request.RequestPieceIdDto import org.android.bbangzip.domain.usecase.GetToInfoUseCase import org.android.bbangzip.domain.usecase.PostCompleteCardIdUseCase import org.android.bbangzip.domain.usecase.PostDeletedItemListUseCase +import org.android.bbangzip.domain.usecase.PostUnCompleteCardIdUseCase import org.android.bbangzip.presentation.component.card.BbangZipCardState import org.android.bbangzip.presentation.model.card.ToDoCardModel import org.android.bbangzip.presentation.type.ToDoScreenType @@ -25,6 +26,7 @@ constructor( private val getTodoInfoUseCase: GetToInfoUseCase, private val postDeletedItemListUseCase: PostDeletedItemListUseCase, private val postCompleteCardIdUseCase: PostCompleteCardIdUseCase, + private val postUnCompleteCardIdUseCase: PostUnCompleteCardIdUseCase, savedStateHandle: SavedStateHandle, ) : BaseViewModel( savedStateHandle = savedStateHandle, @@ -84,6 +86,9 @@ constructor( // revertComplete BottomSheet is TodoContract.TodoEvent.OnRevertCompleteBottomSheetApproveButtonClicked -> { + viewModelScope.launch { + postUnCompleteCardId(event.pieceId) + } updateState( TodoContract.TodoReduce.UpdateCardState( pieceId = event.pieceId, @@ -170,7 +175,7 @@ constructor( viewModelScope.launch { postCompleteCardId(pieceId = event.pieceId) } - TodoContract.TodoSideEffect.ShowSnackBar("공부완료 ! 오늘의 빵굽기 성공!") + setSideEffect(TodoContract.TodoSideEffect.ShowSnackBar("공부완료 ! 오늘의 빵굽기 성공!")) } else { updateState( TodoContract.TodoReduce.UpdateRevertCompleteBottomSheetState( @@ -179,7 +184,6 @@ constructor( ) updateState(TodoContract.TodoReduce.UpdateSelectedItemList(pieceId = event.pieceId)) } - // TODO 서버로 pieceId 이용해서 완료 API 쏘기 } TodoContract.TodoEvent.OnDeleteIconClicked -> { @@ -193,7 +197,6 @@ constructor( } TodoContract.TodoEvent.OnItemDeleteButtonClicked -> { - // TODO setlectedItemlist 사용해서 서버로 삭제한 card API 전송 viewModelScope.launch { postDeletedItemList(selectedItemList = currentUiState.selectedItemList) } @@ -208,7 +211,8 @@ constructor( pendingCount = currentUiState.pendingCount + currentUiState.selectedItemList.size ), ) - if (currentUiState.remainingStudyCount - currentUiState.selectedItemList.size != 0) { + + if (currentUiState.completeCount > 0 || currentUiState.remainingStudyCount - currentUiState.selectedItemList.size != 0) { updateState(TodoContract.TodoReduce.DeleteToDoListItems) updateState( TodoContract.TodoReduce.UpdateToDoListCardState( @@ -220,6 +224,9 @@ constructor( } else { updateState(TodoContract.TodoReduce.UpdateScreenType(screenType = ToDoScreenType.EMPTY)) } + + + updateState(TodoContract.TodoReduce.ResetSelectedItemList) setSideEffect(TodoContract.TodoSideEffect.ShowSnackBar("오늘 할 공부를 삭제했어요")) } @@ -420,4 +427,17 @@ constructor( } } + + private suspend fun postUnCompleteCardId( + pieceId: Int + ) { + postUnCompleteCardIdUseCase( + pieceId = pieceId, requestMarkDoneDto = RequestMarkDoneDto(isFinished = false) + ).onSuccess { + Timber.tag("markDone").e("완료 성공!") + }.onFailure { error -> + Timber.tag("markDone").e(error) + + } + } } diff --git a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/pendingtodoadd/TodoAddPendingViewModel.kt b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/pendingtodoadd/TodoAddPendingViewModel.kt index 861b20b4..b8bb3483 100644 --- a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/pendingtodoadd/TodoAddPendingViewModel.kt +++ b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/pendingtodoadd/TodoAddPendingViewModel.kt @@ -58,6 +58,14 @@ constructor( ) is TodoAddPendingContract.TodoAddPendingEvent.OnFilterBottomSheetItemClicked -> { + viewModelScope.launch { + getToDoInfo( + area = ToDoConstants.PENDING, + year = 2025, + semester = "1학기", + sortOption = event.selectedFilterItem.id + ) + } updateState( TodoAddPendingContract.TodoAddPendingReduce.UpdateFilterType( selectedFilter = event.selectedFilterItem @@ -69,7 +77,6 @@ constructor( ), ) setSideEffect(TodoAddPendingContract.TodoAddPendingSideEffect.ShowTodoAddSnackBar("${event.selectedFilterItem.filter}으로 정렬했어요")) - // TODO 받아오고 다시 정렬해야됨 ㅋㅋ } TodoAddPendingContract.TodoAddPendingEvent.OnItemPlusButtonClicked -> { @@ -129,14 +136,6 @@ constructor( ) is TodoAddPendingContract.TodoAddPendingReduce.UpdateFilterType -> { - viewModelScope.launch { - getToDoInfo( - area = ToDoConstants.PENDING, - year = 2025, - semester = "1학기", - sortOption = reduce.selectedFilter.id - ) - } state.copy( selectedFilter = reduce.selectedFilter, ) @@ -204,7 +203,7 @@ constructor( ) ) }.onFailure { error -> - Timber.tag("todayOrders").e(error.message) + Timber.tag("todayOrders").e(error) } } @@ -216,7 +215,7 @@ constructor( ).onSuccess { Timber.tag("postAdd").d("성공") }.onFailure { error -> - Timber.tag("postAdd").d(error.message) + Timber.tag("postAdd").d(error) } } } diff --git a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/todoadd/TodoAddViewModel.kt b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/todoadd/TodoAddViewModel.kt index 36b05581..63c22e33 100644 --- a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/todoadd/TodoAddViewModel.kt +++ b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/todoadd/TodoAddViewModel.kt @@ -70,11 +70,9 @@ constructor( ), ) setSideEffect(TodoAddContract.TodoAddSideEffect.ShowTodoAddSnackBar("${event.selectedFilterItem.filter}으로 정렬했어요")) - // TODO 받아오고 다시 정렬해야됨 ㅋㅋ } TodoAddContract.TodoAddEvent.OnItemPlusButtonClicked -> { - // TODO 서버로 보내기 viewModelScope.launch { postAddTodoItemList(selectedItemList = currentUiState.selectedItemList) } @@ -190,7 +188,7 @@ constructor( ) } .onFailure { error -> - Timber.tag("todo").d(error.message) + Timber.tag("todo").d(error) } } @@ -202,7 +200,7 @@ constructor( ).onSuccess { Timber.tag("assignToToday").d("server viewmodel") }.onFailure { error -> - Timber.tag("assignToToday").d(error.message) + Timber.tag("assignToToday").d(error) } } } From eb11c749a57c86e7ba280765d0c483474d9efb2a Mon Sep 17 00:00:00 2001 From: beom84 Date: Tue, 21 Jan 2025 02:57:47 +0900 Subject: [PATCH 09/16] =?UTF-8?q?[feat]=20#46=20ktlint=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../remote/AssignToTodayRemoteDataSource.kt | 17 +- .../datasource/remote/HideRemoteDataSource.kt | 17 +- .../remote/MarkDoneRemoteDataStore.kt | 18 +- .../remote/MarkUnDoneRemoteDataStore.kt | 19 +- .../remote/TodayOrdersRemoteDataSource.kt | 34 +- .../datasource/remote/TodoRemoteDataSource.kt | 31 +- .../data/dto/response/ResponseMarkDoneDto.kt | 21 +- .../dto/response/ResponseTodayOrdersDto.kt | 19 +- .../data/dto/response/ResponseTodoDto.kt | 13 +- .../repositoryImpl/PieceRepositoryImpl.kt | 157 ++-- .../bbangzip/data/service/PieceService.kt | 18 +- .../bbangzip/data/util/base/BaseResponse.kt | 4 +- .../domain/model/BadgeCardListEntity.kt | 6 +- .../bbangzip/domain/model/ToDoCardEntity.kt | 2 +- .../repository/remote/PieceRepository.kt | 27 +- .../domain/usecase/GetAddTodoListUseCase.kt | 8 +- .../domain/usecase/GetToInfoUseCase.kt | 8 +- .../usecase/PostAddTodoItemListUseCase.kt | 8 +- .../usecase/PostCompleteCardIdUseCase.kt | 8 +- .../usecase/PostDeletedItemListUseCase.kt | 8 +- .../usecase/PostUnCompleteCardIdUseCase.kt | 8 +- .../component/balloon/BalloonContainer.kt | 2 +- .../ui/navigator/MainNavigator.kt | 1 - .../presentation/ui/todo/TodoContract.kt | 4 +- .../presentation/ui/todo/TodoRoute.kt | 10 +- .../presentation/ui/todo/TodoScreen.kt | 2 + .../presentation/ui/todo/TodoViewModel.kt | 692 +++++++++--------- .../pendingtodoadd/TodoAddPendingContract.kt | 3 +- .../pendingtodoadd/TodoAddPendingRoute.kt | 10 +- .../pendingtodoadd/TodoAddPendingViewModel.kt | 340 ++++----- .../ui/todo/todoadd/TodoAddContract.kt | 3 +- .../ui/todo/todoadd/TodoAddRoute.kt | 10 +- .../ui/todo/todoadd/TodoAddViewModel.kt | 322 ++++---- .../util/constant/DateConstants.kt | 1 - .../util/constant/ToDoConstants.kt | 2 +- 35 files changed, 932 insertions(+), 921 deletions(-) diff --git a/app/src/main/java/org/android/bbangzip/data/datasource/remote/AssignToTodayRemoteDataSource.kt b/app/src/main/java/org/android/bbangzip/data/datasource/remote/AssignToTodayRemoteDataSource.kt index 9b0ef1bb..3790876d 100644 --- a/app/src/main/java/org/android/bbangzip/data/datasource/remote/AssignToTodayRemoteDataSource.kt +++ b/app/src/main/java/org/android/bbangzip/data/datasource/remote/AssignToTodayRemoteDataSource.kt @@ -5,11 +5,12 @@ import org.android.bbangzip.data.service.PieceService import org.android.bbangzip.data.util.base.BaseResponse import javax.inject.Inject -class AssignToTodayRemoteDataSource @Inject -constructor( - private val pieceService: PieceService, -) { - suspend fun postDeletedItemList( - requestPieceIdDto: RequestPieceIdDto - ): BaseResponse = pieceService.postAddTodoItemList(requestPieceIdDto = requestPieceIdDto) -} \ No newline at end of file +class AssignToTodayRemoteDataSource + @Inject + constructor( + private val pieceService: PieceService, + ) { + suspend fun postDeletedItemList( + requestPieceIdDto: RequestPieceIdDto, + ): BaseResponse = pieceService.postAddTodoItemList(requestPieceIdDto = requestPieceIdDto) + } diff --git a/app/src/main/java/org/android/bbangzip/data/datasource/remote/HideRemoteDataSource.kt b/app/src/main/java/org/android/bbangzip/data/datasource/remote/HideRemoteDataSource.kt index 9dfda49e..a3013f5b 100644 --- a/app/src/main/java/org/android/bbangzip/data/datasource/remote/HideRemoteDataSource.kt +++ b/app/src/main/java/org/android/bbangzip/data/datasource/remote/HideRemoteDataSource.kt @@ -5,11 +5,12 @@ import org.android.bbangzip.data.service.PieceService import org.android.bbangzip.data.util.base.BaseResponse import javax.inject.Inject -class HideRemoteDataSource @Inject -constructor( - private val pieceService: PieceService, -) { - suspend fun postDeletedItemList( - requestPieceIdDto: RequestPieceIdDto - ): BaseResponse = pieceService.postDeletedItemList(requestPieceIdDto = requestPieceIdDto) -} \ No newline at end of file +class HideRemoteDataSource + @Inject + constructor( + private val pieceService: PieceService, + ) { + suspend fun postDeletedItemList( + requestPieceIdDto: RequestPieceIdDto, + ): BaseResponse = pieceService.postDeletedItemList(requestPieceIdDto = requestPieceIdDto) + } diff --git a/app/src/main/java/org/android/bbangzip/data/datasource/remote/MarkDoneRemoteDataStore.kt b/app/src/main/java/org/android/bbangzip/data/datasource/remote/MarkDoneRemoteDataStore.kt index 8c003074..715a43f1 100644 --- a/app/src/main/java/org/android/bbangzip/data/datasource/remote/MarkDoneRemoteDataStore.kt +++ b/app/src/main/java/org/android/bbangzip/data/datasource/remote/MarkDoneRemoteDataStore.kt @@ -6,11 +6,13 @@ import org.android.bbangzip.data.service.PieceService import org.android.bbangzip.data.util.base.BaseResponse import javax.inject.Inject -class MarkDoneRemoteDataStore @Inject -constructor( - private val pieceService: PieceService, -) { - suspend fun postCompleteCardId( - pieceId:Int , requestMarkDoneDto: RequestMarkDoneDto - ): BaseResponse = pieceService.postCompleteCardId(pieceId = pieceId, requestMarkDoneDto = requestMarkDoneDto) -} +class MarkDoneRemoteDataStore + @Inject + constructor( + private val pieceService: PieceService, + ) { + suspend fun postCompleteCardId( + pieceId: Int, + requestMarkDoneDto: RequestMarkDoneDto, + ): BaseResponse = pieceService.postCompleteCardId(pieceId = pieceId, requestMarkDoneDto = requestMarkDoneDto) + } diff --git a/app/src/main/java/org/android/bbangzip/data/datasource/remote/MarkUnDoneRemoteDataStore.kt b/app/src/main/java/org/android/bbangzip/data/datasource/remote/MarkUnDoneRemoteDataStore.kt index 6880ba97..f4aa76e4 100644 --- a/app/src/main/java/org/android/bbangzip/data/datasource/remote/MarkUnDoneRemoteDataStore.kt +++ b/app/src/main/java/org/android/bbangzip/data/datasource/remote/MarkUnDoneRemoteDataStore.kt @@ -5,12 +5,13 @@ import org.android.bbangzip.data.service.PieceService import org.android.bbangzip.data.util.base.BaseResponse import javax.inject.Inject -class MarkUnDoneRemoteDataStore @Inject -constructor( - private val pieceService: PieceService, -) { - suspend fun postUnCompleteCardId( - pieceId: Int, - requestMarkDoneDto: RequestMarkDoneDto - ): BaseResponse = pieceService.postUnCompleteCardId(pieceId = pieceId, requestMarkDoneDto = requestMarkDoneDto) -} \ No newline at end of file +class MarkUnDoneRemoteDataStore + @Inject + constructor( + private val pieceService: PieceService, + ) { + suspend fun postUnCompleteCardId( + pieceId: Int, + requestMarkDoneDto: RequestMarkDoneDto, + ): BaseResponse = pieceService.postUnCompleteCardId(pieceId = pieceId, requestMarkDoneDto = requestMarkDoneDto) + } diff --git a/app/src/main/java/org/android/bbangzip/data/datasource/remote/TodayOrdersRemoteDataSource.kt b/app/src/main/java/org/android/bbangzip/data/datasource/remote/TodayOrdersRemoteDataSource.kt index 02a72c28..9dc4b954 100644 --- a/app/src/main/java/org/android/bbangzip/data/datasource/remote/TodayOrdersRemoteDataSource.kt +++ b/app/src/main/java/org/android/bbangzip/data/datasource/remote/TodayOrdersRemoteDataSource.kt @@ -5,19 +5,21 @@ import org.android.bbangzip.data.service.PieceService import org.android.bbangzip.data.util.base.BaseResponse import javax.inject.Inject -class TodayOrdersRemoteDataSource @Inject -constructor( - private val pieceService: PieceService, -) { - suspend fun getTodoInfo( - area: String, - year: Int, - semester: String, - sortOption: String - ): BaseResponse = pieceService.getTodoInfo( - area = area, - year = year, - semester = semester, - sortOption = sortOption - ) -} +class TodayOrdersRemoteDataSource + @Inject + constructor( + private val pieceService: PieceService, + ) { + suspend fun getTodoInfo( + area: String, + year: Int, + semester: String, + sortOption: String, + ): BaseResponse = + pieceService.getTodoInfo( + area = area, + year = year, + semester = semester, + sortOption = sortOption, + ) + } diff --git a/app/src/main/java/org/android/bbangzip/data/datasource/remote/TodoRemoteDataSource.kt b/app/src/main/java/org/android/bbangzip/data/datasource/remote/TodoRemoteDataSource.kt index ea31ae9d..d4fdfaf9 100644 --- a/app/src/main/java/org/android/bbangzip/data/datasource/remote/TodoRemoteDataSource.kt +++ b/app/src/main/java/org/android/bbangzip/data/datasource/remote/TodoRemoteDataSource.kt @@ -1,22 +1,23 @@ package org.android.bbangzip.data.datasource.remote -import org.android.bbangzip.data.dto.response.ResponseTodayOrdersDto import org.android.bbangzip.data.dto.response.ResponseTodoDto import org.android.bbangzip.data.service.PieceService import org.android.bbangzip.data.util.base.BaseResponse import javax.inject.Inject -class TodoRemoteDataSource @Inject -constructor( - private val pieceService: PieceService, -) { - suspend fun getAddTodolist( - year: Int, - semester: String, - sortOption: String - ): BaseResponse = pieceService.getAddTodoList( - year = year, - semester = semester, - sortOption = sortOption - ) -} +class TodoRemoteDataSource + @Inject + constructor( + private val pieceService: PieceService, + ) { + suspend fun getAddTodolist( + year: Int, + semester: String, + sortOption: String, + ): BaseResponse = + pieceService.getAddTodoList( + year = year, + semester = semester, + sortOption = sortOption, + ) + } diff --git a/app/src/main/java/org/android/bbangzip/data/dto/response/ResponseMarkDoneDto.kt b/app/src/main/java/org/android/bbangzip/data/dto/response/ResponseMarkDoneDto.kt index 3ab48018..fe555267 100644 --- a/app/src/main/java/org/android/bbangzip/data/dto/response/ResponseMarkDoneDto.kt +++ b/app/src/main/java/org/android/bbangzip/data/dto/response/ResponseMarkDoneDto.kt @@ -1,6 +1,5 @@ package org.android.bbangzip.data.dto.response - import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import org.android.bbangzip.domain.model.BadgeCardEntity @@ -13,16 +12,14 @@ data class ResponseMarkDoneDto( @SerialName("completeCounts") val completeCounts: Int, @SerialName("todayCounts") - val todayCounts: Int -){ + val todayCounts: Int, +) { fun toBadgeCardListEntity() = BadgeCardListEntity( badgeCardList = - badges?.map { item -> - item.toBadgeCardEntity() - } ?: listOf() - - + badges?.map { item -> + item.toBadgeCardEntity() + } ?: listOf(), ) } @@ -33,12 +30,12 @@ data class Badge( @SerialName("badgeName") val badgeName: String, @SerialName("hashTags") - val hashTags: List -){ + val hashTags: List, +) { fun toBadgeCardEntity() = BadgeCardEntity( badgeImage = badgeImage, badgeName = badgeName, - hashTags = hashTags + hashTags = hashTags, ) -} \ No newline at end of file +} diff --git a/app/src/main/java/org/android/bbangzip/data/dto/response/ResponseTodayOrdersDto.kt b/app/src/main/java/org/android/bbangzip/data/dto/response/ResponseTodayOrdersDto.kt index 5b51f158..c80fe6b3 100644 --- a/app/src/main/java/org/android/bbangzip/data/dto/response/ResponseTodayOrdersDto.kt +++ b/app/src/main/java/org/android/bbangzip/data/dto/response/ResponseTodayOrdersDto.kt @@ -1,6 +1,5 @@ package org.android.bbangzip.data.dto.response - import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import org.android.bbangzip.domain.model.ToDoCardEntity @@ -19,16 +18,16 @@ data class ResponseTodayOrdersDto( ) { fun toTodoInfoEntity() = ToDoInfoEntity( - todoList = todayList.map { todoItem -> - todoItem.toTodoCardEntity() - }, + todoList = + todayList.map { todoItem -> + todoItem.toTodoCardEntity() + }, pendingCount = pendingCount, - remainingStudyCount = todayCount?:0, - completeCount = completeCount?:0 + remainingStudyCount = todayCount ?: 0, + completeCount = completeCount ?: 0, ) } - @Serializable data class TodoInfo( @SerialName("deadline") @@ -48,7 +47,7 @@ data class TodoInfo( @SerialName("studyContents") val studyContents: String, @SerialName("subjectName") - val subjectName: String + val subjectName: String, ) { fun toTodoCardEntity() = ToDoCardEntity( @@ -60,6 +59,6 @@ data class TodoInfo( finishPage = finishPage, deadline = deadline, remainingDays = remainingDays, - isFinished = isFinished + isFinished = isFinished, ) -} \ No newline at end of file +} diff --git a/app/src/main/java/org/android/bbangzip/data/dto/response/ResponseTodoDto.kt b/app/src/main/java/org/android/bbangzip/data/dto/response/ResponseTodoDto.kt index f3d8e408..abaedb5a 100644 --- a/app/src/main/java/org/android/bbangzip/data/dto/response/ResponseTodoDto.kt +++ b/app/src/main/java/org/android/bbangzip/data/dto/response/ResponseTodoDto.kt @@ -10,13 +10,14 @@ data class ResponseTodoDto( @SerialName("todoCount") val todoCount: Int, @SerialName("todoList") - val todoList: List + val todoList: List, ) { fun toTodoCardInfoEntity() = ToDoInfoEntity( - todoList = todoList.map { todoItem -> - todoItem.toTodoCardEntity() - }, + todoList = + todoList.map { todoItem -> + todoItem.toTodoCardEntity() + }, ) } @@ -37,7 +38,7 @@ data class TodoCardInfo( @SerialName("studyContents") val studyContents: String, @SerialName("subjectName") - val subjectName: String + val subjectName: String, ) { fun toTodoCardEntity() = ToDoCardEntity( @@ -50,4 +51,4 @@ data class TodoCardInfo( deadline = deadline, remainingDays = remainingDays, ) -} \ No newline at end of file +} diff --git a/app/src/main/java/org/android/bbangzip/data/repositoryImpl/PieceRepositoryImpl.kt b/app/src/main/java/org/android/bbangzip/data/repositoryImpl/PieceRepositoryImpl.kt index b22a79ad..1bc080f8 100644 --- a/app/src/main/java/org/android/bbangzip/data/repositoryImpl/PieceRepositoryImpl.kt +++ b/app/src/main/java/org/android/bbangzip/data/repositoryImpl/PieceRepositoryImpl.kt @@ -14,86 +14,95 @@ import org.android.bbangzip.domain.repository.remote.PieceRepository import javax.inject.Inject class PieceRepositoryImpl -@Inject -constructor( - private val todayOrdersRemoteDateSource: TodayOrdersRemoteDataSource, - private val todoRemoteDataSource: TodoRemoteDataSource, - private val hideRemoteDataSource: HideRemoteDataSource, - private val assignToTodayRemoteDataSource: AssignToTodayRemoteDataSource, - private val markDoneRemoteDataStore: MarkDoneRemoteDataStore, - private val markUnDoneRemoteDataStore: MarkUnDoneRemoteDataStore -) : PieceRepository { - override suspend fun getTodoInfo( - area: String, - year: Int, - semester: String, - sortOption: String - ): Result = - runCatching { - val response = todayOrdersRemoteDateSource.getTodoInfo( - area = area, - year = year, - semester = semester, - sortOption = sortOption - ) + @Inject + constructor( + private val todayOrdersRemoteDateSource: TodayOrdersRemoteDataSource, + private val todoRemoteDataSource: TodoRemoteDataSource, + private val hideRemoteDataSource: HideRemoteDataSource, + private val assignToTodayRemoteDataSource: AssignToTodayRemoteDataSource, + private val markDoneRemoteDataStore: MarkDoneRemoteDataStore, + private val markUnDoneRemoteDataStore: MarkUnDoneRemoteDataStore, + ) : PieceRepository { + override suspend fun getTodoInfo( + area: String, + year: Int, + semester: String, + sortOption: String, + ): Result = + runCatching { + val response = + todayOrdersRemoteDateSource.getTodoInfo( + area = area, + year = year, + semester = semester, + sortOption = sortOption, + ) - val responseData = response.data ?: throw IllegalStateException(response.message ?: "Null Error") + val responseData = response.data ?: throw IllegalStateException(response.message ?: "Null Error") - responseData.toTodoInfoEntity() - } + responseData.toTodoInfoEntity() + } - override suspend fun getAddTodoList( - year: Int, - semester: String, - sortOption: String - ): Result = - runCatching { - val response = todoRemoteDataSource.getAddTodolist( - year = year, - semester = semester, - sortOption = sortOption - ) + override suspend fun getAddTodoList( + year: Int, + semester: String, + sortOption: String, + ): Result = + runCatching { + val response = + todoRemoteDataSource.getAddTodolist( + year = year, + semester = semester, + sortOption = sortOption, + ) - val responseData = response.data ?: throw IllegalStateException(response.message ?: "Null Error") + val responseData = response.data ?: throw IllegalStateException(response.message ?: "Null Error") - responseData.toTodoCardInfoEntity() - } + responseData.toTodoCardInfoEntity() + } - override suspend fun postDeletedItemList(requestPieceIdDto: RequestPieceIdDto): Result = - runCatching { - val response = hideRemoteDataSource.postDeletedItemList( - requestPieceIdDto = requestPieceIdDto - ) - response - } - - - override suspend fun postAddTodoItemList(requestPieceIdDto: RequestPieceIdDto): Result = - runCatching { - val response = assignToTodayRemoteDataSource.postDeletedItemList( - requestPieceIdDto = requestPieceIdDto - ) - response - } - - override suspend fun postCompleteCardID(pieceId: Int, requestMarkDoneDto: RequestMarkDoneDto): Result = - runCatching { - val response = markDoneRemoteDataStore.postCompleteCardId( - pieceId = pieceId, requestMarkDoneDto = requestMarkDoneDto - ) - val responseData = response.data ?: throw IllegalStateException(response.message ?: "Null Error") - responseData.toBadgeCardListEntity() - } - - override suspend fun postUnCompleteCardId(pieceId: Int,requestMarkDoneDto: RequestMarkDoneDto): Result = - runCatching { - val response = markUnDoneRemoteDataStore.postUnCompleteCardId( - pieceId = pieceId, - requestMarkDoneDto = requestMarkDoneDto - ) - response - } -} + override suspend fun postDeletedItemList(requestPieceIdDto: RequestPieceIdDto): Result = + runCatching { + val response = + hideRemoteDataSource.postDeletedItemList( + requestPieceIdDto = requestPieceIdDto, + ) + response + } + override suspend fun postAddTodoItemList(requestPieceIdDto: RequestPieceIdDto): Result = + runCatching { + val response = + assignToTodayRemoteDataSource.postDeletedItemList( + requestPieceIdDto = requestPieceIdDto, + ) + response + } + override suspend fun postCompleteCardID( + pieceId: Int, + requestMarkDoneDto: RequestMarkDoneDto, + ): Result = + runCatching { + val response = + markDoneRemoteDataStore.postCompleteCardId( + pieceId = pieceId, + requestMarkDoneDto = requestMarkDoneDto, + ) + val responseData = response.data ?: throw IllegalStateException(response.message ?: "Null Error") + responseData.toBadgeCardListEntity() + } + override suspend fun postUnCompleteCardId( + pieceId: Int, + requestMarkDoneDto: RequestMarkDoneDto, + ): Result = + runCatching { + val response = + markUnDoneRemoteDataStore.postUnCompleteCardId( + pieceId = pieceId, + requestMarkDoneDto = requestMarkDoneDto, + ) + response + } + } diff --git a/app/src/main/java/org/android/bbangzip/data/service/PieceService.kt b/app/src/main/java/org/android/bbangzip/data/service/PieceService.kt index 53cb8dc3..ec19d91f 100644 --- a/app/src/main/java/org/android/bbangzip/data/service/PieceService.kt +++ b/app/src/main/java/org/android/bbangzip/data/service/PieceService.kt @@ -18,35 +18,35 @@ interface PieceService { @Query("area") area: String, @Query("year") year: Int, @Query("semester") semester: String, - @Query("sortOption") sortOption: String + @Query("sortOption") sortOption: String, ): BaseResponse @POST("/api/v1/pieces/{pieceId}/mark-done") suspend fun postCompleteCardId( @Path("pieceId") pieceId: Int, - @Body requestMarkDoneDto: RequestMarkDoneDto - ):BaseResponse + @Body requestMarkDoneDto: RequestMarkDoneDto, + ): BaseResponse @POST("/api/v1/pieces/{pieceId}/mark-undone") suspend fun postUnCompleteCardId( @Path("pieceId") pieceId: Int, - @Body requestMarkDoneDto: RequestMarkDoneDto - ):BaseResponse + @Body requestMarkDoneDto: RequestMarkDoneDto, + ): BaseResponse @GET("/api/v1/pieces/todo") suspend fun getAddTodoList( @Query("year") year: Int, @Query("semester") semester: String, - @Query("sortOption") sortOption: String + @Query("sortOption") sortOption: String, ): BaseResponse @POST("/api/v1/pieces/hide") suspend fun postDeletedItemList( - @Body requestPieceIdDto: RequestPieceIdDto + @Body requestPieceIdDto: RequestPieceIdDto, ): BaseResponse @POST("/api/v1/pieces/assign-to-today") suspend fun postAddTodoItemList( - @Body requestPieceIdDto: RequestPieceIdDto + @Body requestPieceIdDto: RequestPieceIdDto, ): BaseResponse -} \ No newline at end of file +} diff --git a/app/src/main/java/org/android/bbangzip/data/util/base/BaseResponse.kt b/app/src/main/java/org/android/bbangzip/data/util/base/BaseResponse.kt index e6b879bc..eb408fc9 100644 --- a/app/src/main/java/org/android/bbangzip/data/util/base/BaseResponse.kt +++ b/app/src/main/java/org/android/bbangzip/data/util/base/BaseResponse.kt @@ -10,5 +10,5 @@ data class BaseResponse( @SerialName("data") val data: T? = null, @SerialName("message") - val message: String? = null -) \ No newline at end of file + val message: String? = null, +) diff --git a/app/src/main/java/org/android/bbangzip/domain/model/BadgeCardListEntity.kt b/app/src/main/java/org/android/bbangzip/domain/model/BadgeCardListEntity.kt index 416c0179..9340e23d 100644 --- a/app/src/main/java/org/android/bbangzip/domain/model/BadgeCardListEntity.kt +++ b/app/src/main/java/org/android/bbangzip/domain/model/BadgeCardListEntity.kt @@ -1,13 +1,11 @@ package org.android.bbangzip.domain.model data class BadgeCardListEntity( - val badgeCardList : List + val badgeCardList: List, ) data class BadgeCardEntity( val badgeImage: String, val badgeName: String, - val hashTags: List + val hashTags: List, ) - - diff --git a/app/src/main/java/org/android/bbangzip/domain/model/ToDoCardEntity.kt b/app/src/main/java/org/android/bbangzip/domain/model/ToDoCardEntity.kt index a717eab8..8be6917f 100644 --- a/app/src/main/java/org/android/bbangzip/domain/model/ToDoCardEntity.kt +++ b/app/src/main/java/org/android/bbangzip/domain/model/ToDoCardEntity.kt @@ -6,7 +6,7 @@ data class ToDoCardEntity( val examName: String = "", val studyContents: String, val startPage: Int = 0, - val finishPage: Int= 0, + val finishPage: Int = 0, val deadline: String = "", val remainingDays: Int = 0, val isFinished: Boolean = false, diff --git a/app/src/main/java/org/android/bbangzip/domain/repository/remote/PieceRepository.kt b/app/src/main/java/org/android/bbangzip/domain/repository/remote/PieceRepository.kt index 216f5c3c..0c25de35 100644 --- a/app/src/main/java/org/android/bbangzip/domain/repository/remote/PieceRepository.kt +++ b/app/src/main/java/org/android/bbangzip/domain/repository/remote/PieceRepository.kt @@ -10,31 +10,30 @@ interface PieceRepository { area: String, year: Int, semester: String, - sortOption: String + sortOption: String, ): Result - suspend fun getAddTodoList( + suspend fun getAddTodoList( year: Int, semester: String, - sortOption: String + sortOption: String, ): Result suspend fun postDeletedItemList( - requestPieceIdDto: RequestPieceIdDto - ) : Result + requestPieceIdDto: RequestPieceIdDto, + ): Result suspend fun postAddTodoItemList( - requestPieceIdDto: RequestPieceIdDto - ) : Result + requestPieceIdDto: RequestPieceIdDto, + ): Result suspend fun postCompleteCardID( - pieceId:Int, - requestMarkDoneDto: RequestMarkDoneDto - ):Result + pieceId: Int, + requestMarkDoneDto: RequestMarkDoneDto, + ): Result suspend fun postUnCompleteCardId( - pieceId:Int, - requestMarkDoneDto: RequestMarkDoneDto - ):Result + pieceId: Int, + requestMarkDoneDto: RequestMarkDoneDto, + ): Result } - diff --git a/app/src/main/java/org/android/bbangzip/domain/usecase/GetAddTodoListUseCase.kt b/app/src/main/java/org/android/bbangzip/domain/usecase/GetAddTodoListUseCase.kt index ec983b2e..585b1020 100644 --- a/app/src/main/java/org/android/bbangzip/domain/usecase/GetAddTodoListUseCase.kt +++ b/app/src/main/java/org/android/bbangzip/domain/usecase/GetAddTodoListUseCase.kt @@ -4,16 +4,16 @@ import org.android.bbangzip.domain.model.ToDoInfoEntity import org.android.bbangzip.domain.repository.remote.PieceRepository class GetAddTodoListUseCase( - private val pieceRepository: PieceRepository + private val pieceRepository: PieceRepository, ) { suspend operator fun invoke( year: Int, semester: String, - sortOption: String + sortOption: String, ): Result = pieceRepository.getAddTodoList( year = year, semester = semester, - sortOption = sortOption + sortOption = sortOption, ) -} \ No newline at end of file +} diff --git a/app/src/main/java/org/android/bbangzip/domain/usecase/GetToInfoUseCase.kt b/app/src/main/java/org/android/bbangzip/domain/usecase/GetToInfoUseCase.kt index a25abfa9..441bc59b 100644 --- a/app/src/main/java/org/android/bbangzip/domain/usecase/GetToInfoUseCase.kt +++ b/app/src/main/java/org/android/bbangzip/domain/usecase/GetToInfoUseCase.kt @@ -4,18 +4,18 @@ import org.android.bbangzip.domain.model.ToDoInfoEntity import org.android.bbangzip.domain.repository.remote.PieceRepository class GetToInfoUseCase( - private val pieceRepository: PieceRepository + private val pieceRepository: PieceRepository, ) { suspend operator fun invoke( area: String, year: Int, semester: String, - sortOption: String + sortOption: String, ): Result = pieceRepository.getTodoInfo( area = area, year = year, semester = semester, - sortOption = sortOption + sortOption = sortOption, ) -} \ No newline at end of file +} diff --git a/app/src/main/java/org/android/bbangzip/domain/usecase/PostAddTodoItemListUseCase.kt b/app/src/main/java/org/android/bbangzip/domain/usecase/PostAddTodoItemListUseCase.kt index e97f6f7d..5597375c 100644 --- a/app/src/main/java/org/android/bbangzip/domain/usecase/PostAddTodoItemListUseCase.kt +++ b/app/src/main/java/org/android/bbangzip/domain/usecase/PostAddTodoItemListUseCase.kt @@ -4,12 +4,12 @@ import org.android.bbangzip.data.dto.request.RequestPieceIdDto import org.android.bbangzip.domain.repository.remote.PieceRepository class PostAddTodoItemListUseCase( - private val pieceRepository: PieceRepository + private val pieceRepository: PieceRepository, ) { suspend operator fun invoke( - requestPieceIdDto: RequestPieceIdDto + requestPieceIdDto: RequestPieceIdDto, ): Result = pieceRepository.postAddTodoItemList( - requestPieceIdDto= requestPieceIdDto + requestPieceIdDto = requestPieceIdDto, ) -} \ No newline at end of file +} diff --git a/app/src/main/java/org/android/bbangzip/domain/usecase/PostCompleteCardIdUseCase.kt b/app/src/main/java/org/android/bbangzip/domain/usecase/PostCompleteCardIdUseCase.kt index e1848849..5ee5cf57 100644 --- a/app/src/main/java/org/android/bbangzip/domain/usecase/PostCompleteCardIdUseCase.kt +++ b/app/src/main/java/org/android/bbangzip/domain/usecase/PostCompleteCardIdUseCase.kt @@ -5,14 +5,14 @@ import org.android.bbangzip.domain.model.BadgeCardListEntity import org.android.bbangzip.domain.repository.remote.PieceRepository class PostCompleteCardIdUseCase( - private val pieceRepository: PieceRepository + private val pieceRepository: PieceRepository, ) { suspend operator fun invoke( pieceId: Int, - requestMarkDoneDto: RequestMarkDoneDto + requestMarkDoneDto: RequestMarkDoneDto, ): Result = pieceRepository.postCompleteCardID( pieceId = pieceId, - requestMarkDoneDto = requestMarkDoneDto + requestMarkDoneDto = requestMarkDoneDto, ) -} \ No newline at end of file +} diff --git a/app/src/main/java/org/android/bbangzip/domain/usecase/PostDeletedItemListUseCase.kt b/app/src/main/java/org/android/bbangzip/domain/usecase/PostDeletedItemListUseCase.kt index 88f8104f..047b9a61 100644 --- a/app/src/main/java/org/android/bbangzip/domain/usecase/PostDeletedItemListUseCase.kt +++ b/app/src/main/java/org/android/bbangzip/domain/usecase/PostDeletedItemListUseCase.kt @@ -4,12 +4,12 @@ import org.android.bbangzip.data.dto.request.RequestPieceIdDto import org.android.bbangzip.domain.repository.remote.PieceRepository class PostDeletedItemListUseCase( - private val pieceRepository: PieceRepository + private val pieceRepository: PieceRepository, ) { suspend operator fun invoke( - requestPieceIdDto: RequestPieceIdDto + requestPieceIdDto: RequestPieceIdDto, ): Result = pieceRepository.postDeletedItemList( - requestPieceIdDto= requestPieceIdDto + requestPieceIdDto = requestPieceIdDto, ) -} \ No newline at end of file +} diff --git a/app/src/main/java/org/android/bbangzip/domain/usecase/PostUnCompleteCardIdUseCase.kt b/app/src/main/java/org/android/bbangzip/domain/usecase/PostUnCompleteCardIdUseCase.kt index 64918c48..8e6b71ab 100644 --- a/app/src/main/java/org/android/bbangzip/domain/usecase/PostUnCompleteCardIdUseCase.kt +++ b/app/src/main/java/org/android/bbangzip/domain/usecase/PostUnCompleteCardIdUseCase.kt @@ -4,14 +4,14 @@ import org.android.bbangzip.data.dto.request.RequestMarkDoneDto import org.android.bbangzip.domain.repository.remote.PieceRepository class PostUnCompleteCardIdUseCase( - private val pieceRepository: PieceRepository + private val pieceRepository: PieceRepository, ) { suspend operator fun invoke( pieceId: Int, - requestMarkDoneDto: RequestMarkDoneDto + requestMarkDoneDto: RequestMarkDoneDto, ): Result = pieceRepository.postUnCompleteCardId( pieceId = pieceId, - requestMarkDoneDto = requestMarkDoneDto + requestMarkDoneDto = requestMarkDoneDto, ) -} \ No newline at end of file +} diff --git a/app/src/main/java/org/android/bbangzip/presentation/component/balloon/BalloonContainer.kt b/app/src/main/java/org/android/bbangzip/presentation/component/balloon/BalloonContainer.kt index 63256b91..ba1b7fed 100644 --- a/app/src/main/java/org/android/bbangzip/presentation/component/balloon/BalloonContainer.kt +++ b/app/src/main/java/org/android/bbangzip/presentation/component/balloon/BalloonContainer.kt @@ -25,7 +25,7 @@ fun BalloonContainer( Box( modifier = modifier - .applyShadows(BbangZipShadowType.STRONG, shape = RoundedCornerShape(size = 20.dp)) + .applyShadows(BbangZipShadowType.EMPHASIZE, shape = RoundedCornerShape(size = 20.dp)) .fillMaxWidth() .background( color = BbangZipTheme.colors.staticWhite_FFFFFF, diff --git a/app/src/main/java/org/android/bbangzip/presentation/ui/navigator/MainNavigator.kt b/app/src/main/java/org/android/bbangzip/presentation/ui/navigator/MainNavigator.kt index d5e02f83..4ebd6e4b 100644 --- a/app/src/main/java/org/android/bbangzip/presentation/ui/navigator/MainNavigator.kt +++ b/app/src/main/java/org/android/bbangzip/presentation/ui/navigator/MainNavigator.kt @@ -12,7 +12,6 @@ import org.android.bbangzip.presentation.model.BottomNavigationRoute import org.android.bbangzip.presentation.model.Route import org.android.bbangzip.presentation.type.BottomNavigationType import org.android.bbangzip.presentation.ui.friend.navigateFriend -import org.android.bbangzip.presentation.ui.login.LoginRoute import org.android.bbangzip.presentation.ui.login.navigateLogin import org.android.bbangzip.presentation.ui.my.navigateMy import org.android.bbangzip.presentation.ui.onboarding.navigation.navigateOnboarding diff --git a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoContract.kt b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoContract.kt index a7468679..f69f4141 100644 --- a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoContract.kt +++ b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoContract.kt @@ -166,7 +166,7 @@ class TodoContract { val pendingCount: Int, val remainingStudyCount: Int, val completeCount: Int, - val screenType: ToDoScreenType + val screenType: ToDoScreenType, ) : TodoEvent data class OnFilterBottomSheetItemClicked( @@ -191,7 +191,7 @@ class TodoContract { val pendingCount: Int, val remainingStudyCount: Int, val completeCount: Int, - val screenType: ToDoScreenType + val screenType: ToDoScreenType, ) : TodoReduce data object DeleteToDoListItems : TodoReduce diff --git a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoRoute.kt b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoRoute.kt index edb76677..754e266d 100644 --- a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoRoute.kt +++ b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoRoute.kt @@ -6,7 +6,6 @@ import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.material3.CircularProgressIndicator import androidx.compose.material3.SnackbarHostState -import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue @@ -113,10 +112,11 @@ fun TodoRoute( false -> Box( - modifier = Modifier - .fillMaxSize() - .background(color = BbangZipTheme.colors.staticWhite_FFFFFF), - contentAlignment = Alignment.Center + modifier = + Modifier + .fillMaxSize() + .background(color = BbangZipTheme.colors.staticWhite_FFFFFF), + contentAlignment = Alignment.Center, ) { CircularProgressIndicator(color = BbangZipTheme.colors.backgroundAccent_FFDAA0) } diff --git a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoScreen.kt b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoScreen.kt index 2b194c71..24c5581d 100644 --- a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoScreen.kt +++ b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoScreen.kt @@ -13,6 +13,7 @@ import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width import androidx.compose.foundation.layout.wrapContentSize import androidx.compose.foundation.lazy.LazyColumn @@ -356,6 +357,7 @@ fun DateMessageCard( imageVector = ImageVector.vectorResource(id = R.drawable.ic_announcement_default_24), contentDescription = null, tint = BbangZipTheme.colors.labelNormal_282119, + modifier = Modifier.size(16.dp), ) Spacer(modifier = Modifier.width(6.dp)) diff --git a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoViewModel.kt b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoViewModel.kt index 5943fa54..75c2df2d 100644 --- a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoViewModel.kt +++ b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoViewModel.kt @@ -21,423 +21,421 @@ import javax.inject.Inject @HiltViewModel class TodoViewModel -@Inject -constructor( - private val getTodoInfoUseCase: GetToInfoUseCase, - private val postDeletedItemListUseCase: PostDeletedItemListUseCase, - private val postCompleteCardIdUseCase: PostCompleteCardIdUseCase, - private val postUnCompleteCardIdUseCase: PostUnCompleteCardIdUseCase, - savedStateHandle: SavedStateHandle, -) : BaseViewModel( - savedStateHandle = savedStateHandle, -) { - override fun createInitialState(savedState: Parcelable?): TodoContract.TodoState { - return savedState as? TodoContract.TodoState ?: TodoContract.TodoState() - } + @Inject + constructor( + private val getTodoInfoUseCase: GetToInfoUseCase, + private val postDeletedItemListUseCase: PostDeletedItemListUseCase, + private val postCompleteCardIdUseCase: PostCompleteCardIdUseCase, + private val postUnCompleteCardIdUseCase: PostUnCompleteCardIdUseCase, + savedStateHandle: SavedStateHandle, + ) : BaseViewModel( + savedStateHandle = savedStateHandle, + ) { + override fun createInitialState(savedState: Parcelable?): TodoContract.TodoState { + return savedState as? TodoContract.TodoState ?: TodoContract.TodoState() + } - init { - setEvent(TodoContract.TodoEvent.Initialize) - } + init { + setEvent(TodoContract.TodoEvent.Initialize) + } - override fun handleEvent(event: TodoContract.TodoEvent) { - when (event) { - // ToDoInfo Fetch - is TodoContract.TodoEvent.FetchToDoInfo -> - updateState( - TodoContract.TodoReduce.UpdateToDoInfo( - pendingCount = event.pendingCount, - remainingStudyCount = event.remainingStudyCount, - completeCount = event.completeCount, - todoList = event.todoList, - screenType = event.screenType - ), - ) + override fun handleEvent(event: TodoContract.TodoEvent) { + when (event) { + // ToDoInfo Fetch + is TodoContract.TodoEvent.FetchToDoInfo -> + updateState( + TodoContract.TodoReduce.UpdateToDoInfo( + pendingCount = event.pendingCount, + remainingStudyCount = event.remainingStudyCount, + completeCount = event.completeCount, + todoList = event.todoList, + screenType = event.screenType, + ), + ) - TodoContract.TodoEvent.Initialize -> launch { initDataLoad() } + TodoContract.TodoEvent.Initialize -> launch { initDataLoad() } - // Filter BottomSheet - is TodoContract.TodoEvent.OnFilterBottomSheetItemClicked -> { - viewModelScope.launch { - initDataLoad() + // Filter BottomSheet + is TodoContract.TodoEvent.OnFilterBottomSheetItemClicked -> { + viewModelScope.launch { + initDataLoad() + } + updateState(TodoContract.TodoReduce.UpdateFilterType(selectedFilter = event.selectedFilterItem)) + updateState( + TodoContract.TodoReduce.UpdateToDoFilterBottomSheetState( + todoFilterBottomSheetState = false, + ), + ) + setSideEffect(TodoContract.TodoSideEffect.ShowSnackBar("${event.selectedFilterItem.filter}으로 정렬했어요")) } - updateState(TodoContract.TodoReduce.UpdateFilterType(selectedFilter = event.selectedFilterItem)) - updateState( - TodoContract.TodoReduce.UpdateToDoFilterBottomSheetState( - todoFilterBottomSheetState = false, + + TodoContract.TodoEvent.OnFilterBottomSheetDismissRequest -> + updateState( + TodoContract.TodoReduce.UpdateToDoFilterBottomSheetState( + todoFilterBottomSheetState = false, + ), ) - ) - setSideEffect(TodoContract.TodoSideEffect.ShowSnackBar("${event.selectedFilterItem.filter}으로 정렬했어요")) - } - TodoContract.TodoEvent.OnFilterBottomSheetDismissRequest -> - updateState( - TodoContract.TodoReduce.UpdateToDoFilterBottomSheetState( - todoFilterBottomSheetState = false, - ), - ) + TodoContract.TodoEvent.OnFilterIconClicked -> { + updateState( + TodoContract.TodoReduce.UpdateToDoFilterBottomSheetState( + todoFilterBottomSheetState = true, + ), + ) + } - TodoContract.TodoEvent.OnFilterIconClicked -> { - updateState( - TodoContract.TodoReduce.UpdateToDoFilterBottomSheetState( - todoFilterBottomSheetState = true, - ), - ) - } + // revertComplete BottomSheet + is TodoContract.TodoEvent.OnRevertCompleteBottomSheetApproveButtonClicked -> { + viewModelScope.launch { + postUnCompleteCardId(event.pieceId) + } + updateState( + TodoContract.TodoReduce.UpdateCardState( + pieceId = event.pieceId, + cardState = BbangZipCardState.DEFAULT, + ), + ) + updateState( + TodoContract.TodoReduce.UpdateRevertCompleteBottomSheetState( + revertCompleteBottomSheetState = false, + ), + ) + updateState( + TodoContract.TodoReduce.UpdateToDoCount( + completeCount = currentUiState.completeCount - 1, + remainingStudyCount = currentUiState.remainingStudyCount + 1, + ), + ) + updateState(TodoContract.TodoReduce.ResetSelectedItemList) + setSideEffect(TodoContract.TodoSideEffect.ShowSnackBar("미완료 상태로 되돌려졌어요!")) + // TODO pieceId 사영헤사 서버로 쏘기 미완료 APT + } - // revertComplete BottomSheet - is TodoContract.TodoEvent.OnRevertCompleteBottomSheetApproveButtonClicked -> { - viewModelScope.launch { - postUnCompleteCardId(event.pieceId) + TodoContract.TodoEvent.OnRevertCompleteBottomSheetDismissButtonClicked -> { + updateState( + TodoContract.TodoReduce.UpdateRevertCompleteBottomSheetState( + revertCompleteBottomSheetState = false, + ), + ) + updateState(TodoContract.TodoReduce.ResetSelectedItemList) } - updateState( - TodoContract.TodoReduce.UpdateCardState( - pieceId = event.pieceId, - cardState = BbangZipCardState.DEFAULT, - ), - ) - updateState( - TodoContract.TodoReduce.UpdateRevertCompleteBottomSheetState( - revertCompleteBottomSheetState = false, - ), - ) - updateState( - TodoContract.TodoReduce.UpdateToDoCount( - completeCount = currentUiState.completeCount - 1, - remainingStudyCount = currentUiState.remainingStudyCount + 1, - ), - ) - updateState(TodoContract.TodoReduce.ResetSelectedItemList) - setSideEffect(TodoContract.TodoSideEffect.ShowSnackBar("미완료 상태로 되돌려졌어요!")) - // TODO pieceId 사영헤사 서버로 쏘기 미완료 APT - } - TodoContract.TodoEvent.OnRevertCompleteBottomSheetDismissButtonClicked -> { - updateState( - TodoContract.TodoReduce.UpdateRevertCompleteBottomSheetState( - revertCompleteBottomSheetState = false, - ), - ) - updateState(TodoContract.TodoReduce.ResetSelectedItemList) - } + TodoContract.TodoEvent.OnRevertCompleteBottomSheetDismissRequest -> { + updateState( + TodoContract.TodoReduce.UpdateRevertCompleteBottomSheetState( + revertCompleteBottomSheetState = false, + ), + ) + updateState(TodoContract.TodoReduce.ResetSelectedItemList) + } - TodoContract.TodoEvent.OnRevertCompleteBottomSheetDismissRequest -> { - updateState( - TodoContract.TodoReduce.UpdateRevertCompleteBottomSheetState( - revertCompleteBottomSheetState = false, - ), - ) - updateState(TodoContract.TodoReduce.ResetSelectedItemList) - } + // Delete + is TodoContract.TodoEvent.OnDeleteScreenCardClicked -> { + when (event.cardState) { + BbangZipCardState.CHECKED -> { + updateState(TodoContract.TodoReduce.UpdateSelectedItemList(pieceId = event.pieceId)) + updateState( + TodoContract.TodoReduce.UpdateCardState( + pieceId = event.pieceId, + cardState = event.cardState, + ), + ) + } - // Delete - is TodoContract.TodoEvent.OnDeleteScreenCardClicked -> { - when (event.cardState) { - BbangZipCardState.CHECKED -> { - updateState(TodoContract.TodoReduce.UpdateSelectedItemList(pieceId = event.pieceId)) + BbangZipCardState.CHECKABLE -> { + updateState(TodoContract.TodoReduce.DeleteSelectedItemList(pieceId = event.pieceId)) + updateState( + TodoContract.TodoReduce.UpdateCardState( + pieceId = event.pieceId, + cardState = event.cardState, + ), + ) + } + + else -> { + setSideEffect(TodoContract.TodoSideEffect.ShowSnackBar("이미 완료한 일은 삭제할 수 없어요!")) + } + } + } + // Default + is TodoContract.TodoEvent.OnDefaultScreenCardClicked -> { + if (event.cardState == BbangZipCardState.COMPLETE) { updateState( TodoContract.TodoReduce.UpdateCardState( pieceId = event.pieceId, cardState = event.cardState, ), ) - } - - BbangZipCardState.CHECKABLE -> { - updateState(TodoContract.TodoReduce.DeleteSelectedItemList(pieceId = event.pieceId)) updateState( - TodoContract.TodoReduce.UpdateCardState( - pieceId = event.pieceId, - cardState = event.cardState, + TodoContract.TodoReduce.UpdateToDoCount( + completeCount = currentUiState.completeCount + 1, + remainingStudyCount = currentUiState.remainingStudyCount - 1, ), ) - } - - else -> { - setSideEffect(TodoContract.TodoSideEffect.ShowSnackBar("이미 완료한 일은 삭제할 수 없어요!")) + viewModelScope.launch { + postCompleteCardId(pieceId = event.pieceId) + } + setSideEffect(TodoContract.TodoSideEffect.ShowSnackBar("공부완료 ! 오늘의 빵굽기 성공!")) + } else { + updateState( + TodoContract.TodoReduce.UpdateRevertCompleteBottomSheetState( + revertCompleteBottomSheetState = true, + ), + ) + updateState(TodoContract.TodoReduce.UpdateSelectedItemList(pieceId = event.pieceId)) } } - } - // Default - is TodoContract.TodoEvent.OnDefaultScreenCardClicked -> { - if (event.cardState == BbangZipCardState.COMPLETE) { + + TodoContract.TodoEvent.OnDeleteIconClicked -> { + updateState(TodoContract.TodoReduce.UpdateScreenType(screenType = ToDoScreenType.DELETE)) updateState( - TodoContract.TodoReduce.UpdateCardState( - pieceId = event.pieceId, - cardState = event.cardState, + TodoContract.TodoReduce.UpdateToDoListCardState( + previousCardState = BbangZipCardState.DEFAULT, + nextCardState = BbangZipCardState.CHECKABLE, ), ) + } + + TodoContract.TodoEvent.OnItemDeleteButtonClicked -> { + viewModelScope.launch { + postDeletedItemList(selectedItemList = currentUiState.selectedItemList) + } updateState( TodoContract.TodoReduce.UpdateToDoCount( - completeCount = currentUiState.completeCount + 1, - remainingStudyCount = currentUiState.remainingStudyCount - 1, + completeCount = currentUiState.completeCount, + remainingStudyCount = currentUiState.remainingStudyCount - currentUiState.selectedItemList.size, ), ) - viewModelScope.launch { - postCompleteCardId(pieceId = event.pieceId) - } - setSideEffect(TodoContract.TodoSideEffect.ShowSnackBar("공부완료 ! 오늘의 빵굽기 성공!")) - } else { updateState( - TodoContract.TodoReduce.UpdateRevertCompleteBottomSheetState( - revertCompleteBottomSheetState = true, + TodoContract.TodoReduce.UpdatePendingToDoCount( + pendingCount = currentUiState.pendingCount + currentUiState.selectedItemList.size, ), ) - updateState(TodoContract.TodoReduce.UpdateSelectedItemList(pieceId = event.pieceId)) - } - } - TodoContract.TodoEvent.OnDeleteIconClicked -> { - updateState(TodoContract.TodoReduce.UpdateScreenType(screenType = ToDoScreenType.DELETE)) - updateState( - TodoContract.TodoReduce.UpdateToDoListCardState( - previousCardState = BbangZipCardState.DEFAULT, - nextCardState = BbangZipCardState.CHECKABLE, - ), - ) - } + if (currentUiState.completeCount > 0 || currentUiState.remainingStudyCount - currentUiState.selectedItemList.size != 0) { + updateState(TodoContract.TodoReduce.DeleteToDoListItems) + updateState( + TodoContract.TodoReduce.UpdateToDoListCardState( + previousCardState = BbangZipCardState.CHECKABLE, + nextCardState = BbangZipCardState.DEFAULT, + ), + ) + updateState(TodoContract.TodoReduce.UpdateScreenType(screenType = ToDoScreenType.DEFAULT)) + } else { + updateState(TodoContract.TodoReduce.UpdateScreenType(screenType = ToDoScreenType.EMPTY)) + } - TodoContract.TodoEvent.OnItemDeleteButtonClicked -> { - viewModelScope.launch { - postDeletedItemList(selectedItemList = currentUiState.selectedItemList) + updateState(TodoContract.TodoReduce.ResetSelectedItemList) + setSideEffect(TodoContract.TodoSideEffect.ShowSnackBar("오늘 할 공부를 삭제했어요")) } - updateState( - TodoContract.TodoReduce.UpdateToDoCount( - completeCount = currentUiState.completeCount, - remainingStudyCount = currentUiState.remainingStudyCount - currentUiState.selectedItemList.size, - ), - ) - updateState( - TodoContract.TodoReduce.UpdatePendingToDoCount( - pendingCount = currentUiState.pendingCount + currentUiState.selectedItemList.size - ), - ) - - if (currentUiState.completeCount > 0 || currentUiState.remainingStudyCount - currentUiState.selectedItemList.size != 0) { - updateState(TodoContract.TodoReduce.DeleteToDoListItems) +// 통과 + TodoContract.TodoEvent.OnCloseIconClicked -> { updateState( TodoContract.TodoReduce.UpdateToDoListCardState( previousCardState = BbangZipCardState.CHECKABLE, nextCardState = BbangZipCardState.DEFAULT, ), ) + updateState( + TodoContract.TodoReduce.UpdateToDoListCardState( + previousCardState = BbangZipCardState.CHECKED, + nextCardState = BbangZipCardState.DEFAULT, + ), + ) + updateState(TodoContract.TodoReduce.ResetSelectedItemList) updateState(TodoContract.TodoReduce.UpdateScreenType(screenType = ToDoScreenType.DEFAULT)) - } else { - updateState(TodoContract.TodoReduce.UpdateScreenType(screenType = ToDoScreenType.EMPTY)) } - - - updateState(TodoContract.TodoReduce.ResetSelectedItemList) - setSideEffect(TodoContract.TodoSideEffect.ShowSnackBar("오늘 할 공부를 삭제했어요")) - } -// 통과 - TodoContract.TodoEvent.OnCloseIconClicked -> { - updateState( - TodoContract.TodoReduce.UpdateToDoListCardState( - previousCardState = BbangZipCardState.CHECKABLE, - nextCardState = BbangZipCardState.DEFAULT, - ), - ) - updateState( - TodoContract.TodoReduce.UpdateToDoListCardState( - previousCardState = BbangZipCardState.CHECKED, - nextCardState = BbangZipCardState.DEFAULT, - ), - ) - updateState(TodoContract.TodoReduce.ResetSelectedItemList) - updateState(TodoContract.TodoReduce.UpdateScreenType(screenType = ToDoScreenType.DEFAULT)) + // 화면 이동 + TodoContract.TodoEvent.OnAddStudyButtonClicked -> setSideEffect(TodoContract.TodoSideEffect.NavigateToAddToDo) + TodoContract.TodoEvent.OnAddPendingStudyButtonClicked -> setSideEffect(TodoContract.TodoSideEffect.NavigateToAddPendingToDo) } - - // 화면 이동 - TodoContract.TodoEvent.OnAddStudyButtonClicked -> setSideEffect(TodoContract.TodoSideEffect.NavigateToAddToDo) - TodoContract.TodoEvent.OnAddPendingStudyButtonClicked -> setSideEffect(TodoContract.TodoSideEffect.NavigateToAddPendingToDo) } - } - override fun reduceState( - state: TodoContract.TodoState, - reduce: TodoContract.TodoReduce, - ): TodoContract.TodoState { - return when (reduce) { - // ToDoInfo Fetch - is TodoContract.TodoReduce.UpdateToDoInfo -> - state.copy( - pendingCount = reduce.pendingCount, - completeCount = reduce.completeCount, - remainingStudyCount = reduce.remainingStudyCount, - todoList = reduce.todoList, - screenType = reduce.screenType - ) + override fun reduceState( + state: TodoContract.TodoState, + reduce: TodoContract.TodoReduce, + ): TodoContract.TodoState { + return when (reduce) { + // ToDoInfo Fetch + is TodoContract.TodoReduce.UpdateToDoInfo -> + state.copy( + pendingCount = reduce.pendingCount, + completeCount = reduce.completeCount, + remainingStudyCount = reduce.remainingStudyCount, + todoList = reduce.todoList, + screenType = reduce.screenType, + ) - // List - is TodoContract.TodoReduce.UpdateCardState -> - state.copy( - todoList = - state.todoList.map { item -> - if (item.pieceId == reduce.pieceId) item.copy(cardState = reduce.cardState) else item - }, - ) + // List + is TodoContract.TodoReduce.UpdateCardState -> + state.copy( + todoList = + state.todoList.map { item -> + if (item.pieceId == reduce.pieceId) item.copy(cardState = reduce.cardState) else item + }, + ) - is TodoContract.TodoReduce.UpdateToDoListCardState -> - state.copy( - todoList = - state.todoList.map { item -> - if (item.cardState == reduce.previousCardState) { - item.copy(cardState = reduce.nextCardState) - } else { - item - } - }, - ) + is TodoContract.TodoReduce.UpdateToDoListCardState -> + state.copy( + todoList = + state.todoList.map { item -> + if (item.cardState == reduce.previousCardState) { + item.copy(cardState = reduce.nextCardState) + } else { + item + } + }, + ) - is TodoContract.TodoReduce.DeleteToDoListItems -> { - val pieceIdSet = currentUiState.selectedItemList.toSet() - state.copy( - todoList = - state.todoList.filter { item -> - item.pieceId !in pieceIdSet - }, - ) - } + is TodoContract.TodoReduce.DeleteToDoListItems -> { + val pieceIdSet = currentUiState.selectedItemList.toSet() + state.copy( + todoList = + state.todoList.filter { item -> + item.pieceId !in pieceIdSet + }, + ) + } - // Revert BottomSheet - is TodoContract.TodoReduce.UpdateRevertCompleteBottomSheetState -> - state.copy( - revertCompleteBottomSheetState = reduce.revertCompleteBottomSheetState, - ) + // Revert BottomSheet + is TodoContract.TodoReduce.UpdateRevertCompleteBottomSheetState -> + state.copy( + revertCompleteBottomSheetState = reduce.revertCompleteBottomSheetState, + ) - is TodoContract.TodoReduce.UpdateSelectedItemList -> - state.copy( - selectedItemList = state.selectedItemList.plus(reduce.pieceId), - ) + is TodoContract.TodoReduce.UpdateSelectedItemList -> + state.copy( + selectedItemList = state.selectedItemList.plus(reduce.pieceId), + ) - is TodoContract.TodoReduce.DeleteSelectedItemList -> - state.copy( - selectedItemList = state.selectedItemList.minus(reduce.pieceId), - ) + is TodoContract.TodoReduce.DeleteSelectedItemList -> + state.copy( + selectedItemList = state.selectedItemList.minus(reduce.pieceId), + ) - // Filter BottomSheet - is TodoContract.TodoReduce.UpdateToDoFilterBottomSheetState -> - state.copy( - todoFilterBottomSheetState = reduce.todoFilterBottomSheetState, - ) + // Filter BottomSheet + is TodoContract.TodoReduce.UpdateToDoFilterBottomSheetState -> + state.copy( + todoFilterBottomSheetState = reduce.todoFilterBottomSheetState, + ) - is TodoContract.TodoReduce.UpdateFilterType -> - state.copy( - selectedFilterItem = reduce.selectedFilter, - ) + is TodoContract.TodoReduce.UpdateFilterType -> + state.copy( + selectedFilterItem = reduce.selectedFilter, + ) - // ToDoCount - is TodoContract.TodoReduce.UpdateToDoCount -> { - state.copy( - completeCount = reduce.completeCount, - remainingStudyCount = reduce.remainingStudyCount, - ) - } + // ToDoCount + is TodoContract.TodoReduce.UpdateToDoCount -> { + state.copy( + completeCount = reduce.completeCount, + remainingStudyCount = reduce.remainingStudyCount, + ) + } - is TodoContract.TodoReduce.UpdatePendingToDoCount -> - state.copy( - pendingCount = reduce.pendingCount, - ) + is TodoContract.TodoReduce.UpdatePendingToDoCount -> + state.copy( + pendingCount = reduce.pendingCount, + ) - // ScreenType - is TodoContract.TodoReduce.UpdateScreenType -> - state.copy( - screenType = reduce.screenType, - ) + // ScreenType + is TodoContract.TodoReduce.UpdateScreenType -> + state.copy( + screenType = reduce.screenType, + ) - TodoContract.TodoReduce.ResetSelectedItemList -> - state.copy( - selectedItemList = listOf(), - ) + TodoContract.TodoReduce.ResetSelectedItemList -> + state.copy( + selectedItemList = listOf(), + ) + } } - } - - private suspend fun initDataLoad() { - getToDoInfo( - area = ToDoConstants.TODO, - year = 2025, - semester = "1학기", - sortOption = currentUiState.selectedFilterItem.id - ) - } - private suspend fun getToDoInfo( - area: String, - year: Int, - semester: String, - sortOption: String - ) { - getTodoInfoUseCase( - area = area, - year = year, - semester = semester, - sortOption = sortOption - ).onSuccess { data -> - Timber.tag("todayOrders").d("server viewmodel") - updateState( - TodoContract.TodoReduce.UpdateToDoInfo( - todoList = data.todoList.map { item -> - ToDoCardModel( - pieceId = item.pieceId, - subjectName = item.subjectName, - examName = item.examName, - studyContents = item.studyContents, - startPage = item.startPage, - finishPage = item.finishPage, - deadline = item.deadline, - remainingDays = item.remainingDays, - cardState = if (item.isFinished) BbangZipCardState.COMPLETE else BbangZipCardState.DEFAULT - ) - }, - pendingCount = data.pendingCount, - remainingStudyCount = data.remainingStudyCount, - completeCount = data.completeCount, - screenType = if (data.todoList.isEmpty()) ToDoScreenType.EMPTY else ToDoScreenType.DEFAULT - ) + private suspend fun initDataLoad() { + getToDoInfo( + area = ToDoConstants.TODO, + year = 2025, + semester = "1학기", + sortOption = currentUiState.selectedFilterItem.id, ) } - .onFailure { error -> - Timber.tag("todayOrders").d(error) - } - } - - private suspend fun postDeletedItemList( - selectedItemList: List - ) { - postDeletedItemListUseCase( - requestPieceIdDto = RequestPieceIdDto(pieceIds = selectedItemList) - ).onSuccess { - Timber.tag("hide").e("삭제 성공!") - }.onFailure { - Timber.tag("hide").e("삭제 성공!") + private suspend fun getToDoInfo( + area: String, + year: Int, + semester: String, + sortOption: String, + ) { + getTodoInfoUseCase( + area = area, + year = year, + semester = semester, + sortOption = sortOption, + ).onSuccess { data -> + Timber.tag("todayOrders").d("server viewmodel") + updateState( + TodoContract.TodoReduce.UpdateToDoInfo( + todoList = + data.todoList.map { item -> + ToDoCardModel( + pieceId = item.pieceId, + subjectName = item.subjectName, + examName = item.examName, + studyContents = item.studyContents, + startPage = item.startPage, + finishPage = item.finishPage, + deadline = item.deadline, + remainingDays = item.remainingDays, + cardState = if (item.isFinished) BbangZipCardState.COMPLETE else BbangZipCardState.DEFAULT, + ) + }, + pendingCount = data.pendingCount, + remainingStudyCount = data.remainingStudyCount, + completeCount = data.completeCount, + screenType = if (data.todoList.isEmpty()) ToDoScreenType.EMPTY else ToDoScreenType.DEFAULT, + ), + ) + } + .onFailure { error -> + Timber.tag("todayOrders").d(error) + } } - } - - private suspend fun postCompleteCardId( - pieceId: Int - ) { - postCompleteCardIdUseCase( - pieceId = pieceId, requestMarkDoneDto = RequestMarkDoneDto(isFinished = true) - ).onSuccess { - Timber.tag("markDone").e("완료 성공!") - }.onFailure { error -> - Timber.tag("markDone").e(error) + private suspend fun postDeletedItemList( + selectedItemList: List, + ) { + postDeletedItemListUseCase( + requestPieceIdDto = RequestPieceIdDto(pieceIds = selectedItemList), + ).onSuccess { + Timber.tag("hide").e("삭제 성공!") + }.onFailure { + Timber.tag("hide").e("삭제 성공!") + } } - } - private suspend fun postUnCompleteCardId( - pieceId: Int - ) { - postUnCompleteCardIdUseCase( - pieceId = pieceId, requestMarkDoneDto = RequestMarkDoneDto(isFinished = false) - ).onSuccess { - Timber.tag("markDone").e("완료 성공!") - }.onFailure { error -> - Timber.tag("markDone").e(error) + private suspend fun postCompleteCardId( + pieceId: Int, + ) { + postCompleteCardIdUseCase( + pieceId = pieceId, + requestMarkDoneDto = RequestMarkDoneDto(isFinished = true), + ).onSuccess { + Timber.tag("markDone").e("완료 성공!") + }.onFailure { error -> + Timber.tag("markDone").e(error) + } + } + private suspend fun postUnCompleteCardId( + pieceId: Int, + ) { + postUnCompleteCardIdUseCase( + pieceId = pieceId, + requestMarkDoneDto = RequestMarkDoneDto(isFinished = false), + ).onSuccess { + Timber.tag("markDone").e("완료 성공!") + }.onFailure { error -> + Timber.tag("markDone").e(error) + } } } -} diff --git a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/pendingtodoadd/TodoAddPendingContract.kt b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/pendingtodoadd/TodoAddPendingContract.kt index 639da0c7..c79fe972 100644 --- a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/pendingtodoadd/TodoAddPendingContract.kt +++ b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/pendingtodoadd/TodoAddPendingContract.kt @@ -5,7 +5,6 @@ import kotlinx.parcelize.Parcelize import org.android.bbangzip.presentation.component.card.BbangZipCardState import org.android.bbangzip.presentation.model.card.ToDoCardModel import org.android.bbangzip.presentation.type.ToDoFilterType -import org.android.bbangzip.presentation.ui.todo.todoadd.TodoAddContract.TodoAddReduce import org.android.bbangzip.presentation.util.base.BaseContract class TodoAddPendingContract { @@ -160,7 +159,7 @@ class TodoAddPendingContract { data class UpdateToDoList( val todoList: List, - ): TodoAddPendingReduce + ) : TodoAddPendingReduce data class UpdateFilterType( val selectedFilter: ToDoFilterType, diff --git a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/pendingtodoadd/TodoAddPendingRoute.kt b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/pendingtodoadd/TodoAddPendingRoute.kt index 3eaa003f..27a1d87f 100644 --- a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/pendingtodoadd/TodoAddPendingRoute.kt +++ b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/pendingtodoadd/TodoAddPendingRoute.kt @@ -5,7 +5,6 @@ import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.material3.CircularProgressIndicator import androidx.compose.material3.SnackbarHostState -import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue @@ -89,10 +88,11 @@ fun TodoAddPendingRoute( false -> Box( - modifier = Modifier - .fillMaxSize() - .background(color = BbangZipTheme.colors.staticWhite_FFFFFF), - contentAlignment = Alignment.Center + modifier = + Modifier + .fillMaxSize() + .background(color = BbangZipTheme.colors.staticWhite_FFFFFF), + contentAlignment = Alignment.Center, ) { CircularProgressIndicator(color = BbangZipTheme.colors.backgroundAccent_FFDAA0) } diff --git a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/pendingtodoadd/TodoAddPendingViewModel.kt b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/pendingtodoadd/TodoAddPendingViewModel.kt index b8bb3483..be11e340 100644 --- a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/pendingtodoadd/TodoAddPendingViewModel.kt +++ b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/pendingtodoadd/TodoAddPendingViewModel.kt @@ -17,206 +17,206 @@ import javax.inject.Inject @HiltViewModel class TodoAddPendingViewModel -@Inject -constructor( - private val getTodoInfoUseCase: GetToInfoUseCase, - private val postAddTodoItemListUseCase: PostAddTodoItemListUseCase, - savedStateHandle: SavedStateHandle, -) : BaseViewModel( - savedStateHandle = savedStateHandle, -) { - override fun createInitialState(savedState: Parcelable?): TodoAddPendingContract.TodoAddPendingState { - return savedState as? TodoAddPendingContract.TodoAddPendingState - ?: TodoAddPendingContract.TodoAddPendingState() - } - - init { - setEvent(TodoAddPendingContract.TodoAddPendingEvent.Initialize) - } - - override fun handleEvent(event: TodoAddPendingContract.TodoAddPendingEvent) { - when (event) { - TodoAddPendingContract.TodoAddPendingEvent.Initialize -> launch { initDataLoad() } - - TodoAddPendingContract.TodoAddPendingEvent.OnBackIconClicked -> { - updateState(TodoAddPendingContract.TodoAddPendingReduce.ResetSelectedItemList) - setSideEffect(TodoAddPendingContract.TodoAddPendingSideEffect.NavigateToBack) - } + @Inject + constructor( + private val getTodoInfoUseCase: GetToInfoUseCase, + private val postAddTodoItemListUseCase: PostAddTodoItemListUseCase, + savedStateHandle: SavedStateHandle, + ) : BaseViewModel( + savedStateHandle = savedStateHandle, + ) { + override fun createInitialState(savedState: Parcelable?): TodoAddPendingContract.TodoAddPendingState { + return savedState as? TodoAddPendingContract.TodoAddPendingState + ?: TodoAddPendingContract.TodoAddPendingState() + } - TodoAddPendingContract.TodoAddPendingEvent.OnFilterBottomSheetDismissRequest -> - updateState( - TodoAddPendingContract.TodoAddPendingReduce.UpdateToDoFilterBottomSheetState( - todoFilterBottomSheetState = false, - ), - ) + init { + setEvent(TodoAddPendingContract.TodoAddPendingEvent.Initialize) + } - TodoAddPendingContract.TodoAddPendingEvent.OnFilterIconClicked -> - updateState( - TodoAddPendingContract.TodoAddPendingReduce.UpdateToDoFilterBottomSheetState( - todoFilterBottomSheetState = true, - ), - ) + override fun handleEvent(event: TodoAddPendingContract.TodoAddPendingEvent) { + when (event) { + TodoAddPendingContract.TodoAddPendingEvent.Initialize -> launch { initDataLoad() } - is TodoAddPendingContract.TodoAddPendingEvent.OnFilterBottomSheetItemClicked -> { - viewModelScope.launch { - getToDoInfo( - area = ToDoConstants.PENDING, - year = 2025, - semester = "1학기", - sortOption = event.selectedFilterItem.id - ) + TodoAddPendingContract.TodoAddPendingEvent.OnBackIconClicked -> { + updateState(TodoAddPendingContract.TodoAddPendingReduce.ResetSelectedItemList) + setSideEffect(TodoAddPendingContract.TodoAddPendingSideEffect.NavigateToBack) } - updateState( - TodoAddPendingContract.TodoAddPendingReduce.UpdateFilterType( - selectedFilter = event.selectedFilterItem - ) - ) - updateState( - TodoAddPendingContract.TodoAddPendingReduce.UpdateToDoFilterBottomSheetState( - todoFilterBottomSheetState = false, - ), - ) - setSideEffect(TodoAddPendingContract.TodoAddPendingSideEffect.ShowTodoAddSnackBar("${event.selectedFilterItem.filter}으로 정렬했어요")) - } - TodoAddPendingContract.TodoAddPendingEvent.OnItemPlusButtonClicked -> { - viewModelScope.launch { - postAddTodoItemList(selectedItemList = currentUiState.selectedItemList) - } - setSideEffect(TodoAddPendingContract.TodoAddPendingSideEffect.NavigateToToDo) - setSideEffect(TodoAddPendingContract.TodoAddPendingSideEffect.ShowSnackBar("오늘 할 공부를 추가했어요!")) - } - - is TodoAddPendingContract.TodoAddPendingEvent.OnToDoCardClicked -> { - if (event.cardState == BbangZipCardState.CHECKED) { + TodoAddPendingContract.TodoAddPendingEvent.OnFilterBottomSheetDismissRequest -> updateState( - TodoAddPendingContract.TodoAddPendingReduce.UpdateSelectedItemList( - pieceId = event.pieceId - ) + TodoAddPendingContract.TodoAddPendingReduce.UpdateToDoFilterBottomSheetState( + todoFilterBottomSheetState = false, + ), ) + + TodoAddPendingContract.TodoAddPendingEvent.OnFilterIconClicked -> updateState( - TodoAddPendingContract.TodoAddPendingReduce.UpdateCardState( - pieceId = event.pieceId, - cardState = event.cardState, + TodoAddPendingContract.TodoAddPendingReduce.UpdateToDoFilterBottomSheetState( + todoFilterBottomSheetState = true, ), ) - } else { - updateState( - TodoAddPendingContract.TodoAddPendingReduce.DeleteSelectedItemList( - pieceId = event.pieceId + + is TodoAddPendingContract.TodoAddPendingEvent.OnFilterBottomSheetItemClicked -> { + viewModelScope.launch { + getToDoInfo( + area = ToDoConstants.PENDING, + year = 2025, + semester = "1학기", + sortOption = event.selectedFilterItem.id, ) + } + updateState( + TodoAddPendingContract.TodoAddPendingReduce.UpdateFilterType( + selectedFilter = event.selectedFilterItem, + ), ) updateState( - TodoAddPendingContract.TodoAddPendingReduce.UpdateCardState( - pieceId = event.pieceId, - cardState = event.cardState, + TodoAddPendingContract.TodoAddPendingReduce.UpdateToDoFilterBottomSheetState( + todoFilterBottomSheetState = false, ), ) + setSideEffect(TodoAddPendingContract.TodoAddPendingSideEffect.ShowTodoAddSnackBar("${event.selectedFilterItem.filter}으로 정렬했어요")) + } + + TodoAddPendingContract.TodoAddPendingEvent.OnItemPlusButtonClicked -> { + viewModelScope.launch { + postAddTodoItemList(selectedItemList = currentUiState.selectedItemList) + } + setSideEffect(TodoAddPendingContract.TodoAddPendingSideEffect.NavigateToToDo) + setSideEffect(TodoAddPendingContract.TodoAddPendingSideEffect.ShowSnackBar("오늘 할 공부를 추가했어요!")) + } + + is TodoAddPendingContract.TodoAddPendingEvent.OnToDoCardClicked -> { + if (event.cardState == BbangZipCardState.CHECKED) { + updateState( + TodoAddPendingContract.TodoAddPendingReduce.UpdateSelectedItemList( + pieceId = event.pieceId, + ), + ) + updateState( + TodoAddPendingContract.TodoAddPendingReduce.UpdateCardState( + pieceId = event.pieceId, + cardState = event.cardState, + ), + ) + } else { + updateState( + TodoAddPendingContract.TodoAddPendingReduce.DeleteSelectedItemList( + pieceId = event.pieceId, + ), + ) + updateState( + TodoAddPendingContract.TodoAddPendingReduce.UpdateCardState( + pieceId = event.pieceId, + cardState = event.cardState, + ), + ) + } } } } - } - override fun reduceState( - state: TodoAddPendingContract.TodoAddPendingState, - reduce: TodoAddPendingContract.TodoAddPendingReduce, - ): TodoAddPendingContract.TodoAddPendingState { - return when (reduce) { - TodoAddPendingContract.TodoAddPendingReduce.ResetSelectedItemList -> - state.copy( - selectedItemList = listOf(), - ) + override fun reduceState( + state: TodoAddPendingContract.TodoAddPendingState, + reduce: TodoAddPendingContract.TodoAddPendingReduce, + ): TodoAddPendingContract.TodoAddPendingState { + return when (reduce) { + TodoAddPendingContract.TodoAddPendingReduce.ResetSelectedItemList -> + state.copy( + selectedItemList = listOf(), + ) - is TodoAddPendingContract.TodoAddPendingReduce.UpdateCardState -> - state.copy( - todoList = - state.todoList.map { item -> - if (item.pieceId == reduce.pieceId) item.copy(cardState = reduce.cardState) else item - }, - ) + is TodoAddPendingContract.TodoAddPendingReduce.UpdateCardState -> + state.copy( + todoList = + state.todoList.map { item -> + if (item.pieceId == reduce.pieceId) item.copy(cardState = reduce.cardState) else item + }, + ) - is TodoAddPendingContract.TodoAddPendingReduce.UpdateFilterType -> { - state.copy( - selectedFilter = reduce.selectedFilter, - ) - } + is TodoAddPendingContract.TodoAddPendingReduce.UpdateFilterType -> { + state.copy( + selectedFilter = reduce.selectedFilter, + ) + } - is TodoAddPendingContract.TodoAddPendingReduce.UpdateSelectedItemList -> - state.copy( - selectedItemList = state.selectedItemList.plus(reduce.pieceId), - ) + is TodoAddPendingContract.TodoAddPendingReduce.UpdateSelectedItemList -> + state.copy( + selectedItemList = state.selectedItemList.plus(reduce.pieceId), + ) - is TodoAddPendingContract.TodoAddPendingReduce.UpdateToDoFilterBottomSheetState -> - state.copy( - todoFilterBottomSheetState = reduce.todoFilterBottomSheetState, - ) + is TodoAddPendingContract.TodoAddPendingReduce.UpdateToDoFilterBottomSheetState -> + state.copy( + todoFilterBottomSheetState = reduce.todoFilterBottomSheetState, + ) - is TodoAddPendingContract.TodoAddPendingReduce.DeleteSelectedItemList -> - state.copy( - selectedItemList = state.selectedItemList.minus(reduce.pieceId), - ) + is TodoAddPendingContract.TodoAddPendingReduce.DeleteSelectedItemList -> + state.copy( + selectedItemList = state.selectedItemList.minus(reduce.pieceId), + ) - is TodoAddPendingContract.TodoAddPendingReduce.UpdateToDoList -> - state.copy( - todoList = reduce.todoList - ) + is TodoAddPendingContract.TodoAddPendingReduce.UpdateToDoList -> + state.copy( + todoList = reduce.todoList, + ) + } } - } - private suspend fun initDataLoad() { - getToDoInfo( - area = ToDoConstants.PENDING, - year = 2025, - semester = "1학기", - sortOption = currentUiState.selectedFilter.id - ) - } + private suspend fun initDataLoad() { + getToDoInfo( + area = ToDoConstants.PENDING, + year = 2025, + semester = "1학기", + sortOption = currentUiState.selectedFilter.id, + ) + } - private suspend fun getToDoInfo( - area: String, - year: Int, - semester: String, - sortOption: String - ) { - getTodoInfoUseCase( - area = area, - year = year, - semester = semester, - sortOption = sortOption - ).onSuccess { data -> - Timber.tag("todayOrders").d("${currentUiState.selectedItemList}") - updateState( - TodoAddPendingContract.TodoAddPendingReduce.UpdateToDoList( - todoList = data.todoList.map { item -> - ToDoCardModel( - pieceId = item.pieceId, - subjectName = item.subjectName, - examName = item.examName, - studyContents = item.studyContents, - startPage = item.startPage, - finishPage = item.finishPage, - deadline = item.deadline, - remainingDays = item.remainingDays, - cardState = BbangZipCardState.CHECKABLE - ) - }, + private suspend fun getToDoInfo( + area: String, + year: Int, + semester: String, + sortOption: String, + ) { + getTodoInfoUseCase( + area = area, + year = year, + semester = semester, + sortOption = sortOption, + ).onSuccess { data -> + Timber.tag("todayOrders").d("${currentUiState.selectedItemList}") + updateState( + TodoAddPendingContract.TodoAddPendingReduce.UpdateToDoList( + todoList = + data.todoList.map { item -> + ToDoCardModel( + pieceId = item.pieceId, + subjectName = item.subjectName, + examName = item.examName, + studyContents = item.studyContents, + startPage = item.startPage, + finishPage = item.finishPage, + deadline = item.deadline, + remainingDays = item.remainingDays, + cardState = BbangZipCardState.CHECKABLE, + ) + }, + ), ) - ) - }.onFailure { error -> - Timber.tag("todayOrders").e(error) + }.onFailure { error -> + Timber.tag("todayOrders").e(error) + } } - } - private suspend fun postAddTodoItemList( - selectedItemList: List - ) { - postAddTodoItemListUseCase( - requestPieceIdDto = RequestPieceIdDto(pieceIds = selectedItemList) - ).onSuccess { - Timber.tag("postAdd").d("성공") - }.onFailure { error -> - Timber.tag("postAdd").d(error) + private suspend fun postAddTodoItemList( + selectedItemList: List, + ) { + postAddTodoItemListUseCase( + requestPieceIdDto = RequestPieceIdDto(pieceIds = selectedItemList), + ).onSuccess { + Timber.tag("postAdd").d("성공") + }.onFailure { error -> + Timber.tag("postAdd").d(error) + } } } -} - diff --git a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/todoadd/TodoAddContract.kt b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/todoadd/TodoAddContract.kt index 1f0bc485..94534c3f 100644 --- a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/todoadd/TodoAddContract.kt +++ b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/todoadd/TodoAddContract.kt @@ -5,7 +5,6 @@ import kotlinx.parcelize.Parcelize import org.android.bbangzip.presentation.component.card.BbangZipCardState import org.android.bbangzip.presentation.model.card.ToDoCardModel import org.android.bbangzip.presentation.type.ToDoFilterType -import org.android.bbangzip.presentation.type.ToDoScreenType import org.android.bbangzip.presentation.util.base.BaseContract class TodoAddContract { @@ -152,7 +151,7 @@ class TodoAddContract { data class UpdateToDoList( val todoList: List, - ): TodoAddReduce + ) : TodoAddReduce data class UpdateSelectedItemList( val pieceId: Int, diff --git a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/todoadd/TodoAddRoute.kt b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/todoadd/TodoAddRoute.kt index 71015d28..97a4ce18 100644 --- a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/todoadd/TodoAddRoute.kt +++ b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/todoadd/TodoAddRoute.kt @@ -5,7 +5,6 @@ import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.material3.CircularProgressIndicator import androidx.compose.material3.SnackbarHostState -import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue @@ -89,10 +88,11 @@ fun TodoAddRoute( false -> Box( - modifier = Modifier - .fillMaxSize() - .background(color = BbangZipTheme.colors.staticWhite_FFFFFF), - contentAlignment = Alignment.Center + modifier = + Modifier + .fillMaxSize() + .background(color = BbangZipTheme.colors.staticWhite_FFFFFF), + contentAlignment = Alignment.Center, ) { CircularProgressIndicator(color = BbangZipTheme.colors.backgroundAccent_FFDAA0) } diff --git a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/todoadd/TodoAddViewModel.kt b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/todoadd/TodoAddViewModel.kt index 63c22e33..acbfec59 100644 --- a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/todoadd/TodoAddViewModel.kt +++ b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/todoadd/TodoAddViewModel.kt @@ -16,192 +16,196 @@ import javax.inject.Inject @HiltViewModel class TodoAddViewModel -@Inject -constructor( - private val getAddTodoListUseCase: GetAddTodoListUseCase, - private val postAddTodoItemListUseCase: PostAddTodoItemListUseCase, - savedStateHandle: SavedStateHandle, -) : BaseViewModel( - savedStateHandle = savedStateHandle, -) { - override fun createInitialState(savedState: Parcelable?): TodoAddContract.TodoAddState { - return savedState as? TodoAddContract.TodoAddState ?: TodoAddContract.TodoAddState() - } - - init { - setEvent(TodoAddContract.TodoAddEvent.Initialize) - } - - override fun handleEvent(event: TodoAddContract.TodoAddEvent) { - when (event) { - TodoAddContract.TodoAddEvent.Initialize -> launch { initDataLoad() } - - TodoAddContract.TodoAddEvent.OnBackIconClicked -> { - updateState(TodoAddContract.TodoAddReduce.ResetSelectedItemList) - setSideEffect(TodoAddContract.TodoAddSideEffect.NavigateToBack) - } + @Inject + constructor( + private val getAddTodoListUseCase: GetAddTodoListUseCase, + private val postAddTodoItemListUseCase: PostAddTodoItemListUseCase, + savedStateHandle: SavedStateHandle, + ) : BaseViewModel( + savedStateHandle = savedStateHandle, + ) { + override fun createInitialState(savedState: Parcelable?): TodoAddContract.TodoAddState { + return savedState as? TodoAddContract.TodoAddState ?: TodoAddContract.TodoAddState() + } - TodoAddContract.TodoAddEvent.OnFilterBottomSheetDismissRequest -> - updateState( - TodoAddContract.TodoAddReduce.UpdateToDoFilterBottomSheetState( - todoFilterBottomSheetState = false, - ), - ) + init { + setEvent(TodoAddContract.TodoAddEvent.Initialize) + } - TodoAddContract.TodoAddEvent.OnFilterIconClicked -> - updateState( - TodoAddContract.TodoAddReduce.UpdateToDoFilterBottomSheetState( - todoFilterBottomSheetState = true, - ), - ) + override fun handleEvent(event: TodoAddContract.TodoAddEvent) { + when (event) { + TodoAddContract.TodoAddEvent.Initialize -> launch { initDataLoad() } - is TodoAddContract.TodoAddEvent.OnFilterBottomSheetItemClicked -> { - viewModelScope.launch { - getAddTodoList( - year = 2025, - semester = "1학기", - sortOption = event.selectedFilterItem.id - ) + TodoAddContract.TodoAddEvent.OnBackIconClicked -> { + updateState(TodoAddContract.TodoAddReduce.ResetSelectedItemList) + setSideEffect(TodoAddContract.TodoAddSideEffect.NavigateToBack) } - updateState(TodoAddContract.TodoAddReduce.UpdateFilterType(selectedFilter = event.selectedFilterItem)) - updateState( - TodoAddContract.TodoAddReduce.UpdateToDoFilterBottomSheetState( - todoFilterBottomSheetState = false, - ), - ) - setSideEffect(TodoAddContract.TodoAddSideEffect.ShowTodoAddSnackBar("${event.selectedFilterItem.filter}으로 정렬했어요")) - } - TodoAddContract.TodoAddEvent.OnItemPlusButtonClicked -> { - viewModelScope.launch { - postAddTodoItemList(selectedItemList = currentUiState.selectedItemList) - } - setSideEffect(TodoAddContract.TodoAddSideEffect.NavigateToToDo) - setSideEffect(TodoAddContract.TodoAddSideEffect.ShowSnackBar("오늘 할 공부를 추가했어요!")) - } + TodoAddContract.TodoAddEvent.OnFilterBottomSheetDismissRequest -> + updateState( + TodoAddContract.TodoAddReduce.UpdateToDoFilterBottomSheetState( + todoFilterBottomSheetState = false, + ), + ) - is TodoAddContract.TodoAddEvent.OnToDoCardClicked -> { - if (event.cardState == BbangZipCardState.CHECKED) { - updateState(TodoAddContract.TodoAddReduce.UpdateSelectedItemList(pieceId = event.pieceId)) + TodoAddContract.TodoAddEvent.OnFilterIconClicked -> updateState( - TodoAddContract.TodoAddReduce.UpdateCardState( - pieceId = event.pieceId, - cardState = event.cardState, + TodoAddContract.TodoAddReduce.UpdateToDoFilterBottomSheetState( + todoFilterBottomSheetState = true, ), ) - } else { - updateState(TodoAddContract.TodoAddReduce.DeleteSelectedItemList(pieceId = event.pieceId)) + + is TodoAddContract.TodoAddEvent.OnFilterBottomSheetItemClicked -> { + viewModelScope.launch { + getAddTodoList( + year = 2025, + semester = "1학기", + sortOption = event.selectedFilterItem.id, + ) + } + updateState(TodoAddContract.TodoAddReduce.UpdateFilterType(selectedFilter = event.selectedFilterItem)) updateState( - TodoAddContract.TodoAddReduce.UpdateCardState( - pieceId = event.pieceId, - cardState = event.cardState, + TodoAddContract.TodoAddReduce.UpdateToDoFilterBottomSheetState( + todoFilterBottomSheetState = false, ), ) + setSideEffect(TodoAddContract.TodoAddSideEffect.ShowTodoAddSnackBar("${event.selectedFilterItem.filter}으로 정렬했어요")) + } + + TodoAddContract.TodoAddEvent.OnItemPlusButtonClicked -> { + viewModelScope.launch { + postAddTodoItemList(selectedItemList = currentUiState.selectedItemList) + } + setSideEffect(TodoAddContract.TodoAddSideEffect.NavigateToToDo) + setSideEffect(TodoAddContract.TodoAddSideEffect.ShowSnackBar("오늘 할 공부를 추가했어요!")) + } + + is TodoAddContract.TodoAddEvent.OnToDoCardClicked -> { + if (event.cardState == BbangZipCardState.CHECKED) { + updateState(TodoAddContract.TodoAddReduce.UpdateSelectedItemList(pieceId = event.pieceId)) + updateState( + TodoAddContract.TodoAddReduce.UpdateCardState( + pieceId = event.pieceId, + cardState = event.cardState, + ), + ) + } else { + updateState(TodoAddContract.TodoAddReduce.DeleteSelectedItemList(pieceId = event.pieceId)) + updateState( + TodoAddContract.TodoAddReduce.UpdateCardState( + pieceId = event.pieceId, + cardState = event.cardState, + ), + ) + } } } } - } - - override fun reduceState( - state: TodoAddContract.TodoAddState, - reduce: TodoAddContract.TodoAddReduce, - ): TodoAddContract.TodoAddState { - return when (reduce) { - TodoAddContract.TodoAddReduce.ResetSelectedItemList -> - state.copy( - selectedItemList = listOf(), - ) + override fun reduceState( + state: TodoAddContract.TodoAddState, + reduce: TodoAddContract.TodoAddReduce, + ): TodoAddContract.TodoAddState { + return when (reduce) { + TodoAddContract.TodoAddReduce.ResetSelectedItemList -> + state.copy( + selectedItemList = listOf(), + ) - is TodoAddContract.TodoAddReduce.UpdateCardState -> - state.copy( - todoList = - state.todoList.map { item -> - if (item.pieceId == reduce.pieceId) item.copy(cardState = reduce.cardState) else item - }, - ) + is TodoAddContract.TodoAddReduce.UpdateCardState -> + state.copy( + todoList = + state.todoList.map { item -> + if (item.pieceId == reduce.pieceId) item.copy(cardState = reduce.cardState) else item + }, + ) - is TodoAddContract.TodoAddReduce.UpdateFilterType -> - state.copy( - selectedFilter = reduce.selectedFilter, - ) + is TodoAddContract.TodoAddReduce.UpdateFilterType -> + state.copy( + selectedFilter = reduce.selectedFilter, + ) - is TodoAddContract.TodoAddReduce.UpdateSelectedItemList -> - state.copy( - selectedItemList = state.selectedItemList.plus(reduce.pieceId), - ) + is TodoAddContract.TodoAddReduce.UpdateSelectedItemList -> + state.copy( + selectedItemList = state.selectedItemList.plus(reduce.pieceId), + ) - is TodoAddContract.TodoAddReduce.UpdateToDoFilterBottomSheetState -> - state.copy( - todoFilterBottomSheetState = reduce.todoFilterBottomSheetState, - ) + is TodoAddContract.TodoAddReduce.UpdateToDoFilterBottomSheetState -> + state.copy( + todoFilterBottomSheetState = reduce.todoFilterBottomSheetState, + ) - is TodoAddContract.TodoAddReduce.DeleteSelectedItemList -> - state.copy( - selectedItemList = state.selectedItemList.minus(reduce.pieceId), - ) + is TodoAddContract.TodoAddReduce.DeleteSelectedItemList -> + state.copy( + selectedItemList = state.selectedItemList.minus(reduce.pieceId), + ) - is TodoAddContract.TodoAddReduce.UpdateToDoList -> - state.copy( - todoList = reduce.todoList - ) + is TodoAddContract.TodoAddReduce.UpdateToDoList -> + state.copy( + todoList = reduce.todoList, + ) + } } - } - - private suspend fun initDataLoad() { - getAddTodoList( - year = 2025, - semester = "1학기", - sortOption = currentUiState.selectedFilter.id - ) - } - private suspend fun getAddTodoList( - year: Int, - semester: String, - sortOption: String - ) { - getAddTodoListUseCase( - year = year, - semester = semester, - sortOption = sortOption - ).onSuccess { data -> - Timber.tag("todo").d("server viewmodel") - updateState( - TodoAddContract.TodoAddReduce.UpdateToDoList( - todoList = data.todoList.map { item -> - ToDoCardModel( - pieceId = item.pieceId, - subjectName = item.subjectName, - examName = item.examName, - studyContents = item.studyContents, - startPage = item.startPage, - finishPage = item.finishPage, - deadline = item.deadline, - remainingDays = item.remainingDays, - cardState = if (currentUiState.selectedItemList.toSet() - .contains(item.pieceId) - ) BbangZipCardState.CHECKED else BbangZipCardState.CHECKABLE - ) - }, - ) + private suspend fun initDataLoad() { + getAddTodoList( + year = 2025, + semester = "1학기", + sortOption = currentUiState.selectedFilter.id, ) } - .onFailure { error -> - Timber.tag("todo").d(error) + + private suspend fun getAddTodoList( + year: Int, + semester: String, + sortOption: String, + ) { + getAddTodoListUseCase( + year = year, + semester = semester, + sortOption = sortOption, + ).onSuccess { data -> + Timber.tag("todo").d("server viewmodel") + updateState( + TodoAddContract.TodoAddReduce.UpdateToDoList( + todoList = + data.todoList.map { item -> + ToDoCardModel( + pieceId = item.pieceId, + subjectName = item.subjectName, + examName = item.examName, + studyContents = item.studyContents, + startPage = item.startPage, + finishPage = item.finishPage, + deadline = item.deadline, + remainingDays = item.remainingDays, + cardState = + if (currentUiState.selectedItemList.toSet() + .contains(item.pieceId) + ) { + BbangZipCardState.CHECKED + } else { + BbangZipCardState.CHECKABLE + }, + ) + }, + ), + ) } - } + .onFailure { error -> + Timber.tag("todo").d(error) + } + } - private suspend fun postAddTodoItemList( - selectedItemList: List - ) { - postAddTodoItemListUseCase( - requestPieceIdDto = RequestPieceIdDto(pieceIds = selectedItemList) - ).onSuccess { - Timber.tag("assignToToday").d("server viewmodel") - }.onFailure { error -> - Timber.tag("assignToToday").d(error) + private suspend fun postAddTodoItemList( + selectedItemList: List, + ) { + postAddTodoItemListUseCase( + requestPieceIdDto = RequestPieceIdDto(pieceIds = selectedItemList), + ).onSuccess { + Timber.tag("assignToToday").d("server viewmodel") + }.onFailure { error -> + Timber.tag("assignToToday").d(error) + } } } -} - diff --git a/app/src/main/java/org/android/bbangzip/presentation/util/constant/DateConstants.kt b/app/src/main/java/org/android/bbangzip/presentation/util/constant/DateConstants.kt index ed1ef04e..24dde950 100644 --- a/app/src/main/java/org/android/bbangzip/presentation/util/constant/DateConstants.kt +++ b/app/src/main/java/org/android/bbangzip/presentation/util/constant/DateConstants.kt @@ -7,4 +7,3 @@ object DateConstants { val YEARS_LIST = (YEAR_OF_TODAY..2028).map { it.toString() + "년" } val MONTHS_LIST = (1..12).map { it.toString() + "월" } } - diff --git a/app/src/main/java/org/android/bbangzip/presentation/util/constant/ToDoConstants.kt b/app/src/main/java/org/android/bbangzip/presentation/util/constant/ToDoConstants.kt index 8654cada..d8ff5f79 100644 --- a/app/src/main/java/org/android/bbangzip/presentation/util/constant/ToDoConstants.kt +++ b/app/src/main/java/org/android/bbangzip/presentation/util/constant/ToDoConstants.kt @@ -3,4 +3,4 @@ package org.android.bbangzip.presentation.util.constant object ToDoConstants { const val TODO = "todo" const val PENDING = "pending" -} \ No newline at end of file +} From 412d7980b9b233b852665a022d16f48a70de9252 Mon Sep 17 00:00:00 2001 From: beom84 Date: Tue, 21 Jan 2025 03:12:11 +0900 Subject: [PATCH 10/16] =?UTF-8?q?[feat]=20#46=20ktlint=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/android/bbangzip/presentation/ui/todo/TodoRoute.kt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoRoute.kt b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoRoute.kt index 754e266d..f98aa4e3 100644 --- a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoRoute.kt +++ b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/TodoRoute.kt @@ -1,5 +1,6 @@ package org.android.bbangzip.presentation.ui.todo +import android.app.Activity import androidx.compose.foundation.background import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.PaddingValues @@ -11,6 +12,8 @@ import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.toArgb +import androidx.compose.ui.platform.LocalView import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.Lifecycle import androidx.lifecycle.compose.LifecycleEventEffect @@ -34,6 +37,10 @@ fun TodoRoute( val todoState by viewModel.uiState.collectAsStateWithLifecycle() val success by viewModel.success.collectAsStateWithLifecycle(initialValue = false) val todayDate = LocalDateTime.now().format(DateTimeFormatter.ofPattern("MM-dd-E").withLocale(Locale.forLanguageTag("ko"))).split("-") + val view = LocalView.current + val activity = view.context as Activity + + activity.window.statusBarColor = BbangZipTheme.colors.backgroundAccent_FFDAA0.toArgb() LaunchedEffect(viewModel.uiSideEffect) { viewModel.uiSideEffect.collectLatest { effect -> From 8794f0b2b8fd440018c5cf2159876fc9cbd10c76 Mon Sep 17 00:00:00 2001 From: beom84 Date: Tue, 21 Jan 2025 04:06:00 +0900 Subject: [PATCH 11/16] =?UTF-8?q?[feat]=20#46=20badge=20=EC=BB=B4=ED=8F=AC?= =?UTF-8?q?=EB=84=8C=ED=8A=B8=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BbangZipGetBadgeBottomSheet.kt | 60 +++++++++++++++++++ app/src/main/res/values/strings.xml | 3 + 2 files changed, 63 insertions(+) create mode 100644 app/src/main/java/org/android/bbangzip/presentation/component/bottomsheet/BbangZipGetBadgeBottomSheet.kt diff --git a/app/src/main/java/org/android/bbangzip/presentation/component/bottomsheet/BbangZipGetBadgeBottomSheet.kt b/app/src/main/java/org/android/bbangzip/presentation/component/bottomsheet/BbangZipGetBadgeBottomSheet.kt new file mode 100644 index 00000000..f03ed202 --- /dev/null +++ b/app/src/main/java/org/android/bbangzip/presentation/component/bottomsheet/BbangZipGetBadgeBottomSheet.kt @@ -0,0 +1,60 @@ +package org.android.bbangzip.presentation.component.bottomsheet + +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.material3.Button +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.unit.dp +import org.android.bbangzip.R +import org.android.bbangzip.ui.theme.BbangZipTheme + +@OptIn(ExperimentalMaterial3Api::class) +@Composable +fun BbangZipGetBadgeBottomSheet( + isBottomSheetVisible: Boolean, + cancelButtonText: String, + modifier: Modifier = Modifier, + onDismissRequest: () -> Unit = {}, + onClickCancelButton: () -> Unit = {}, +) { + BbangZipBasicModalBottomSheet( + modifier = modifier, + isBottomSheetVisible = isBottomSheetVisible, + onDismissRequest = onDismissRequest, + content = { + Column( + modifier = Modifier.fillMaxWidth(), + horizontalAlignment = Alignment.CenterHorizontally, + ) { + Text( + text = stringResource(R.string.badge_get_bottom_sheet_title), + style = BbangZipTheme.typography.heading2Bold, + color = BbangZipTheme.colors.labelNormal_282119, + ) + + Spacer(modifier = Modifier.height(32.dp)) + } + }, + cancelButton = { + Spacer(modifier = Modifier.height(32.dp)) + + Button( + onClick = onClickCancelButton, + ) { + Text( + text = cancelButtonText, + style = BbangZipTheme.typography.body1Bold, + color = BbangZipTheme.colors.primaryNormal_282119, + ) + } + // TODO Button 집어넣기 + }, + ) +} diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 29d6b48f..cdbcca76 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -103,4 +103,7 @@ 오늘부터 하나씩!\n공부할 내용을 선택해 보세요 개 / 총 %s개 오늘 할 공부 추가하기 + + //badge + 배지를 획득했어요! \ No newline at end of file From 301565cefe2ff4520271755daac4c473c7df3eac Mon Sep 17 00:00:00 2001 From: beom84 Date: Tue, 21 Jan 2025 04:50:28 +0900 Subject: [PATCH 12/16] =?UTF-8?q?[feat]=20#46=20startDestination=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bbangzip/presentation/ui/navigator/MainNavigator.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/android/bbangzip/presentation/ui/navigator/MainNavigator.kt b/app/src/main/java/org/android/bbangzip/presentation/ui/navigator/MainNavigator.kt index 4ebd6e4b..8e819bd2 100644 --- a/app/src/main/java/org/android/bbangzip/presentation/ui/navigator/MainNavigator.kt +++ b/app/src/main/java/org/android/bbangzip/presentation/ui/navigator/MainNavigator.kt @@ -12,6 +12,7 @@ import org.android.bbangzip.presentation.model.BottomNavigationRoute import org.android.bbangzip.presentation.model.Route import org.android.bbangzip.presentation.type.BottomNavigationType import org.android.bbangzip.presentation.ui.friend.navigateFriend +import org.android.bbangzip.presentation.ui.login.LoginRoute import org.android.bbangzip.presentation.ui.login.navigateLogin import org.android.bbangzip.presentation.ui.my.navigateMy import org.android.bbangzip.presentation.ui.onboarding.navigation.navigateOnboarding @@ -29,7 +30,7 @@ class MainNavigator( private val currentDestination: NavDestination? @Composable get() = navHostController.currentBackStackEntryAsState().value?.destination - val startDestination = BottomNavigationType.TODO.route + val startDestination = LoginRoute val currentBottomNavigationBarItem: BottomNavigationType? @Composable get() = From b59dc0cecbc62a552391a493f53ba0b76c8532f0 Mon Sep 17 00:00:00 2001 From: beom84 Date: Tue, 21 Jan 2025 05:23:38 +0900 Subject: [PATCH 13/16] =?UTF-8?q?[feat]=20#46=20deadline=20parsing=20?= =?UTF-8?q?=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bbangzip/data/dto/response/ResponseTodayOrdersDto.kt | 5 ++++- .../android/bbangzip/data/dto/response/ResponseTodoDto.kt | 5 ++++- app/src/main/res/values/strings.xml | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/android/bbangzip/data/dto/response/ResponseTodayOrdersDto.kt b/app/src/main/java/org/android/bbangzip/data/dto/response/ResponseTodayOrdersDto.kt index c80fe6b3..cef24314 100644 --- a/app/src/main/java/org/android/bbangzip/data/dto/response/ResponseTodayOrdersDto.kt +++ b/app/src/main/java/org/android/bbangzip/data/dto/response/ResponseTodayOrdersDto.kt @@ -57,7 +57,10 @@ data class TodoInfo( studyContents = studyContents, startPage = startPage, finishPage = finishPage, - deadline = deadline, + deadline = + deadline.split("-").let { parts -> + "${parts[0]}년 ${parts[1].toInt()}월 ${parts[2].toInt()}일" + }, remainingDays = remainingDays, isFinished = isFinished, ) diff --git a/app/src/main/java/org/android/bbangzip/data/dto/response/ResponseTodoDto.kt b/app/src/main/java/org/android/bbangzip/data/dto/response/ResponseTodoDto.kt index abaedb5a..3312db27 100644 --- a/app/src/main/java/org/android/bbangzip/data/dto/response/ResponseTodoDto.kt +++ b/app/src/main/java/org/android/bbangzip/data/dto/response/ResponseTodoDto.kt @@ -48,7 +48,10 @@ data class TodoCardInfo( studyContents = studyContents, startPage = startPage, finishPage = finishPage, - deadline = deadline, + deadline = + deadline.split("-").let { parts -> + "${parts[0]}년 ${parts[1].toInt()}월 ${parts[2].toInt()}일" + }, remainingDays = remainingDays, ) } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index cdbcca76..25b170c5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -17,7 +17,7 @@ 더보기 버튼입니다. 사장님 D-%s - %s까지 + %s 까지 %sp - %sp %s / %s D+ From dfc096bef8dea8052bd6c8ee082f456a9bbbf9c8 Mon Sep 17 00:00:00 2001 From: beom84 Date: Tue, 21 Jan 2025 16:15:23 +0900 Subject: [PATCH 14/16] =?UTF-8?q?[feat]=20#46=20status=20bar=20=EC=83=89?= =?UTF-8?q?=EC=83=81=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/todo/pendingtodoadd/TodoAddPendingRoute.kt | 7 +++++++ .../bbangzip/presentation/ui/todo/todoadd/TodoAddRoute.kt | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/pendingtodoadd/TodoAddPendingRoute.kt b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/pendingtodoadd/TodoAddPendingRoute.kt index 27a1d87f..cdd7db36 100644 --- a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/pendingtodoadd/TodoAddPendingRoute.kt +++ b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/pendingtodoadd/TodoAddPendingRoute.kt @@ -1,5 +1,6 @@ package org.android.bbangzip.presentation.ui.todo.pendingtodoadd +import android.app.Activity import androidx.compose.foundation.background import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize @@ -11,6 +12,8 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.toArgb +import androidx.compose.ui.platform.LocalView import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle import kotlinx.coroutines.delay @@ -28,6 +31,10 @@ fun TodoAddPendingRoute( val todoAddPendingState by viewModel.uiState.collectAsStateWithLifecycle() val success by viewModel.success.collectAsStateWithLifecycle(initialValue = false) val todoAddsSnackBarHostState = remember { SnackbarHostState() } + val view = LocalView.current + val activity = view.context as Activity + + activity.window.statusBarColor = BbangZipTheme.colors.staticWhite_FFFFFF.toArgb() LaunchedEffect(viewModel.uiSideEffect) { viewModel.uiSideEffect.collectLatest { effect -> diff --git a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/todoadd/TodoAddRoute.kt b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/todoadd/TodoAddRoute.kt index 97a4ce18..e2859ce6 100644 --- a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/todoadd/TodoAddRoute.kt +++ b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/todoadd/TodoAddRoute.kt @@ -1,5 +1,6 @@ package org.android.bbangzip.presentation.ui.todo.todoadd +import android.app.Activity import androidx.compose.foundation.background import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize @@ -11,6 +12,8 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.toArgb +import androidx.compose.ui.platform.LocalView import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle import kotlinx.coroutines.delay @@ -28,6 +31,11 @@ fun TodoAddRoute( val todoAddState by viewModel.uiState.collectAsStateWithLifecycle() val success by viewModel.success.collectAsStateWithLifecycle(initialValue = false) val todoAddsSnackBarHostState = remember { SnackbarHostState() } + val view = LocalView.current + val activity = view.context as Activity + + activity.window.statusBarColor = BbangZipTheme.colors.staticWhite_FFFFFF.toArgb() + LaunchedEffect(viewModel.uiSideEffect) { viewModel.uiSideEffect.collectLatest { effect -> From a288765be28e503a37ffc6c283c7eb76f087ddb1 Mon Sep 17 00:00:00 2001 From: beom84 Date: Tue, 21 Jan 2025 16:16:26 +0900 Subject: [PATCH 15/16] [feat] #46 ktlint --- .../bbangzip/presentation/ui/todo/todoadd/TodoAddRoute.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/todoadd/TodoAddRoute.kt b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/todoadd/TodoAddRoute.kt index e2859ce6..19219c24 100644 --- a/app/src/main/java/org/android/bbangzip/presentation/ui/todo/todoadd/TodoAddRoute.kt +++ b/app/src/main/java/org/android/bbangzip/presentation/ui/todo/todoadd/TodoAddRoute.kt @@ -36,7 +36,6 @@ fun TodoAddRoute( activity.window.statusBarColor = BbangZipTheme.colors.staticWhite_FFFFFF.toArgb() - LaunchedEffect(viewModel.uiSideEffect) { viewModel.uiSideEffect.collectLatest { effect -> when (effect) { From 66c1a114d4e8a1579abc73b059ae1ece39ea9b74 Mon Sep 17 00:00:00 2001 From: beom84 Date: Wed, 22 Jan 2025 20:13:07 +0900 Subject: [PATCH 16/16] =?UTF-8?q?[feat]=20#46=20merge=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/org/android/bbangzip/di/RepositoryModule.kt | 3 --- app/src/main/java/org/android/bbangzip/di/UseCaseModule.kt | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/app/src/main/java/org/android/bbangzip/di/RepositoryModule.kt b/app/src/main/java/org/android/bbangzip/di/RepositoryModule.kt index 7da0a8a3..b9b1822c 100644 --- a/app/src/main/java/org/android/bbangzip/di/RepositoryModule.kt +++ b/app/src/main/java/org/android/bbangzip/di/RepositoryModule.kt @@ -4,10 +4,7 @@ import dagger.Binds import dagger.Module import dagger.hilt.InstallIn import dagger.hilt.components.SingletonComponent -import org.android.bbangzip.data.repositoryImpl.DummyRepositoryImpl import org.android.bbangzip.data.repositoryImpl.PieceRepositoryImpl -import org.android.bbangzip.data.repositoryImpl.UserRepositoryImpl -import org.android.bbangzip.domain.repository.local.UserRepository import org.android.bbangzip.data.repositoryImpl.local.UserLocalRepositoryImpl import org.android.bbangzip.data.repositoryImpl.remote.DummyRepositoryImpl import org.android.bbangzip.data.repositoryImpl.remote.UserRepositoryImpl diff --git a/app/src/main/java/org/android/bbangzip/di/UseCaseModule.kt b/app/src/main/java/org/android/bbangzip/di/UseCaseModule.kt index 54904dfd..a40eca82 100644 --- a/app/src/main/java/org/android/bbangzip/di/UseCaseModule.kt +++ b/app/src/main/java/org/android/bbangzip/di/UseCaseModule.kt @@ -15,8 +15,8 @@ import org.android.bbangzip.domain.usecase.GetToInfoUseCase import org.android.bbangzip.domain.usecase.PostAddTodoItemListUseCase import org.android.bbangzip.domain.usecase.PostCompleteCardIdUseCase import org.android.bbangzip.domain.usecase.PostDeletedItemListUseCase -import org.android.bbangzip.domain.usecase.PostUnCompleteCardIdUseCase import org.android.bbangzip.domain.usecase.PostOnboardingUseCase +import org.android.bbangzip.domain.usecase.PostUnCompleteCardIdUseCase import javax.inject.Singleton @Module