Skip to content

Commit

Permalink
[MERGE] #75 -> develop
Browse files Browse the repository at this point in the history
[FEAT/#75] μ•„μ›Œ, 마이 νˆ¬λ‘ 쑰회, 생성, μ‚­μ œ / μ„œλ²„ν†΅μ‹  κ΅¬ν˜„
  • Loading branch information
Marchbreeze authored Jan 12, 2024
2 parents 855add3 + 6c53ef4 commit 48f8540
Show file tree
Hide file tree
Showing 42 changed files with 827 additions and 243 deletions.
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
android:screenOrientation="portrait" />

<activity
android:name="com.going.presentation.todo.mytodo.detail.MyTodoDetailActivity"
android:name="com.going.presentation.todo.detail.PrivateDetailActivity"
android:exported="false"
android:screenOrientation="portrait" />

Expand All @@ -115,7 +115,7 @@
android:screenOrientation="portrait" />

<activity
android:name="com.going.presentation.todo.ourtodo.detail.OurTodoDetailActivity"
android:name="com.going.presentation.todo.detail.PublicDetailActivity"
android:exported="false"
android:screenOrientation="portrait" />

Expand Down
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
}
21 changes: 19 additions & 2 deletions data/src/main/java/com/going/data/datasource/TodoDataSource.kt
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
Expand Up @@ -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
Expand All @@ -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)

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
Expand Up @@ -18,7 +18,6 @@ data class TodoResponseDto(
@SerialName("secret")
val secret: Boolean
) {

@Serializable
data class TodoAllocatorResponseDto(
@SerialName("name")
Expand All @@ -29,7 +28,6 @@ data class TodoResponseDto(
fun toTodoAllocatorModel() =
TodoAllocatorModel(name, isOwner)
}

fun toTodoModel() =
TodoModel(todoId, title, endDate, allocators.map { it.toTodoAllocatorModel() }, secret)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.going.data.repositoryImpl

import com.going.data.datasource.TodoDataSource
import com.going.data.dto.request.toTodoCreateRequestDto
import com.going.domain.entity.request.TodoCreateRequestModel
import com.going.domain.entity.response.TodoDetailModel
import com.going.domain.entity.response.TodoModel
import com.going.domain.repository.TodoRepository
import javax.inject.Inject
Expand All @@ -18,4 +21,26 @@ class TodoRepositoryImpl @Inject constructor(
todoDataSource.getTodoListData(tripId, category, progress).data.map { it.toTodoModel() }
}

override suspend fun postToCreateTodo(
tripId: Long,
request: TodoCreateRequestModel
): Result<Unit> =
runCatching {
todoDataSource.postToCreateTodoData(tripId, request.toTodoCreateRequestDto())
}

override suspend fun deleteTodo(
todoId: Long
): Result<Unit> =
runCatching {
todoDataSource.deleteTodoData(todoId)
}

override suspend fun getTodoDetail(
todoId: Long
): Result<TodoDetailModel> =
runCatching {
todoDataSource.getTodoDetailData(todoId).data.toTodoDetailModel()
}

}
22 changes: 22 additions & 0 deletions data/src/main/java/com/going/data/service/TodoService.kt
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

Expand All @@ -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
): 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
@@ -1,5 +1,7 @@
package com.going.domain.repository

import com.going.domain.entity.request.TodoCreateRequestModel
import com.going.domain.entity.response.TodoDetailModel
import com.going.domain.entity.response.TodoModel

interface TodoRepository {
Expand All @@ -10,4 +12,17 @@ interface TodoRepository {
progress: String
): Result<List<TodoModel>>

suspend fun postToCreateTodo(
tripId: Long,
request: TodoCreateRequestModel
): Result<Unit>

suspend fun deleteTodo(
todoId: Long
): Result<Unit>

suspend fun getTodoDetail(
todoId: Long
): Result<TodoDetailModel>

}
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)
}

}
Loading

0 comments on commit 48f8540

Please sign in to comment.