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 18, 2023
1 parent 107e546 commit 64a1381
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,8 @@ interface TodoService {
@Query("pastGroupIdx") pastGroupIdx : Int,
@Query("curGroupIdx") curGroupIdx : Int
) : Response<ResponseCommonWithString>

@GET("/todo/default")
suspend fun getDefaultTodoGroup()
: Response<ResponseTodoGroupData>
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,10 @@ class TodoGroupRepositoryImpl @Inject constructor(private val todoGroupSource: T
override suspend fun patchDefaultTodoGroup(past: Int, cur: Int): Result<String> {
return todoGroupSource.patchDefaultTodoGroup(past, cur)
}

override suspend fun getDefaultTodoGroup(): Result<GroupData> {
return todoGroupSource.getDefaultTodoGroup()
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,16 @@ class TodoGroupRemoteSource @Inject constructor(private val todoService : TodoSe
override suspend fun patchDefaultTodoGroup(past: Int, cur: Int): Result<String> {
val res = todoService.setDefaultTodoGroup(past, cur)
if(res.isSuccessful) {
Log.d("----", "patchDefaultTodoGroup: SUCCESS")
return Result.success(res.body()!!.result)
}
Log.d("----", "patchDefaultTodoGroup: ${res.message()}")
return Result.failure(IllegalArgumentException(res.message()))
}

override suspend fun getDefaultTodoGroup(): Result<GroupData> {
val res = todoService.getDefaultTodoGroup()
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
Expand Up @@ -18,4 +18,6 @@ interface TodoGroupRepository {
suspend fun getTodoListData(date : String?) : Result<List<TodoData.TodoList>>

suspend fun patchDefaultTodoGroup(past : Int, cur : Int) : Result<String>

suspend fun getDefaultTodoGroup() : Result<GroupData>
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ interface TodoGroupSource {
suspend fun getTodoListData(date : String?) : Result<List<TodoData.TodoList>>

suspend fun patchDefaultTodoGroup(past : Int, cur : Int) : Result<String>

suspend fun getDefaultTodoGroup() : Result<GroupData>
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.chunbae.narchive.presentation.ui.main.todo.view

import android.icu.text.SimpleDateFormat
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand Down Expand Up @@ -53,6 +54,11 @@ class WriteTodoFragment : Fragment() {
todoViewModel.getGroupList()
}

override fun onResume() {
super.onResume()
todoViewModel.getDefaultTodoGroup()
}

private fun initBinding() {
binding.fragment = this
binding.todoViewModel = todoViewModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ class WriteTodoViewModel @Inject constructor(private val todoGroupRepository: To
_isAllday.value = _isAllday.value!!.not()
}

fun getDefaultTodoGroup() {
viewModelScope.launch {
todoGroupRepository.getDefaultTodoGroup()
.onSuccess { _selectedGroup.value = it }
}
}

fun saveTodo() {
Log.d("----", "saveTOdo: ${todoTitle.value} / ${startDate.value}-${startTime.value} / ${endDate.value}-${endTime.value} / ${isAllday.value} / ${_selectedGroup.value}")
}
Expand Down

0 comments on commit 64a1381

Please sign in to comment.