Skip to content

Commit c191e9e

Browse files
committed
✨ PostDataSource 추상화
1 parent 24cf4e2 commit c191e9e

File tree

4 files changed

+37
-10
lines changed

4 files changed

+37
-10
lines changed

data/src/main/java/com/whyranoid/data/di/PostModule.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.whyranoid.data.di
22

3+
import com.whyranoid.data.post.PostDataSource
4+
import com.whyranoid.data.post.PostDataSourceImpl
35
import com.whyranoid.data.post.PostRepositoryImpl
46
import com.whyranoid.domain.repository.PostRepository
57
import dagger.Binds
@@ -11,6 +13,9 @@ import dagger.hilt.components.SingletonComponent
1113
@InstallIn(SingletonComponent::class)
1214
abstract class PostModule {
1315

16+
@Binds
17+
abstract fun bindPostDataSource(postDataSourceImpl: PostDataSourceImpl): PostDataSource
18+
1419
@Binds
1520
abstract fun bindPostRepository(postRepositoryImpl: PostRepositoryImpl): PostRepository
1621
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.whyranoid.data.post
2+
3+
import com.whyranoid.domain.model.Post
4+
import kotlinx.coroutines.flow.Flow
5+
6+
interface PostDataSource {
7+
8+
fun getAllPostFlow(): Flow<List<Post>>
9+
10+
fun getMyPostFlow(uid: String): Flow<List<Post>>
11+
12+
suspend fun createRecruitPost(
13+
authorUid: String,
14+
groupUid: String
15+
): Boolean
16+
17+
suspend fun createRunningPost(
18+
authorUid: String,
19+
runningHistoryId: String,
20+
content: String
21+
): Result<Boolean>
22+
}

data/src/main/java/com/whyranoid/data/post/PostDataSourceImpl.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ import kotlin.coroutines.resume
2727

2828
class PostDataSourceImpl @Inject constructor(
2929
private val db: FirebaseFirestore
30-
) {
30+
) : PostDataSource {
3131

3232
// TODO : 조금 더 간결하게 처리 필요.
33-
fun getAllPostFlow(): Flow<List<Post>> =
33+
override fun getAllPostFlow(): Flow<List<Post>> =
3434
callbackFlow {
3535
db.collection(CollectionId.POST_COLLECTION)
3636
.orderBy(UPDATED_AT, Query.Direction.DESCENDING)
@@ -122,7 +122,7 @@ class PostDataSourceImpl @Inject constructor(
122122
awaitClose()
123123
}
124124

125-
fun getMyPostFlow(uid: String): Flow<List<Post>> =
125+
override fun getMyPostFlow(uid: String): Flow<List<Post>> =
126126
callbackFlow {
127127
db.collection(CollectionId.POST_COLLECTION)
128128
.whereEqualTo(AUTHOR_ID, uid)
@@ -215,7 +215,7 @@ class PostDataSourceImpl @Inject constructor(
215215
awaitClose()
216216
}
217217

218-
suspend fun createRecruitPost(
218+
override suspend fun createRecruitPost(
219219
authorUid: String,
220220
groupUid: String
221221
): Boolean {
@@ -240,7 +240,7 @@ class PostDataSourceImpl @Inject constructor(
240240
}
241241
}
242242

243-
suspend fun createRunningPost(
243+
override suspend fun createRunningPost(
244244
authorUid: String,
245245
runningHistoryId: String,
246246
content: String

data/src/main/java/com/whyranoid/data/post/PostRepositoryImpl.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import kotlinx.coroutines.flow.Flow
66
import javax.inject.Inject
77

88
class PostRepositoryImpl @Inject constructor(
9-
private val postDataSourceImpl: PostDataSourceImpl
9+
private val postDataSource: PostDataSource
1010
) : PostRepository {
1111

1212
// TODO : 페이징처리하기
@@ -15,26 +15,26 @@ class PostRepositoryImpl @Inject constructor(
1515
}
1616

1717
override fun getAllPostFlow(): Flow<List<Post>> {
18-
return postDataSourceImpl.getAllPostFlow()
18+
return postDataSource.getAllPostFlow()
1919
}
2020

2121
override fun getMyPostFlow(uid: String): Flow<List<Post>> {
22-
return postDataSourceImpl.getMyPostFlow(uid)
22+
return postDataSource.getMyPostFlow(uid)
2323
}
2424

2525
override suspend fun createRunningPost(
2626
authorUid: String,
2727
runningHistoryId: String,
2828
content: String
2929
): Result<Boolean> {
30-
return postDataSourceImpl.createRunningPost(authorUid, runningHistoryId, content)
30+
return postDataSource.createRunningPost(authorUid, runningHistoryId, content)
3131
}
3232

3333
override suspend fun createRecruitPost(
3434
authorUid: String,
3535
groupUid: String
3636
): Boolean {
37-
return postDataSourceImpl.createRecruitPost(authorUid, groupUid)
37+
return postDataSource.createRecruitPost(authorUid, groupUid)
3838
}
3939

4040
override suspend fun deletePost(postId: String): Boolean {

0 commit comments

Comments
 (0)