Skip to content

Commit

Permalink
Merge pull request #196 from team-winey/feature/mod-delete-feed-logic
Browse files Browse the repository at this point in the history
[mod] μœ„λ‹ˆν”Όλ“œ, λ§ˆμ΄ν”Όλ“œ / μ„œλ²„λ‘œλΆ€ν„° 받은 feed id둜 μ–΄λŒ‘ν„° μ•„μ΄ν…œ μ‚­μ œ
  • Loading branch information
leeeha authored Sep 14, 2023
2 parents 5509f17 + 608cad9 commit 2b63b71
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.go.sopt.winey.data.model.remote.response

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class ResponseDeleteFeedDto(
@SerialName("feedId")
val feedId: Long
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import okhttp3.RequestBody
import org.go.sopt.winey.data.model.remote.request.RequestPostCommentDto
import org.go.sopt.winey.data.model.remote.request.RequestPostLikeDto
import org.go.sopt.winey.data.model.remote.response.ResponseDeleteCommentDto
import org.go.sopt.winey.data.model.remote.response.ResponseDeleteFeedDto
import org.go.sopt.winey.data.model.remote.response.ResponsePostWineyFeedDto
import org.go.sopt.winey.data.service.FeedService
import org.go.sopt.winey.data.source.FeedDataSource
Expand Down Expand Up @@ -43,9 +44,9 @@ class FeedRepositoryImpl @Inject constructor(
feedDataSource.postWineyFeedList(file, requestMap).data
}

override suspend fun deleteFeed(feedId: Int): Result<Unit> =
override suspend fun deleteFeed(feedId: Int): Result<ResponseDeleteFeedDto?> =
runCatching {
feedDataSource.deleteFeed(feedId)
feedDataSource.deleteFeed(feedId).data
}

override suspend fun postFeedLike(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import okhttp3.RequestBody
import org.go.sopt.winey.data.model.remote.request.RequestPostCommentDto
import org.go.sopt.winey.data.model.remote.request.RequestPostLikeDto
import org.go.sopt.winey.data.model.remote.response.ResponseDeleteCommentDto
import org.go.sopt.winey.data.model.remote.response.ResponseDeleteFeedDto
import org.go.sopt.winey.data.model.remote.response.ResponseGetFeedDetailDto
import org.go.sopt.winey.data.model.remote.response.ResponseGetWineyFeedListDto
import org.go.sopt.winey.data.model.remote.response.ResponsePostCommentDto
Expand Down Expand Up @@ -41,7 +42,7 @@ interface FeedService {
@DELETE("feed/{feedId}")
suspend fun deleteFeed(
@Path("feedId") feedId: Int
): BaseResponse<Unit>
): BaseResponse<ResponseDeleteFeedDto>

@Multipart
@POST("feed")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import okhttp3.RequestBody
import org.go.sopt.winey.data.model.remote.request.RequestPostCommentDto
import org.go.sopt.winey.data.model.remote.request.RequestPostLikeDto
import org.go.sopt.winey.data.model.remote.response.ResponseDeleteCommentDto
import org.go.sopt.winey.data.model.remote.response.ResponseDeleteFeedDto
import org.go.sopt.winey.data.model.remote.response.ResponseGetFeedDetailDto
import org.go.sopt.winey.data.model.remote.response.ResponsePostCommentDto
import org.go.sopt.winey.data.model.remote.response.ResponsePostLikeDto
Expand All @@ -22,7 +23,7 @@ class FeedDataSource @Inject constructor(
): ResponsePostLikeDto =
feedService.postFeedLike(feedId, requestPostLikeDto)

suspend fun deleteFeed(feedId: Int): BaseResponse<Unit> =
suspend fun deleteFeed(feedId: Int): BaseResponse<ResponseDeleteFeedDto> =
feedService.deleteFeed(feedId)

suspend fun postWineyFeedList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import okhttp3.RequestBody
import org.go.sopt.winey.data.model.remote.request.RequestPostCommentDto
import org.go.sopt.winey.data.model.remote.request.RequestPostLikeDto
import org.go.sopt.winey.data.model.remote.response.ResponseDeleteCommentDto
import org.go.sopt.winey.data.model.remote.response.ResponseDeleteFeedDto
import org.go.sopt.winey.data.model.remote.response.ResponsePostWineyFeedDto
import org.go.sopt.winey.domain.entity.Comment
import org.go.sopt.winey.domain.entity.DetailFeed
Expand All @@ -20,7 +21,7 @@ interface FeedRepository {

suspend fun postFeedLike(feedId: Int, requestPostLikeDto: RequestPostLikeDto): Result<Like>

suspend fun deleteFeed(feedId: Int): Result<Unit>
suspend fun deleteFeed(feedId: Int): Result<ResponseDeleteFeedDto?>

suspend fun postWineyFeed(
file: MultipartBody.Part?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ class WineyFeedFragment :
private lateinit var wineyFeedHeaderAdapter: WineyFeedHeaderAdapter
private lateinit var wineyFeedLoadAdapter: WineyFeedLoadAdapter
private var clickedFeedId = -1
private var deleteFeedId = -1

@Inject
lateinit var dataStoreRepository: DataStoreRepository
Expand Down Expand Up @@ -191,7 +190,6 @@ class WineyFeedFragment :
stringOf(R.string.comment_delete_dialog_positive_button),
handleNegativeButton = {},
handlePositiveButton = {
deleteFeedId = feed.feedId
viewModel.deleteFeed(feed.feedId)
}
)
Expand Down Expand Up @@ -223,8 +221,9 @@ class WineyFeedFragment :
.onEach { state ->
when (state) {
is UiState.Success -> {
// todo: μ„œλ²„μ—μ„œ μ‘λ‹΅κ°’μœΌλ‘œ μ‚­μ œλœ ν”Όλ“œ 아이디 보내쀄 μ˜ˆμ •
deletePagingDataItem()
val response = state.data ?: return@onEach
deletePagingDataItem(response.feedId.toInt())

wineySnackbar(
binding.root,
true,
Expand All @@ -242,11 +241,10 @@ class WineyFeedFragment :
}.launchIn(viewLifeCycleScope)
}

private fun deletePagingDataItem() {
private fun deletePagingDataItem(feedId: Int) {
viewLifeCycleScope.launch {
val newList = wineyFeedAdapter.deleteItem(deleteFeedId)
val newList = wineyFeedAdapter.deleteItem(feedId)
wineyFeedAdapter.submitData(PagingData.from(newList))
deleteFeedId = -1
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
import org.go.sopt.winey.data.model.remote.request.RequestPostLikeDto
import org.go.sopt.winey.data.model.remote.response.ResponseDeleteFeedDto
import org.go.sopt.winey.domain.entity.DetailFeed
import org.go.sopt.winey.domain.entity.Like
import org.go.sopt.winey.domain.entity.WineyFeed
Expand All @@ -38,8 +39,10 @@ class WineyFeedViewModel @Inject constructor(
private val _postWineyFeedLikeState = MutableStateFlow<UiState<Like>>(UiState.Empty)
val postWineyFeedLikeState: StateFlow<UiState<Like>> = _postWineyFeedLikeState.asStateFlow()

private val _deleteWineyFeedState = MutableStateFlow<UiState<Unit>>(UiState.Empty)
val deleteWineyFeedState: StateFlow<UiState<Unit>> = _deleteWineyFeedState.asStateFlow()
private val _deleteWineyFeedState =
MutableStateFlow<UiState<ResponseDeleteFeedDto?>>(UiState.Empty)
val deleteWineyFeedState: StateFlow<UiState<ResponseDeleteFeedDto?>> =
_deleteWineyFeedState.asStateFlow()

init {
getWineyFeedList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import kotlinx.coroutines.launch
import org.go.sopt.winey.data.model.remote.request.RequestPostCommentDto
import org.go.sopt.winey.data.model.remote.request.RequestPostLikeDto
import org.go.sopt.winey.data.model.remote.response.ResponseDeleteCommentDto
import org.go.sopt.winey.data.model.remote.response.ResponseDeleteFeedDto
import org.go.sopt.winey.domain.entity.Comment
import org.go.sopt.winey.domain.entity.DetailFeed
import org.go.sopt.winey.domain.entity.Like
Expand Down Expand Up @@ -58,8 +59,10 @@ class DetailViewModel @Inject constructor(
private val _postFeedDetailLikeState = MutableStateFlow<UiState<Like>>(UiState.Loading)
val postFeedDetailLikeState: StateFlow<UiState<Like>> = _postFeedDetailLikeState.asStateFlow()

private val _deleteFeedDetailState = MutableStateFlow<UiState<Unit>>(UiState.Loading)
val deleteFeedDetailState: StateFlow<UiState<Unit>> = _deleteFeedDetailState.asStateFlow()
private val _deleteFeedDetailState =
MutableStateFlow<UiState<ResponseDeleteFeedDto?>>(UiState.Loading)
val deleteFeedDetailState: StateFlow<UiState<ResponseDeleteFeedDto?>> =
_deleteFeedDetailState.asStateFlow()

/** Comment */
private val _postCommentState = MutableStateFlow<UiState<Comment?>>(UiState.Loading)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class MyFeedFragment : BindingFragment<FragmentMyfeedBinding>(R.layout.fragment_
private lateinit var myFeedAdapter: MyFeedAdapter
private lateinit var wineyFeedLoadAdapter: WineyFeedLoadAdapter
private var clickedFeedId = -1
private var deleteFeedId = -1

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
Expand Down Expand Up @@ -141,7 +140,6 @@ class MyFeedFragment : BindingFragment<FragmentMyfeedBinding>(R.layout.fragment_
handleNegativeButton = {},
handlePositiveButton = {
viewModel.deleteFeed(feed.feedId)
deleteFeedId = feed.feedId
}
)
dialog.show(parentFragmentManager, TAG_FEED_DELETE_DIALOG)
Expand All @@ -158,8 +156,8 @@ class MyFeedFragment : BindingFragment<FragmentMyfeedBinding>(R.layout.fragment_
viewModel.deleteMyFeedState.flowWithLifecycle(viewLifeCycle).onEach { state ->
when (state) {
is UiState.Success -> {
// todo: μ„œλ²„μ—μ„œ μ‘λ‹΅κ°’μœΌλ‘œ μ‚­μ œλœ ν”Όλ“œ 아이디 보내쀄 μ˜ˆμ •
deletePagingDataItem(deleteFeedId)
val response = state.data ?: return@onEach
deletePagingDataItem(response.feedId.toInt())

wineySnackbar(
binding.root,
Expand All @@ -183,7 +181,6 @@ class MyFeedFragment : BindingFragment<FragmentMyfeedBinding>(R.layout.fragment_
val newList = myFeedAdapter.deleteItem(feedId)
checkEmptyList(newList)
myFeedAdapter.submitData(PagingData.from(newList))
deleteFeedId = -1
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
import org.go.sopt.winey.data.model.remote.request.RequestPostLikeDto
import org.go.sopt.winey.data.model.remote.response.ResponseDeleteFeedDto
import org.go.sopt.winey.domain.entity.DetailFeed
import org.go.sopt.winey.domain.entity.Like
import org.go.sopt.winey.domain.entity.WineyFeed
Expand All @@ -31,15 +32,17 @@ class MyFeedViewModel @Inject constructor(
_getMyFeedListState.asStateFlow()

private val _getDetailFeedState =
MutableStateFlow<UiState<DetailFeed?>>(UiState.Loading)
MutableStateFlow<UiState<DetailFeed?>>(UiState.Empty)
val getDetailFeedState: StateFlow<UiState<DetailFeed?>> =
_getDetailFeedState.asStateFlow()

private val _postMyFeedLikeState = MutableStateFlow<UiState<Like>>(UiState.Empty)
val postMyFeedLikeState: StateFlow<UiState<Like>> = _postMyFeedLikeState.asStateFlow()

private val _deleteMyFeedState = MutableStateFlow<UiState<Unit>>(UiState.Empty)
val deleteMyFeedState: StateFlow<UiState<Unit>> = _deleteMyFeedState.asStateFlow()
private val _deleteMyFeedState =
MutableStateFlow<UiState<ResponseDeleteFeedDto?>>(UiState.Empty)
val deleteMyFeedState: StateFlow<UiState<ResponseDeleteFeedDto?>> =
_deleteMyFeedState.asStateFlow()

init {
getMyFeedList()
Expand Down Expand Up @@ -95,6 +98,8 @@ class MyFeedViewModel @Inject constructor(

fun deleteFeed(feedId: Int) {
viewModelScope.launch {
_deleteMyFeedState.emit(UiState.Loading)

feedRepository.deleteFeed(feedId)
.onSuccess { response ->
_deleteMyFeedState.emit(UiState.Success(response))
Expand Down

0 comments on commit 2b63b71

Please sign in to comment.