-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEAT/#75] 아워, 마이 투두 조회, 생성, 삭제 / 서버통신 구현 #84
Changes from all commits
1af6549
60e5dc5
ad7909a
1120f79
6f5cc28
7cfc768
b480609
8bc3278
ce03bfe
bc5a4ba
51b60f0
0d3c6b4
80917f1
897d666
eb035e4
5344db0
2cf2949
565b90b
0df653d
178c13b
b826501
a59e1be
2f9d0e7
94136f5
94861e8
55b048a
d5bfbc9
6c53ef4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package com.going.ui.extension | ||
|
||
enum class EnumUiState { | ||
SUCCESS, FAILURE, LOADING, EMPTY | ||
LOADING, SUCCESS, FAILURE, EMPTY | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,30 @@ | ||
package com.going.data.datasource | ||
|
||
import com.going.data.dto.BaseResponse | ||
import com.going.data.dto.NonDataBaseResponse | ||
import com.going.data.dto.request.TodoCreateRequestDto | ||
import com.going.data.dto.response.TodoDetailResponseDto | ||
import com.going.data.dto.response.TodoResponseDto | ||
|
||
interface TodoDataSource { | ||
|
||
suspend fun getTodoListData( | ||
tripId: Long, | ||
category: String, | ||
progress: String, | ||
progress: String | ||
): BaseResponse<List<TodoResponseDto>> | ||
} | ||
|
||
suspend fun postToCreateTodoData( | ||
tripId: Long, | ||
request: TodoCreateRequestDto | ||
): NonDataBaseResponse<Unit> | ||
|
||
suspend fun deleteTodoData( | ||
todoId: Long | ||
): NonDataBaseResponse<Unit> | ||
|
||
suspend fun getTodoDetailData( | ||
todoId: Long | ||
): BaseResponse<TodoDetailResponseDto> | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,9 @@ package com.going.data.datasourceImpl | |
|
||
import com.going.data.datasource.TodoDataSource | ||
import com.going.data.dto.BaseResponse | ||
import com.going.data.dto.NonDataBaseResponse | ||
import com.going.data.dto.request.TodoCreateRequestDto | ||
import com.going.data.dto.response.TodoDetailResponseDto | ||
import com.going.data.dto.response.TodoResponseDto | ||
import com.going.data.service.TodoService | ||
import javax.inject.Inject | ||
|
@@ -17,4 +20,20 @@ class TodoDataSourceImpl @Inject constructor( | |
): BaseResponse<List<TodoResponseDto>> = | ||
todoService.getTodoList(tripId, category, progress) | ||
|
||
override suspend fun postToCreateTodoData( | ||
tripId: Long, | ||
request: TodoCreateRequestDto | ||
): NonDataBaseResponse<Unit> = | ||
todoService.postToCreateTodo(tripId, request) | ||
Comment on lines
+25
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 받아올게 없어서요 ~ |
||
|
||
override suspend fun deleteTodoData( | ||
todoId: Long | ||
): NonDataBaseResponse<Unit> = | ||
todoService.deleteTodo(todoId) | ||
|
||
override suspend fun getTodoDetailData( | ||
todoId: Long | ||
): BaseResponse<TodoDetailResponseDto> = | ||
todoService.getTodoDetail(todoId) | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.going.data.dto.request | ||
|
||
import com.going.domain.entity.request.TodoCreateRequestModel | ||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class TodoCreateRequestDto( | ||
@SerialName("title") | ||
val title: String, | ||
@SerialName("endDate") | ||
val endDate: String, | ||
@SerialName("allocators") | ||
val allocators: List<Long>, | ||
@SerialName("memo") | ||
val memo: String?, | ||
@SerialName("secret") | ||
val secret: Boolean | ||
) | ||
|
||
fun TodoCreateRequestModel.toTodoCreateRequestDto(): TodoCreateRequestDto = | ||
TodoCreateRequestDto(title, endDate, allocators, memo, secret) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.going.data.dto.response | ||
|
||
import com.going.domain.entity.response.TodoDetailModel | ||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class TodoDetailResponseDto( | ||
@SerialName("title") | ||
val title: String, | ||
@SerialName("endDate") | ||
val endDate: String, | ||
@SerialName("allocators") | ||
val allocators: List<TodoResponseDto.TodoAllocatorResponseDto>, | ||
@SerialName("memo") | ||
val memo: String, | ||
@SerialName("secret") | ||
val secret: Boolean | ||
) { | ||
fun toTodoDetailModel(): TodoDetailModel = | ||
TodoDetailModel(title, endDate, allocators.map { it.toTodoAllocatorModel() }, memo, secret) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
package com.going.data.service | ||
|
||
import com.going.data.dto.BaseResponse | ||
import com.going.data.dto.NonDataBaseResponse | ||
import com.going.data.dto.request.TodoCreateRequestDto | ||
import com.going.data.dto.response.TodoDetailResponseDto | ||
import com.going.data.dto.response.TodoResponseDto | ||
import retrofit2.http.Body | ||
import retrofit2.http.DELETE | ||
import retrofit2.http.GET | ||
import retrofit2.http.POST | ||
import retrofit2.http.Path | ||
import retrofit2.http.Query | ||
|
||
|
@@ -15,4 +21,20 @@ interface TodoService { | |
@Query("progress") progress: String | ||
): BaseResponse<List<TodoResponseDto>> | ||
|
||
@POST("api/trips/{tripId}/todos") | ||
suspend fun postToCreateTodo( | ||
@Path("tripId") tripId: Long, | ||
@Body request: TodoCreateRequestDto | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이렇게 감싸야하는군요 오늘도 배워갑니다 |
||
): NonDataBaseResponse<Unit> | ||
|
||
@DELETE("api/trips/todos/{todoId}") | ||
suspend fun deleteTodo( | ||
@Path("todoId") todoId: Long | ||
): NonDataBaseResponse<Unit> | ||
|
||
@GET("api/trips/todos/{todoId}") | ||
suspend fun getTodoDetail( | ||
@Path("todoId") todoId: Long | ||
): BaseResponse<TodoDetailResponseDto> | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.going.domain.entity.request | ||
|
||
data class TodoCreateRequestModel( | ||
val title: String, | ||
val endDate: String, | ||
val allocators: List<Long>, | ||
val memo: String?, | ||
val secret: Boolean | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.going.domain.entity.response | ||
|
||
data class TodoDetailModel( | ||
val title: String, | ||
val endDate: String, | ||
val allocators: List<TodoAllocatorModel>, | ||
val memo: String, | ||
val secret: Boolean | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package com.going.presentation.todo.detail | ||
|
||
import android.os.Bundle | ||
import androidx.activity.viewModels | ||
import androidx.lifecycle.flowWithLifecycle | ||
import androidx.lifecycle.lifecycleScope | ||
import com.going.presentation.R | ||
import com.going.presentation.databinding.ActivityPrivateDetailBinding | ||
import com.going.presentation.todo.detail.PublicDetailActivity.Companion.EXTRA_TODO_ID | ||
import com.going.ui.base.BaseActivity | ||
import com.going.ui.extension.EnumUiState | ||
import com.going.ui.extension.setOnSingleClickListener | ||
import com.going.ui.extension.toast | ||
import dagger.hilt.android.AndroidEntryPoint | ||
import kotlinx.coroutines.flow.launchIn | ||
import kotlinx.coroutines.flow.onEach | ||
|
||
@AndroidEntryPoint | ||
class PrivateDetailActivity : | ||
BaseActivity<ActivityPrivateDetailBinding>(R.layout.activity_private_detail) { | ||
|
||
private val viewModel by viewModels<PrivateDetailViewModel>() | ||
|
||
private var todoId: Long = 0 | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
initViewModel() | ||
initBackBtnClickListener() | ||
initDeleteBtnClickListener() | ||
initModBtnClickListener() | ||
getTodoId() | ||
setDetailData() | ||
observeTodoDetailState() | ||
observeTodoDeleteState() | ||
} | ||
|
||
private fun initViewModel() { | ||
binding.vm = viewModel | ||
} | ||
|
||
private fun initBackBtnClickListener() { | ||
binding.btnMyTodoDetailBack.setOnSingleClickListener { | ||
finish() | ||
} | ||
} | ||
|
||
private fun initDeleteBtnClickListener() { | ||
binding.btnMyTodoDetailDelete.setOnSingleClickListener { | ||
viewModel.deleteTodoFromServer(todoId) | ||
} | ||
} | ||
|
||
private fun initModBtnClickListener() { | ||
binding.btnMyTodoDetailMod.setOnSingleClickListener { | ||
toast(getString(R.string.will_be_update)) | ||
} | ||
} | ||
|
||
private fun getTodoId() { | ||
todoId = intent.getLongExtra(EXTRA_TODO_ID, 0) | ||
} | ||
|
||
private fun setDetailData() { | ||
viewModel.getTodoDetailFromServer(todoId) | ||
} | ||
|
||
private fun observeTodoDetailState() { | ||
viewModel.todoDetailState.flowWithLifecycle(lifecycle).onEach { state -> | ||
when (state) { | ||
EnumUiState.LOADING -> return@onEach | ||
|
||
EnumUiState.SUCCESS -> return@onEach | ||
|
||
EnumUiState.FAILURE -> toast(getString(R.string.server_error)) | ||
|
||
EnumUiState.EMPTY -> return@onEach | ||
} | ||
}.launchIn(lifecycleScope) | ||
} | ||
|
||
private fun observeTodoDeleteState() { | ||
viewModel.todoDeleteState.flowWithLifecycle(lifecycle).onEach { state -> | ||
when (state) { | ||
EnumUiState.LOADING -> return@onEach | ||
|
||
EnumUiState.SUCCESS -> { | ||
toast(getString(R.string.todo_delete_toast)) | ||
finish() | ||
} | ||
|
||
EnumUiState.FAILURE -> toast(getString(R.string.server_error)) | ||
|
||
EnumUiState.EMPTY -> return@onEach | ||
} | ||
}.launchIn(lifecycleScope) | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
요거 다시 보니까 T를 안쓰는데 T를 받아오더라구여!
그래서 NoDataBaseResponse에서 NoDataBaseResponse로 수정했습니다! 조만간 올릴텐데 그때 맞춰서 수정하면 좋을 것 같아용~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
네넨