diff --git a/app/src/main/java/com/chunbae/narchive/data/remote/api/TodoService.kt b/app/src/main/java/com/chunbae/narchive/data/remote/api/TodoService.kt index b1b0779..09745c5 100644 --- a/app/src/main/java/com/chunbae/narchive/data/remote/api/TodoService.kt +++ b/app/src/main/java/com/chunbae/narchive/data/remote/api/TodoService.kt @@ -1,11 +1,20 @@ package com.chunbae.narchive.data.remote.api +import com.chunbae.narchive.data.remote.request.RequestTodoGroupData +import com.chunbae.narchive.data.remote.response.ResponseCommonWithString import com.chunbae.narchive.data.remote.response.ResponseTodoGroupData import retrofit2.Response +import retrofit2.http.Body import retrofit2.http.GET +import retrofit2.http.POST interface TodoService { @GET("/todo/groups") suspend fun getTodoGroupList() : Response + + @POST("/todo/groups") + suspend fun postTodoGroup( + @Body body : RequestTodoGroupData + ) : Response } \ No newline at end of file diff --git a/app/src/main/java/com/chunbae/narchive/data/remote/repository/TodoGroupRepositoryImpl.kt b/app/src/main/java/com/chunbae/narchive/data/remote/repository/TodoGroupRepositoryImpl.kt index ca54aa1..9ac8f38 100644 --- a/app/src/main/java/com/chunbae/narchive/data/remote/repository/TodoGroupRepositoryImpl.kt +++ b/app/src/main/java/com/chunbae/narchive/data/remote/repository/TodoGroupRepositoryImpl.kt @@ -1,6 +1,7 @@ package com.chunbae.narchive.data.remote.repository import com.chunbae.narchive.data.data.GroupData +import com.chunbae.narchive.data.remote.request.RequestTodoGroupData import com.chunbae.narchive.domain.repository.TodoGroupRepository import com.chunbae.narchive.domain.source.TodoGroupSource import javax.inject.Inject @@ -9,4 +10,8 @@ class TodoGroupRepositoryImpl @Inject constructor(private val todoGroupSource: T override suspend fun getTodoGroupListData(): Result> { return todoGroupSource.getTodoGroupListData() } + + override suspend fun postTodoGroupData(body: RequestTodoGroupData): Result { + return todoGroupSource.postTodoGroupData(body) + } } \ No newline at end of file diff --git a/app/src/main/java/com/chunbae/narchive/data/remote/request/RequestTodoGroupData.kt b/app/src/main/java/com/chunbae/narchive/data/remote/request/RequestTodoGroupData.kt new file mode 100644 index 0000000..9d6167e --- /dev/null +++ b/app/src/main/java/com/chunbae/narchive/data/remote/request/RequestTodoGroupData.kt @@ -0,0 +1,6 @@ +package com.chunbae.narchive.data.remote.request + +data class RequestTodoGroupData( + val groupTitle : String, + val groupColor : String +) diff --git a/app/src/main/java/com/chunbae/narchive/data/remote/response/ResponseCommonWithString.kt b/app/src/main/java/com/chunbae/narchive/data/remote/response/ResponseCommonWithString.kt new file mode 100644 index 0000000..4540da3 --- /dev/null +++ b/app/src/main/java/com/chunbae/narchive/data/remote/response/ResponseCommonWithString.kt @@ -0,0 +1,7 @@ +package com.chunbae.narchive.data.remote.response + +import com.chunbae.narchive.presentation.util.BaseResponse + +data class ResponseCommonWithString( + val result : String +) : BaseResponse() diff --git a/app/src/main/java/com/chunbae/narchive/data/remote/source/TodoGroupRemoteSource.kt b/app/src/main/java/com/chunbae/narchive/data/remote/source/TodoGroupRemoteSource.kt index 06fba62..276ad73 100644 --- a/app/src/main/java/com/chunbae/narchive/data/remote/source/TodoGroupRemoteSource.kt +++ b/app/src/main/java/com/chunbae/narchive/data/remote/source/TodoGroupRemoteSource.kt @@ -2,6 +2,7 @@ package com.chunbae.narchive.data.remote.source import com.chunbae.narchive.data.data.GroupData import com.chunbae.narchive.data.remote.api.TodoService +import com.chunbae.narchive.data.remote.request.RequestTodoGroupData import com.chunbae.narchive.domain.source.TodoGroupSource import javax.inject.Inject @@ -13,4 +14,12 @@ class TodoGroupRemoteSource @Inject constructor(private val todoService : TodoSe } return Result.failure(IllegalArgumentException(res.message())) } + + override suspend fun postTodoGroupData(body: RequestTodoGroupData): Result { + val res = todoService.postTodoGroup(body) + if(res.isSuccessful) { + return Result.success(res.body()!!.result) + } + return Result.failure(IllegalArgumentException(res.message())) + } } \ No newline at end of file diff --git a/app/src/main/java/com/chunbae/narchive/domain/repository/TodoGroupRepository.kt b/app/src/main/java/com/chunbae/narchive/domain/repository/TodoGroupRepository.kt index c5deabf..6c879d5 100644 --- a/app/src/main/java/com/chunbae/narchive/domain/repository/TodoGroupRepository.kt +++ b/app/src/main/java/com/chunbae/narchive/domain/repository/TodoGroupRepository.kt @@ -1,8 +1,11 @@ package com.chunbae.narchive.domain.repository import com.chunbae.narchive.data.data.GroupData +import com.chunbae.narchive.data.remote.request.RequestTodoGroupData interface TodoGroupRepository { suspend fun getTodoGroupListData() : Result> + + suspend fun postTodoGroupData(body : RequestTodoGroupData) : Result } \ No newline at end of file diff --git a/app/src/main/java/com/chunbae/narchive/domain/source/TodoGroupSource.kt b/app/src/main/java/com/chunbae/narchive/domain/source/TodoGroupSource.kt index 342ecab..bad686c 100644 --- a/app/src/main/java/com/chunbae/narchive/domain/source/TodoGroupSource.kt +++ b/app/src/main/java/com/chunbae/narchive/domain/source/TodoGroupSource.kt @@ -1,8 +1,11 @@ package com.chunbae.narchive.domain.source import com.chunbae.narchive.data.data.GroupData +import com.chunbae.narchive.data.remote.request.RequestTodoGroupData interface TodoGroupSource { suspend fun getTodoGroupListData() : Result> + + suspend fun postTodoGroupData(body : RequestTodoGroupData) : Result } \ No newline at end of file diff --git a/app/src/main/java/com/chunbae/narchive/presentation/ui/main/dialog/AddTodoGroupDialog.kt b/app/src/main/java/com/chunbae/narchive/presentation/ui/main/dialog/AddTodoGroupDialog.kt index 865685c..b4b9928 100644 --- a/app/src/main/java/com/chunbae/narchive/presentation/ui/main/dialog/AddTodoGroupDialog.kt +++ b/app/src/main/java/com/chunbae/narchive/presentation/ui/main/dialog/AddTodoGroupDialog.kt @@ -42,7 +42,6 @@ class AddTodoGroupDialog : DialogFragment() { private fun checkTag() { TAG = this.tag!! - Log.d("----", "checkTag: ${TAG}") } override fun onResume() { @@ -73,7 +72,7 @@ class AddTodoGroupDialog : DialogFragment() { } fun onSaveGroup() { - viewModel.addNewGroup() + viewModel.addNewGroup(TAG) dismissDialog() } diff --git a/app/src/main/java/com/chunbae/narchive/presentation/ui/main/todo/viewmodel/WriteTodoViewModel.kt b/app/src/main/java/com/chunbae/narchive/presentation/ui/main/todo/viewmodel/WriteTodoViewModel.kt index 1678865..a9c5fd6 100644 --- a/app/src/main/java/com/chunbae/narchive/presentation/ui/main/todo/viewmodel/WriteTodoViewModel.kt +++ b/app/src/main/java/com/chunbae/narchive/presentation/ui/main/todo/viewmodel/WriteTodoViewModel.kt @@ -7,6 +7,7 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.chunbae.narchive.data.data.GroupData +import com.chunbae.narchive.data.remote.request.RequestTodoGroupData import com.chunbae.narchive.domain.repository.TodoGroupRepository import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.launch @@ -67,8 +68,8 @@ class WriteTodoViewModel @Inject constructor(private val todoGroupRepository: To val selectedGroup : LiveData = _selectedGroup var newGroupTitle = MutableLiveData().apply { value = "" } - private val _newGroupColor = MutableLiveData() - val newGroupColor : LiveData = _newGroupColor + private val _newGroupColor = MutableLiveData() + val newGroupColor : LiveData = _newGroupColor fun manageCalendarState(state: Int) { // 0:all gone / 1 : start Cal / 2 : end Cal / 3 : start Time / 4 : end Time _isStartDay.value = state @@ -127,8 +128,12 @@ class WriteTodoViewModel @Inject constructor(private val todoGroupRepository: To _newGroupColor.value = color } - fun addNewGroup() { + fun addNewGroup(tag : String) { if(newGroupTitle.value != null && _newGroupColor.value != null) { + viewModelScope.launch { + if(tag == "ADD") + todoGroupRepository.postTodoGroupData(RequestTodoGroupData(newGroupTitle.value!!, newGroupColor.value!!)) + } } }