Skip to content
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

[mod] 위니피드, 마이피드 / 서버로부터 받은 feed id로 어댑터 아이템 삭제 #196

Merged
merged 4 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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