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

[feat] 위니 피드 / 상세페이지 피드, 댓글 조회 #125

Merged
merged 17 commits into from
Aug 20, 2023
Merged
Show file tree
Hide file tree
Changes from 15 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,81 @@
package com.android.go.sopt.winey.data.model.remote.response

import com.android.go.sopt.winey.domain.entity.CommentList
import com.android.go.sopt.winey.domain.entity.DetailFeed
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class ResponseGetFeedDetailDto(
@SerialName("getFeedResponseDto")
val getFeedResponseDto: GetFeedResponseDto,
@SerialName("getCommentResponseList")
val getCommentResponseList: List<GetCommentResponseList>
) {
@Serializable
data class GetFeedResponseDto(
@SerialName("createdAt")
val createdAt: String,
@SerialName("feedId")
val feedId: Int,
@SerialName("feedImage")
val feedImage: String,
@SerialName("feedMoney")
val feedMoney: Long,
@SerialName("feedTitle")
val feedTitle: String,
@SerialName("isLiked")
val isLiked: Boolean,
@SerialName("likes")
val likes: Long,
@SerialName("nickName")
val nickName: String,
@SerialName("userId")
val userId: Int,
@SerialName("writerLevel")
val writerLevel: Int,
@SerialName("comments")
val comments: Long,
@SerialName("timeAgo")
val timeAgo: String
)

@Serializable
data class GetCommentResponseList(
@SerialName("commentId")
val commentId: Long,
@SerialName("author")
val author: String,
@SerialName("content")
val content: String,
@SerialName("createdAt")
val createdAt: String,
@SerialName("authorLevel")
val authorLevel: Int,
@SerialName("authorId")
val authorId: Int
)

fun toDetailFeed(): DetailFeed = DetailFeed(
feedId = getFeedResponseDto.feedId,
feedImage = getFeedResponseDto.feedImage,
feedMoney = getFeedResponseDto.feedMoney,
feedTitle = getFeedResponseDto.feedTitle,
isLiked = getFeedResponseDto.isLiked,
likes = getFeedResponseDto.likes,
nickName = getFeedResponseDto.nickName,
userId = getFeedResponseDto.userId,
writerLevel = getFeedResponseDto.writerLevel,
comments = getFeedResponseDto.comments,
timeAgo = getFeedResponseDto.timeAgo,
commentList = getCommentResponseList.map { list ->
CommentList(
commentId = list.commentId,
author = list.author,
content = list.content,
authorId = list.authorId,
authorLevel = list.authorLevel
)
}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.android.go.sopt.winey.data.service.FeedService
import com.android.go.sopt.winey.data.source.FeedDataSource
import com.android.go.sopt.winey.data.source.paging.MyFeedPagingSource
import com.android.go.sopt.winey.data.source.paging.WineyFeedPagingSource
import com.android.go.sopt.winey.domain.entity.DetailFeed
import com.android.go.sopt.winey.domain.entity.Like
import com.android.go.sopt.winey.domain.entity.WineyFeed
import com.android.go.sopt.winey.domain.repository.FeedRepository
Expand Down Expand Up @@ -52,6 +53,11 @@ class FeedRepositoryImpl @Inject constructor(
feedDataSource.postFeedLike(feedId, requestPostLikeDto).toLike()
}

override suspend fun getFeedDetail(feedId: Int): Result<DetailFeed?> =
runCatching {
feedDataSource.getFeedDetail(feedId).data?.toDetailFeed()
}

companion object {
const val WINEYFEED_PAGE_SIZE = 20
const val MYFEED_PAGE_SIZE = 10
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.android.go.sopt.winey.data.service

import com.android.go.sopt.winey.data.model.remote.request.RequestPostLikeDto
import com.android.go.sopt.winey.data.model.remote.response.ResponseGetFeedDetailDto
import com.android.go.sopt.winey.data.model.remote.response.ResponseGetWineyFeedListDto
import com.android.go.sopt.winey.data.model.remote.response.ResponsePostLikeDto
import com.android.go.sopt.winey.data.model.remote.response.ResponsePostWineyFeedDto
Expand Down Expand Up @@ -45,4 +46,9 @@ interface FeedService {
@Part file: MultipartBody.Part?,
@PartMap requestMap: HashMap<String, RequestBody>
): BaseResponse<ResponsePostWineyFeedDto>

@GET("feed/{feedId}")
suspend fun getFeedDetail(
@Path("feedId") feedId: Int
): BaseResponse<ResponseGetFeedDetailDto>
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.android.go.sopt.winey.data.source

import com.android.go.sopt.winey.data.model.remote.request.RequestPostLikeDto
import com.android.go.sopt.winey.data.model.remote.response.ResponseGetFeedDetailDto
import com.android.go.sopt.winey.data.model.remote.response.ResponsePostLikeDto
import com.android.go.sopt.winey.data.model.remote.response.ResponsePostWineyFeedDto
import com.android.go.sopt.winey.data.model.remote.response.base.BaseResponse
Expand All @@ -26,4 +27,9 @@ class FeedDataSource @Inject constructor(
requestMap: HashMap<String, RequestBody>
): BaseResponse<ResponsePostWineyFeedDto> =
feedService.postWineyFeed(file, requestMap)

suspend fun getFeedDetail(
feedId: Int
): BaseResponse<ResponseGetFeedDetailDto> =
feedService.getFeedDetail(feedId)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.android.go.sopt.winey.domain.entity

data class DetailFeed(
val feedId: Int,
val feedImage: String,
val feedMoney: Long,
val feedTitle: String,
var isLiked: Boolean,
var likes: Long,
val nickName: String,
val userId: Int,
val writerLevel: Int,
val comments: Long,
val timeAgo: String,
val commentList: List<CommentList>
)

data class CommentList(
val commentId: Long,
val author: String,
val content: String,
val authorLevel: Int,
val authorId: Int
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.android.go.sopt.winey.domain.repository
import androidx.paging.PagingData
import com.android.go.sopt.winey.data.model.remote.request.RequestPostLikeDto
import com.android.go.sopt.winey.data.model.remote.response.ResponsePostWineyFeedDto
import com.android.go.sopt.winey.domain.entity.DetailFeed
import com.android.go.sopt.winey.domain.entity.Like
import com.android.go.sopt.winey.domain.entity.WineyFeed
import kotlinx.coroutines.flow.Flow
Expand All @@ -22,4 +23,6 @@ interface FeedRepository {
file: MultipartBody.Part?,
requestMap: HashMap<String, RequestBody>
): Result<ResponsePostWineyFeedDto?>

suspend fun getFeedDetail(feedId: Int): Result<DetailFeed?>
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import com.android.go.sopt.winey.util.view.setOnSingleClickListener

class WineyFeedAdapter(
private val likeButtonClick: (feedId: Int, isLiked: Boolean) -> Unit,
private val showPopupMenu: (View, WineyFeed) -> Unit
private val showPopupMenu: (View, WineyFeed) -> Unit,
private val toFeedDetail: (feedId: Int, writerLevel: Int) -> Unit
) :
PagingDataAdapter<WineyFeed, WineyFeedAdapter.WineyFeedViewHolder>(diffUtil) {
private val currentData: ItemSnapshotList<WineyFeed>
Expand All @@ -23,7 +24,8 @@ class WineyFeedAdapter(
class WineyFeedViewHolder(
private val binding: ItemWineyfeedPostBinding,
private val onLikeButtonClick: (feedId: Int, isLiked: Boolean) -> Unit,
private val showPopupMenu: (View, WineyFeed) -> Unit
private val showPopupMenu: (View, WineyFeed) -> Unit,
private val toFeedDetail: (feedId: Int, writerLevel: Int) -> Unit
) : RecyclerView.ViewHolder(binding.root) {

fun onBind(data: WineyFeed?) {
Expand All @@ -37,9 +39,13 @@ class WineyFeedAdapter(
onLikeButtonClick(data.feedId, !data.isLiked)
}

btnWineyfeedMore.setOnClickListener { view ->
btnWineyfeedMore.setOnSingleClickListener { view ->
showPopupMenu(view, data)
}

lWineyfeedPost.setOnSingleClickListener {
toFeedDetail(data.feedId, data.writerLevel)
}
}
}

Expand All @@ -60,7 +66,7 @@ class WineyFeedAdapter(
): WineyFeedViewHolder {
val binding =
ItemWineyfeedPostBinding.inflate(LayoutInflater.from(parent.context), parent, false)
return WineyFeedViewHolder(binding, likeButtonClick, showPopupMenu)
return WineyFeedViewHolder(binding, likeButtonClick, showPopupMenu, toFeedDetail)
}

override fun onBindViewHolder(holder: WineyFeedViewHolder, position: Int) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.widget.PopupWindow
import android.widget.TextView
import androidx.core.view.isVisible
import androidx.fragment.app.activityViewModels
import androidx.fragment.app.commit
import androidx.fragment.app.viewModels
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.flowWithLifecycle
Expand All @@ -22,6 +23,7 @@ import com.android.go.sopt.winey.domain.entity.WineyFeed
import com.android.go.sopt.winey.domain.repository.DataStoreRepository
import com.android.go.sopt.winey.presentation.main.AlertDialogFragment
import com.android.go.sopt.winey.presentation.main.MainViewModel
import com.android.go.sopt.winey.presentation.main.feed.detail.DetailFragment
import com.android.go.sopt.winey.presentation.main.feed.upload.UploadActivity
import com.android.go.sopt.winey.util.binding.BindingFragment
import com.android.go.sopt.winey.util.fragment.snackBar
Expand Down Expand Up @@ -70,7 +72,8 @@ class WineyFeedFragment : BindingFragment<FragmentWineyFeedBinding>(R.layout.fra
},
showPopupMenu = { view, wineyFeed ->
showPopupMenu(view, wineyFeed)
}
},
toFeedDetail = { feedId, writerLevel -> navigateDetail(feedId, writerLevel) }
)
binding.rvWineyfeedPost.adapter = ConcatAdapter(
wineyFeedHeaderAdapter,
Expand All @@ -95,7 +98,7 @@ class WineyFeedFragment : BindingFragment<FragmentWineyFeedBinding>(R.layout.fra
menuDelete.isVisible = false
}
menuDelete.setOnSingleClickListener {
showDeleteDialog(wineyFeed.feedId, wineyFeed.writerLevel)
showDeleteDialog(wineyFeed.feedId)
popupWindow.dismiss()
}
popupWindow.showAsDropDown(view)
Expand All @@ -109,17 +112,10 @@ class WineyFeedFragment : BindingFragment<FragmentWineyFeedBinding>(R.layout.fra
}
}

private fun showDeleteDialog(feedId: Int, userLevel: Int) {
val dialogSub: Int =
if (userLevel <= LV_KNIGHT) {
R.string.myfeed_dialog_lowlevel_sub
} else {
R.string.myfeed_dialog_highlevel_sub
}

private fun showDeleteDialog(feedId: Int) {
val deleteDialog = AlertDialogFragment(
getString(R.string.wineyfeed_dialog_title),
getString(dialogSub),
getString(R.string.myfeed_dialog_title),
getString(R.string.myfeed_dialog_sub),
getString(R.string.wineyfeed_dialog_cancel),
getString(R.string.myfeed_dialog_delete),
handleNegativeButton = { },
Expand Down Expand Up @@ -234,8 +230,14 @@ class WineyFeedFragment : BindingFragment<FragmentWineyFeedBinding>(R.layout.fra
startActivity(intent)
}

private fun navigateDetail(feedId: Int, writerLevel: Int) {
parentFragmentManager.commit {
replace(R.id.fcv_main, DetailFragment(feedId, writerLevel))
addToBackStack(null)
}
}

companion object {
private const val LV_KNIGHT = 2
private const val TAG_WINEYFEED_DIALOG = "NO_GOAL_DIALOG"
private const val MSG_WINEYFEED_ERROR = "ERROR"
private const val TAG_DELETE_DIALOG = "DELETE_DIALOG"
Expand Down
Loading