From 7b02137ea2522fa534a005c2d7f671ec313c2f62 Mon Sep 17 00:00:00 2001 From: leeeha Date: Thu, 14 Sep 2023 20:34:35 +0900 Subject: [PATCH 1/4] =?UTF-8?q?[mod]=20#195=20=ED=94=BC=EB=93=9C=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20DTO=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/remote/response/ResponseDeleteFeedDto.kt | 10 ++++++++++ .../sopt/winey/data/repository/FeedRepositoryImpl.kt | 5 +++-- .../java/org/go/sopt/winey/data/service/FeedService.kt | 3 ++- .../org/go/sopt/winey/data/source/FeedDataSource.kt | 3 ++- .../go/sopt/winey/domain/repository/FeedRepository.kt | 3 ++- 5 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 app/src/main/java/org/go/sopt/winey/data/model/remote/response/ResponseDeleteFeedDto.kt diff --git a/app/src/main/java/org/go/sopt/winey/data/model/remote/response/ResponseDeleteFeedDto.kt b/app/src/main/java/org/go/sopt/winey/data/model/remote/response/ResponseDeleteFeedDto.kt new file mode 100644 index 00000000..846edaf0 --- /dev/null +++ b/app/src/main/java/org/go/sopt/winey/data/model/remote/response/ResponseDeleteFeedDto.kt @@ -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 +) diff --git a/app/src/main/java/org/go/sopt/winey/data/repository/FeedRepositoryImpl.kt b/app/src/main/java/org/go/sopt/winey/data/repository/FeedRepositoryImpl.kt index d17afb25..087fa656 100644 --- a/app/src/main/java/org/go/sopt/winey/data/repository/FeedRepositoryImpl.kt +++ b/app/src/main/java/org/go/sopt/winey/data/repository/FeedRepositoryImpl.kt @@ -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 @@ -43,9 +44,9 @@ class FeedRepositoryImpl @Inject constructor( feedDataSource.postWineyFeedList(file, requestMap).data } - override suspend fun deleteFeed(feedId: Int): Result = + override suspend fun deleteFeed(feedId: Int): Result = runCatching { - feedDataSource.deleteFeed(feedId) + feedDataSource.deleteFeed(feedId).data } override suspend fun postFeedLike( diff --git a/app/src/main/java/org/go/sopt/winey/data/service/FeedService.kt b/app/src/main/java/org/go/sopt/winey/data/service/FeedService.kt index 46fa68e7..601be349 100644 --- a/app/src/main/java/org/go/sopt/winey/data/service/FeedService.kt +++ b/app/src/main/java/org/go/sopt/winey/data/service/FeedService.kt @@ -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 @@ -41,7 +42,7 @@ interface FeedService { @DELETE("feed/{feedId}") suspend fun deleteFeed( @Path("feedId") feedId: Int - ): BaseResponse + ): BaseResponse @Multipart @POST("feed") diff --git a/app/src/main/java/org/go/sopt/winey/data/source/FeedDataSource.kt b/app/src/main/java/org/go/sopt/winey/data/source/FeedDataSource.kt index ae329dc1..b0b18e48 100644 --- a/app/src/main/java/org/go/sopt/winey/data/source/FeedDataSource.kt +++ b/app/src/main/java/org/go/sopt/winey/data/source/FeedDataSource.kt @@ -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 @@ -22,7 +23,7 @@ class FeedDataSource @Inject constructor( ): ResponsePostLikeDto = feedService.postFeedLike(feedId, requestPostLikeDto) - suspend fun deleteFeed(feedId: Int): BaseResponse = + suspend fun deleteFeed(feedId: Int): BaseResponse = feedService.deleteFeed(feedId) suspend fun postWineyFeedList( diff --git a/app/src/main/java/org/go/sopt/winey/domain/repository/FeedRepository.kt b/app/src/main/java/org/go/sopt/winey/domain/repository/FeedRepository.kt index afab5096..26b00523 100644 --- a/app/src/main/java/org/go/sopt/winey/domain/repository/FeedRepository.kt +++ b/app/src/main/java/org/go/sopt/winey/domain/repository/FeedRepository.kt @@ -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 @@ -20,7 +21,7 @@ interface FeedRepository { suspend fun postFeedLike(feedId: Int, requestPostLikeDto: RequestPostLikeDto): Result - suspend fun deleteFeed(feedId: Int): Result + suspend fun deleteFeed(feedId: Int): Result suspend fun postWineyFeed( file: MultipartBody.Part?, From 021ac4b77137942f838726cf40fad981d49a7ca9 Mon Sep 17 00:00:00 2001 From: leeeha Date: Thu, 14 Sep 2023 20:41:11 +0900 Subject: [PATCH 2/4] =?UTF-8?q?[mod]=20#195=20=EC=9C=84=EB=8B=88=ED=94=BC?= =?UTF-8?q?=EB=93=9C=20=EC=82=AD=EC=A0=9C=20=EC=BD=94=EB=93=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/main/feed/WineyFeedFragment.kt | 12 +++++------- .../presentation/main/feed/WineyFeedViewModel.kt | 7 +++++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/org/go/sopt/winey/presentation/main/feed/WineyFeedFragment.kt b/app/src/main/java/org/go/sopt/winey/presentation/main/feed/WineyFeedFragment.kt index a2e1ee80..dad38e8e 100644 --- a/app/src/main/java/org/go/sopt/winey/presentation/main/feed/WineyFeedFragment.kt +++ b/app/src/main/java/org/go/sopt/winey/presentation/main/feed/WineyFeedFragment.kt @@ -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 @@ -191,7 +190,6 @@ class WineyFeedFragment : stringOf(R.string.comment_delete_dialog_positive_button), handleNegativeButton = {}, handlePositiveButton = { - deleteFeedId = feed.feedId viewModel.deleteFeed(feed.feedId) } ) @@ -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, @@ -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 } } diff --git a/app/src/main/java/org/go/sopt/winey/presentation/main/feed/WineyFeedViewModel.kt b/app/src/main/java/org/go/sopt/winey/presentation/main/feed/WineyFeedViewModel.kt index 630b0815..c16785bf 100644 --- a/app/src/main/java/org/go/sopt/winey/presentation/main/feed/WineyFeedViewModel.kt +++ b/app/src/main/java/org/go/sopt/winey/presentation/main/feed/WineyFeedViewModel.kt @@ -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 @@ -38,8 +39,10 @@ class WineyFeedViewModel @Inject constructor( private val _postWineyFeedLikeState = MutableStateFlow>(UiState.Empty) val postWineyFeedLikeState: StateFlow> = _postWineyFeedLikeState.asStateFlow() - private val _deleteWineyFeedState = MutableStateFlow>(UiState.Empty) - val deleteWineyFeedState: StateFlow> = _deleteWineyFeedState.asStateFlow() + private val _deleteWineyFeedState = + MutableStateFlow>(UiState.Empty) + val deleteWineyFeedState: StateFlow> = + _deleteWineyFeedState.asStateFlow() init { getWineyFeedList() From f6c79acba0a27e488fc8f46edc30a84931b7cb3b Mon Sep 17 00:00:00 2001 From: leeeha Date: Thu, 14 Sep 2023 20:45:47 +0900 Subject: [PATCH 3/4] =?UTF-8?q?[mod]=20#195=20=EB=A7=88=EC=9D=B4=ED=94=BC?= =?UTF-8?q?=EB=93=9C=20=EC=82=AD=EC=A0=9C=20=EC=BD=94=EB=93=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/main/mypage/myfeed/MyFeedFragment.kt | 7 ++----- .../main/mypage/myfeed/MyFeedViewModel.kt | 11 ++++++++--- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/org/go/sopt/winey/presentation/main/mypage/myfeed/MyFeedFragment.kt b/app/src/main/java/org/go/sopt/winey/presentation/main/mypage/myfeed/MyFeedFragment.kt index aa240fe2..b6cb32e1 100644 --- a/app/src/main/java/org/go/sopt/winey/presentation/main/mypage/myfeed/MyFeedFragment.kt +++ b/app/src/main/java/org/go/sopt/winey/presentation/main/mypage/myfeed/MyFeedFragment.kt @@ -41,7 +41,6 @@ class MyFeedFragment : BindingFragment(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) @@ -141,7 +140,6 @@ class MyFeedFragment : BindingFragment(R.layout.fragment_ handleNegativeButton = {}, handlePositiveButton = { viewModel.deleteFeed(feed.feedId) - deleteFeedId = feed.feedId } ) dialog.show(parentFragmentManager, TAG_FEED_DELETE_DIALOG) @@ -158,8 +156,8 @@ class MyFeedFragment : BindingFragment(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, @@ -183,7 +181,6 @@ class MyFeedFragment : BindingFragment(R.layout.fragment_ val newList = myFeedAdapter.deleteItem(feedId) checkEmptyList(newList) myFeedAdapter.submitData(PagingData.from(newList)) - deleteFeedId = -1 } } diff --git a/app/src/main/java/org/go/sopt/winey/presentation/main/mypage/myfeed/MyFeedViewModel.kt b/app/src/main/java/org/go/sopt/winey/presentation/main/mypage/myfeed/MyFeedViewModel.kt index d78adc9f..1a227886 100644 --- a/app/src/main/java/org/go/sopt/winey/presentation/main/mypage/myfeed/MyFeedViewModel.kt +++ b/app/src/main/java/org/go/sopt/winey/presentation/main/mypage/myfeed/MyFeedViewModel.kt @@ -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 @@ -31,15 +32,17 @@ class MyFeedViewModel @Inject constructor( _getMyFeedListState.asStateFlow() private val _getDetailFeedState = - MutableStateFlow>(UiState.Loading) + MutableStateFlow>(UiState.Empty) val getDetailFeedState: StateFlow> = _getDetailFeedState.asStateFlow() private val _postMyFeedLikeState = MutableStateFlow>(UiState.Empty) val postMyFeedLikeState: StateFlow> = _postMyFeedLikeState.asStateFlow() - private val _deleteMyFeedState = MutableStateFlow>(UiState.Empty) - val deleteMyFeedState: StateFlow> = _deleteMyFeedState.asStateFlow() + private val _deleteMyFeedState = + MutableStateFlow>(UiState.Empty) + val deleteMyFeedState: StateFlow> = + _deleteMyFeedState.asStateFlow() init { getMyFeedList() @@ -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)) From 608cad9a28e33eb23970e065c78939b20a0672dc Mon Sep 17 00:00:00 2001 From: leeeha Date: Thu, 14 Sep 2023 20:48:43 +0900 Subject: [PATCH 4/4] =?UTF-8?q?[mod]=20#195=20=EC=83=81=EC=84=B8=ED=94=BC?= =?UTF-8?q?=EB=93=9C=20=EC=82=AD=EC=A0=9C=20=EC=BD=94=EB=93=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../winey/presentation/main/feed/detail/DetailViewModel.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/go/sopt/winey/presentation/main/feed/detail/DetailViewModel.kt b/app/src/main/java/org/go/sopt/winey/presentation/main/feed/detail/DetailViewModel.kt index 3e623f15..625b0689 100644 --- a/app/src/main/java/org/go/sopt/winey/presentation/main/feed/detail/DetailViewModel.kt +++ b/app/src/main/java/org/go/sopt/winey/presentation/main/feed/detail/DetailViewModel.kt @@ -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 @@ -58,8 +59,10 @@ class DetailViewModel @Inject constructor( private val _postFeedDetailLikeState = MutableStateFlow>(UiState.Loading) val postFeedDetailLikeState: StateFlow> = _postFeedDetailLikeState.asStateFlow() - private val _deleteFeedDetailState = MutableStateFlow>(UiState.Loading) - val deleteFeedDetailState: StateFlow> = _deleteFeedDetailState.asStateFlow() + private val _deleteFeedDetailState = + MutableStateFlow>(UiState.Loading) + val deleteFeedDetailState: StateFlow> = + _deleteFeedDetailState.asStateFlow() /** Comment */ private val _postCommentState = MutableStateFlow>(UiState.Loading)