Skip to content

Commit 06cbc08

Browse files
authored
Merge pull request #805 from Team-WSS/fix/801
fix: 피드 QA 반영
2 parents dc17392 + 872b613 commit 06cbc08

70 files changed

Lines changed: 3397 additions & 2659 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/build.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ android {
7474
}
7575
}
7676

77+
// 룸 디비 제거
78+
// 좋아요 기능 좀더 생각해보기
79+
7780
dependencies {
7881
// 프로젝트 의존성
7982
implementation(projects.core.resource)
@@ -83,7 +86,6 @@ dependencies {
8386
implementation(projects.core.authKakao)
8487
implementation(projects.core.network)
8588
implementation(projects.core.datastore)
86-
implementation(projects.core.database)
8789

8890
implementation(projects.data.account)
8991
implementation(projects.data.library)

app/src/main/java/com/into/websoso/data/repository/FeedRepository.kt

Lines changed: 138 additions & 178 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.into.websoso.data.repository
22

33
import android.net.Uri
44
import com.into.websoso.core.common.util.ImageCompressor
5-
import com.into.websoso.data.library.datasource.LibraryLocalDataSource
65
import com.into.websoso.data.mapper.MultiPartMapper
76
import com.into.websoso.data.mapper.toData
87
import com.into.websoso.data.model.CommentsEntity
@@ -20,201 +19,162 @@ import javax.inject.Singleton
2019

2120
@Singleton
2221
class FeedRepository
23-
@Inject
24-
constructor(
25-
private val feedApi: FeedApi,
26-
private val multiPartMapper: MultiPartMapper,
27-
private val imageDownloader: ImageDownloader,
28-
private val imageCompressor: ImageCompressor,
29-
private val libraryLocalDataSource: LibraryLocalDataSource,
30-
) {
31-
private val _cachedFeeds: MutableList<FeedEntity> = mutableListOf()
32-
val cachedFeeds: List<FeedEntity> get() = _cachedFeeds.toList()
33-
34-
fun clearCachedFeeds() {
35-
if (cachedFeeds.isNotEmpty()) _cachedFeeds.clear()
36-
}
37-
38-
suspend fun fetchFeeds(
39-
category: String,
40-
lastFeedId: Long,
41-
size: Int,
42-
): FeedsEntity =
43-
feedApi
44-
.getFeeds(
45-
category = if (category == "all") null else category,
46-
lastFeedId = lastFeedId,
47-
size = size,
48-
).toData()
49-
.also { _cachedFeeds.addAll(it.feeds) }
50-
.copy(feeds = cachedFeeds)
51-
52-
suspend fun saveFeed(
53-
relevantCategories: List<String>,
54-
feedContent: String,
55-
novelId: Long?,
56-
isSpoiler: Boolean,
57-
isPublic: Boolean,
58-
images: List<Uri>,
59-
) {
60-
runCatching {
61-
feedApi.postFeed(
62-
feedRequestDto = multiPartMapper.formatToMultipart<FeedRequestDto>(
63-
target = FeedRequestDto(
64-
relevantCategories = relevantCategories,
65-
feedContent = feedContent,
66-
novelId = novelId,
67-
isSpoiler = isSpoiler,
68-
isPublic = isPublic,
69-
),
70-
partName = PART_NAME_FEED,
71-
fileName = "feed.json",
72-
),
73-
images = images.map { multiPartMapper.formatToMultipart(it) },
74-
)
75-
}.onSuccess {
76-
val novel = novelId?.let { id ->
77-
libraryLocalDataSource.selectNovelByNovelId(id)
78-
}
79-
80-
if (novel != null) {
81-
val updatedNovel = novel.copy(myFeeds = listOf(feedContent) + novel.myFeeds)
82-
libraryLocalDataSource.insertNovel(updatedNovel)
83-
}
84-
}
85-
}
86-
87-
suspend fun saveEditedFeed(
88-
feedId: Long,
89-
relevantCategories: List<String>,
90-
editedFeed: String,
91-
legacyFeed: String,
92-
novelId: Long?,
93-
isSpoiler: Boolean,
94-
isPublic: Boolean,
95-
images: List<Uri>,
96-
) {
97-
runCatching {
98-
feedApi.putFeed(
99-
feedId = feedId,
100-
feedRequestDto = multiPartMapper.formatToMultipart<FeedRequestDto>(
101-
target = FeedRequestDto(
102-
relevantCategories = relevantCategories,
103-
feedContent = editedFeed,
104-
novelId = novelId,
105-
isSpoiler = isSpoiler,
106-
isPublic = isPublic,
107-
),
108-
partName = "feed",
109-
fileName = "feed.json",
110-
),
111-
images = images.map { multiPartMapper.formatToMultipart(it) },
112-
)
113-
}.onSuccess {
114-
val novel = novelId?.let { id ->
115-
libraryLocalDataSource.selectNovelByNovelId(id)
116-
}
117-
118-
if (novel != null) {
119-
val updatedNovel = novel.copy(
120-
myFeeds = novel.myFeeds.map { currentFeed ->
121-
if (currentFeed == legacyFeed) editedFeed else currentFeed
122-
},
123-
)
124-
libraryLocalDataSource.insertNovel(updatedNovel)
125-
}
126-
}
127-
}
22+
@Inject
23+
constructor(
24+
private val feedApi: FeedApi,
25+
private val multiPartMapper: MultiPartMapper,
26+
private val imageDownloader: ImageDownloader,
27+
private val imageCompressor: ImageCompressor,
28+
) {
29+
private val _cachedFeeds: MutableList<FeedEntity> = mutableListOf()
30+
val cachedFeeds: List<FeedEntity> get() = _cachedFeeds.toList()
31+
32+
fun clearCachedFeeds() {
33+
if (cachedFeeds.isNotEmpty()) _cachedFeeds.clear()
34+
}
12835

129-
suspend fun fetchFeed(feedId: Long): FeedDetailEntity = feedApi.getFeed(feedId).toData()
36+
suspend fun fetchFeeds(
37+
category: String,
38+
lastFeedId: Long,
39+
size: Int,
40+
): FeedsEntity =
41+
feedApi
42+
.getFeeds(
43+
category = if (category == "all") null else category,
44+
lastFeedId = lastFeedId,
45+
size = size,
46+
).toData()
47+
.also { _cachedFeeds.addAll(it.feeds) }
48+
.copy(feeds = cachedFeeds)
49+
50+
suspend fun saveFeed(
51+
relevantCategories: List<String>,
52+
feedContent: String,
53+
novelId: Long?,
54+
isSpoiler: Boolean,
55+
isPublic: Boolean,
56+
images: List<Uri>,
57+
) {
58+
feedApi.postFeed(
59+
feedRequestDto = multiPartMapper.formatToMultipart<FeedRequestDto>(
60+
target = FeedRequestDto(
61+
relevantCategories = relevantCategories,
62+
feedContent = feedContent,
63+
novelId = novelId,
64+
isSpoiler = isSpoiler,
65+
isPublic = isPublic,
66+
),
67+
partName = PART_NAME_FEED,
68+
fileName = "feed.json",
69+
),
70+
images = images.map { multiPartMapper.formatToMultipart(it) },
71+
)
72+
}
13073

131-
suspend fun fetchPopularFeeds(): PopularFeedsEntity = feedApi.getPopularFeeds().toData()
74+
suspend fun saveEditedFeed(
75+
feedId: Long,
76+
relevantCategories: List<String>,
77+
editedFeed: String,
78+
novelId: Long?,
79+
isSpoiler: Boolean,
80+
isPublic: Boolean,
81+
images: List<Uri>,
82+
) {
83+
feedApi.putFeed(
84+
feedId = feedId,
85+
feedRequestDto = multiPartMapper.formatToMultipart<FeedRequestDto>(
86+
target = FeedRequestDto(
87+
relevantCategories = relevantCategories,
88+
feedContent = editedFeed,
89+
novelId = novelId,
90+
isSpoiler = isSpoiler,
91+
isPublic = isPublic,
92+
),
93+
partName = "feed",
94+
fileName = "feed.json",
95+
),
96+
images = images.map { multiPartMapper.formatToMultipart(it) },
97+
)
98+
}
13299

133-
suspend fun fetchUserInterestFeeds(): UserInterestFeedsEntity = feedApi.getUserInterestFeeds().toData()
100+
suspend fun fetchFeed(feedId: Long): FeedDetailEntity = feedApi.getFeed(feedId).toData()
134101

135-
suspend fun saveRemovedFeed(
136-
feedId: Long,
137-
novelId: Long?,
138-
content: String,
139-
) {
140-
runCatching {
141-
feedApi.deleteFeed(feedId)
142-
}.onSuccess {
143-
_cachedFeeds.removeIf { it.id == feedId }
102+
suspend fun fetchPopularFeeds(): PopularFeedsEntity = feedApi.getPopularFeeds().toData()
144103

145-
val novel = novelId?.let { id ->
146-
libraryLocalDataSource.selectNovelByNovelId(id)
147-
}
104+
suspend fun fetchUserInterestFeeds(): UserInterestFeedsEntity =
105+
feedApi.getUserInterestFeeds().toData()
148106

149-
if (novel != null) {
150-
val updatedNovel = novel.copy(myFeeds = novel.myFeeds.filterNot { it == content })
151-
libraryLocalDataSource.insertNovel(updatedNovel)
152-
}
153-
}
107+
suspend fun saveRemovedFeed(feedId: Long) {
108+
runCatching {
109+
feedApi.deleteFeed(feedId)
110+
}.onSuccess {
111+
_cachedFeeds.removeIf { it.id == feedId }
154112
}
113+
}
155114

156-
suspend fun saveSpoilerFeed(feedId: Long) {
157-
feedApi.postSpoilerFeed(feedId)
158-
}
115+
suspend fun saveSpoilerFeed(feedId: Long) {
116+
feedApi.postSpoilerFeed(feedId)
117+
}
159118

160-
suspend fun saveImpertinenceFeed(feedId: Long) {
161-
feedApi.postImpertinenceFeed(feedId)
162-
}
119+
suspend fun saveImpertinenceFeed(feedId: Long) {
120+
feedApi.postImpertinenceFeed(feedId)
121+
}
163122

164-
suspend fun saveLike(
165-
isLikedOfLikedFeed: Boolean,
166-
selectedFeedId: Long,
167-
) {
168-
when (isLikedOfLikedFeed) {
169-
true -> feedApi.deleteLikes(selectedFeedId)
170-
false -> feedApi.postLikes(selectedFeedId)
171-
}
123+
suspend fun saveLike(
124+
isLikedOfLikedFeed: Boolean,
125+
selectedFeedId: Long,
126+
) {
127+
when (isLikedOfLikedFeed) {
128+
true -> feedApi.deleteLikes(selectedFeedId)
129+
false -> feedApi.postLikes(selectedFeedId)
172130
}
131+
}
173132

174-
suspend fun fetchComments(feedId: Long): CommentsEntity = feedApi.getComments(feedId).toData()
133+
suspend fun fetchComments(feedId: Long): CommentsEntity = feedApi.getComments(feedId).toData()
175134

176-
suspend fun saveComment(
177-
feedId: Long,
178-
comment: String,
179-
) {
180-
feedApi.postComment(feedId, CommentRequestDto(comment))
181-
}
135+
suspend fun saveComment(
136+
feedId: Long,
137+
comment: String,
138+
) {
139+
feedApi.postComment(feedId, CommentRequestDto(comment))
140+
}
182141

183-
suspend fun saveModifiedComment(
184-
feedId: Long,
185-
commentId: Long,
186-
comment: String,
187-
) {
188-
feedApi.putComment(feedId, commentId, CommentRequestDto(comment))
189-
}
142+
suspend fun saveModifiedComment(
143+
feedId: Long,
144+
commentId: Long,
145+
comment: String,
146+
) {
147+
feedApi.putComment(feedId, commentId, CommentRequestDto(comment))
148+
}
190149

191-
suspend fun deleteComment(
192-
feedId: Long,
193-
commentId: Long,
194-
) {
195-
feedApi.deleteComment(feedId, commentId)
196-
}
150+
suspend fun deleteComment(
151+
feedId: Long,
152+
commentId: Long,
153+
) {
154+
feedApi.deleteComment(feedId, commentId)
155+
}
197156

198-
suspend fun saveSpoilerComment(
199-
feedId: Long,
200-
commentId: Long,
201-
) {
202-
feedApi.postSpoilerComment(feedId, commentId)
203-
}
157+
suspend fun saveSpoilerComment(
158+
feedId: Long,
159+
commentId: Long,
160+
) {
161+
feedApi.postSpoilerComment(feedId, commentId)
162+
}
204163

205-
suspend fun saveImpertinenceComment(
206-
feedId: Long,
207-
commentId: Long,
208-
) {
209-
feedApi.postImpertinenceComment(feedId, commentId)
210-
}
164+
suspend fun saveImpertinenceComment(
165+
feedId: Long,
166+
commentId: Long,
167+
) {
168+
feedApi.postImpertinenceComment(feedId, commentId)
169+
}
211170

212-
suspend fun downloadImage(imageUrl: String): Result<Uri?> = imageDownloader.formatImageToUri(imageUrl)
171+
suspend fun downloadImage(imageUrl: String): Result<Uri?> =
172+
imageDownloader.formatImageToUri(imageUrl)
213173

214-
suspend fun compressImages(imageUris: List<Uri>): List<Uri> = imageCompressor.compressUris(imageUris)
174+
suspend fun compressImages(imageUris: List<Uri>): List<Uri> =
175+
imageCompressor.compressUris(imageUris)
215176

216-
companion object {
217-
private const val PART_NAME_FEED: String = "feed"
218-
private const val FILE_NAME_FEED: String = "feed.json"
219-
}
177+
companion object {
178+
private const val PART_NAME_FEED: String = "feed"
220179
}
180+
}

0 commit comments

Comments
 (0)