Skip to content

Commit

Permalink
#58 feat: 사용자가 일정 추가하기 API 연동
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunBaee committed Jun 6, 2023
1 parent 1d3e55e commit 827ab80
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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<ResponseTodoGroupData>

@POST("/todo/groups")
suspend fun postTodoGroup(
@Body body : RequestTodoGroupData
) : Response<ResponseCommonWithString>
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -9,4 +10,8 @@ class TodoGroupRepositoryImpl @Inject constructor(private val todoGroupSource: T
override suspend fun getTodoGroupListData(): Result<List<GroupData>> {
return todoGroupSource.getTodoGroupListData()
}

override suspend fun postTodoGroupData(body: RequestTodoGroupData): Result<String> {
return todoGroupSource.postTodoGroupData(body)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.chunbae.narchive.data.remote.request

data class RequestTodoGroupData(
val groupTitle : String,
val groupColor : String
)
Original file line number Diff line number Diff line change
@@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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<String> {
val res = todoService.postTodoGroup(body)
if(res.isSuccessful) {
return Result.success(res.body()!!.result)
}
return Result.failure(IllegalArgumentException(res.message()))
}
}
Original file line number Diff line number Diff line change
@@ -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<List<GroupData>>

suspend fun postTodoGroupData(body : RequestTodoGroupData) : Result<String>
}
Original file line number Diff line number Diff line change
@@ -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<List<GroupData>>

suspend fun postTodoGroupData(body : RequestTodoGroupData) : Result<String>
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class AddTodoGroupDialog : DialogFragment() {

private fun checkTag() {
TAG = this.tag!!
Log.d("----", "checkTag: ${TAG}")
}

override fun onResume() {
Expand Down Expand Up @@ -73,7 +72,7 @@ class AddTodoGroupDialog : DialogFragment() {
}

fun onSaveGroup() {
viewModel.addNewGroup()
viewModel.addNewGroup(TAG)
dismissDialog()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -67,8 +68,8 @@ class WriteTodoViewModel @Inject constructor(private val todoGroupRepository: To
val selectedGroup : LiveData<GroupData> = _selectedGroup

var newGroupTitle = MutableLiveData<String>().apply { value = "" }
private val _newGroupColor = MutableLiveData<String>()
val newGroupColor : LiveData<String> = _newGroupColor
private val _newGroupColor = MutableLiveData<String?>()
val newGroupColor : LiveData<String?> = _newGroupColor

fun manageCalendarState(state: Int) { // 0:all gone / 1 : start Cal / 2 : end Cal / 3 : start Time / 4 : end Time
_isStartDay.value = state
Expand Down Expand Up @@ -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!!))
}

}
}
Expand Down

0 comments on commit 827ab80

Please sign in to comment.