Skip to content

Commit

Permalink
Merge pull request #256 from Team-WSS/feat/249
Browse files Browse the repository at this point in the history
feat: 피드 상세보기 뷰 댓글 기능 구현
  • Loading branch information
s9hn committed Aug 28, 2024
2 parents 9c2bd81 + 4e70a42 commit 015a71c
Show file tree
Hide file tree
Showing 27 changed files with 578 additions and 172 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fun CommentsResponseDto.toData(): CommentsEntity = CommentsEntity(

fun CommentResponseDto.toData(): CommentEntity = CommentEntity(
user = UserEntity(
id = userId.toLong(),
id = userId,
nickname = nickname,
avatarImage = avatarImage,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.teamwss.websoso.data.model.FeedEntity.UserEntity
data class CommentEntity(
val user: UserEntity,
val commentContent: String,
val commentId: Int,
val commentId: Long,
val createdDate: String,
val isModified: Boolean,
val isMyComment: Boolean,
Expand Down
58 changes: 46 additions & 12 deletions app/src/main/java/com/teamwss/websoso/data/remote/api/FeedApi.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package com.teamwss.websoso.data.remote.api

import com.teamwss.websoso.data.remote.request.CommentRequestDto
import com.teamwss.websoso.data.remote.response.CommentsResponseDto
import com.teamwss.websoso.data.remote.response.FeedDetailResponseDto
import com.teamwss.websoso.data.remote.response.FeedsResponseDto
import com.teamwss.websoso.data.remote.response.PopularFeedsResponseDto
import com.teamwss.websoso.data.remote.response.UserInterestFeedsResponseDto
import retrofit2.http.Body
import retrofit2.http.DELETE
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.PUT
import retrofit2.http.Path
import retrofit2.http.Query

Expand All @@ -25,16 +28,27 @@ interface FeedApi {
@Path("feedId") feedId: Long,
): FeedDetailResponseDto

@GET("feeds/{feedId}/comments")
suspend fun getComments(
@Path("feedId") feedId: Long,
): CommentsResponseDto
@GET("feeds/popular")
suspend fun getPopularFeeds(): PopularFeedsResponseDto

@GET("feeds/interest")
suspend fun getUserInterestFeeds(): UserInterestFeedsResponseDto

@DELETE("feeds/{feedId}")
suspend fun deleteFeed(
@Path("feedId") feedId: Long,
)

@POST("feeds/{feedId}/spoiler")
suspend fun postSpoilerFeed(
@Path("feedId") feedId: Long,
)

@POST("feeds/{feedId}/impertinence")
suspend fun postImpertinenceFeed(
@Path("feedId") feedId: Long,
)

@POST("feeds/{feedId}/likes")
suspend fun postLikes(
@Path("feedId") feedId: Long,
Expand All @@ -45,19 +59,39 @@ interface FeedApi {
@Path("feedId") feedId: Long,
)

@POST("feeds/{feedId}/spoiler")
suspend fun postSpoilerFeed(
@GET("feeds/{feedId}/comments")
suspend fun getComments(
@Path("feedId") feedId: Long,
): CommentsResponseDto

@POST("feeds/{feedId}/comments")
suspend fun postComment(
@Path("feedId") feedId: Long,
@Body commentRequestDto: CommentRequestDto,
)

@POST("feeds/{feedId}/impertinence")
suspend fun postImpertinenceFeed(
@PUT("feeds/{feedId}/comments/{commentId}")
suspend fun putComment(
@Path("feedId") feedId: Long,
@Path("commentId") commentId: Long,
@Body commentRequestDto: CommentRequestDto,
)

@GET("feeds/popular")
suspend fun getPopularFeeds(): PopularFeedsResponseDto
@DELETE("feeds/{feedId}/comments/{commentId}")
suspend fun deleteComment(
@Path("feedId") feedId: Long,
@Path("commentId") commentId: Long,
)

@GET("feeds/interest")
suspend fun getUserInterestFeeds(): UserInterestFeedsResponseDto
@POST("feeds/{feedId}/comments/{commentId}/spoiler")
suspend fun postSpoilerComment(
@Path("feedId") feedId: Long,
@Path("commentId") commentId: Long,
)

@POST("feeds/{feedId}/comments/{commentId}/impertinence")
suspend fun postImpertinenceComment(
@Path("feedId") feedId: Long,
@Path("commentId") commentId: Long,
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.teamwss.websoso.data.remote.request

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

@Serializable
data class CommentRequestDto(
@SerialName("commentContent") val commentContent: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ data class CommentResponseDto(
@SerialName("commentContent")
val commentContent: String,
@SerialName("commentId")
val commentId: Int,
val commentId: Long,
@SerialName("createdDate")
val createdDate: String,
@SerialName("isModified")
Expand All @@ -20,5 +20,5 @@ data class CommentResponseDto(
@SerialName("nickname")
val nickname: String,
@SerialName("userId")
val userId: Int,
val userId: Long,
)
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.teamwss.websoso.data.repository

import android.util.Log
import com.teamwss.websoso.data.mapper.toData
import com.teamwss.websoso.data.model.CommentsEntity
import com.teamwss.websoso.data.model.FeedEntity
import com.teamwss.websoso.data.model.FeedsEntity
import com.teamwss.websoso.data.model.PopularFeedsEntity
import com.teamwss.websoso.data.model.UserInterestFeedsEntity
import com.teamwss.websoso.data.remote.api.FeedApi
import com.teamwss.websoso.data.remote.request.CommentRequestDto
import javax.inject.Inject

class FeedRepository @Inject constructor(
Expand All @@ -15,6 +17,10 @@ class FeedRepository @Inject constructor(
private val _cachedFeeds: MutableList<FeedEntity> = mutableListOf()
val cachedFeeds: List<FeedEntity> get() = _cachedFeeds.toList()

fun clearCachedFeeds() {
if (cachedFeeds.isNotEmpty()) _cachedFeeds.clear()
}

suspend fun fetchFeeds(category: String, lastFeedId: Long, size: Int): FeedsEntity =
feedApi.getFeeds(
category = if (category == "all") null else category,
Expand All @@ -26,40 +32,53 @@ class FeedRepository @Inject constructor(

suspend fun fetchFeed(feedId: Long): FeedEntity = feedApi.getFeed(feedId).toData()

suspend fun fetchComments(feedId: Long): CommentsEntity = feedApi.getComments(feedId).toData()
suspend fun fetchPopularFeeds(): PopularFeedsEntity {
return feedApi.getPopularFeeds().toData()
}

suspend fun fetchUserInterestFeeds(): UserInterestFeedsEntity {
return feedApi.getUserInterestFeeds().toData()
}

suspend fun saveRemovedFeed(feedId: Long) {
feedApi.deleteFeed(feedId).also { _cachedFeeds.removeIf { it.id == feedId } }
}

suspend fun saveSpoilerFeed(feedId: Long) {
feedApi.postSpoilerFeed(feedId).also { _cachedFeeds.removeIf { it.id == feedId } }
}

suspend fun saveImpertinenceFeed(feedId: Long) {
feedApi.postImpertinenceFeed(feedId).also { _cachedFeeds.removeIf { it.id == feedId } }
}

suspend fun saveLike(isLikedOfLikedFeed: Boolean, selectedFeedId: Long) {

return when (isLikedOfLikedFeed) {
when (isLikedOfLikedFeed) {
true -> feedApi.deleteLikes(selectedFeedId)
false -> feedApi.postLikes(selectedFeedId)
}
}

suspend fun saveRemovedFeed(feedId: Long) {
return feedApi.deleteFeed(feedId)
.also { _cachedFeeds.removeIf { it.id == feedId } }
}
suspend fun fetchComments(feedId: Long): CommentsEntity = feedApi.getComments(feedId).toData()

suspend fun saveSpoilerFeed(feedId: Long) {
return feedApi.postSpoilerFeed(feedId)
.also { _cachedFeeds.removeIf { it.id == feedId } }
suspend fun saveComment(feedId: Long, comment: String) {
feedApi.postComment(feedId, CommentRequestDto(comment))
}

suspend fun saveImpertinenceFeed(feedId: Long) {
return feedApi.postImpertinenceFeed(feedId)
.also { _cachedFeeds.removeIf { it.id == feedId } }
suspend fun saveModifiedComment(feedId: Long, commentId: Long, comment: String) {
feedApi.putComment(feedId, commentId, CommentRequestDto(comment))
}

fun clearCachedFeeds() {
if (cachedFeeds.isNotEmpty()) _cachedFeeds.clear()
suspend fun deleteComment(feedId: Long, commentId: Long) {
feedApi.deleteComment(feedId, commentId)
}

suspend fun fetchPopularFeeds(): PopularFeedsEntity {
return feedApi.getPopularFeeds().toData()
suspend fun saveSpoilerComment(feedId: Long, commentId: Long) {
feedApi.postSpoilerComment(feedId, commentId)
}

suspend fun fetchUserInterestFeeds(): UserInterestFeedsEntity {
return feedApi.getUserInterestFeeds().toData()
suspend fun saveImpertinenceComment(feedId: Long, commentId: Long) {
feedApi.postImpertinenceComment(feedId, commentId)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.teamwss.websoso.ui.feedDetail

import android.view.View

interface CommentClickListener {

fun onProfileClick(userId: Long, isMyComment: Boolean)

fun onMoreButtonClick(view: View, commentId: Long, isMyComment: Boolean)
}
Loading

0 comments on commit 015a71c

Please sign in to comment.