File tree Expand file tree Collapse file tree 6 files changed +142
-4
lines changed
data/src/main/java/com/whyranoid/data
domain/src/main/java/com/whyranoid/domain Expand file tree Collapse file tree 6 files changed +142
-4
lines changed Original file line number Diff line number Diff line change
1
+ package com.whyranoid.data.Post
2
+
3
+ import com.google.firebase.firestore.FirebaseFirestore
4
+ import com.whyranoid.data.constant.CollectionId
5
+ import com.whyranoid.domain.model.GroupInfo
6
+ import com.whyranoid.domain.model.RecruitPost
7
+ import com.whyranoid.domain.model.User
8
+ import kotlinx.coroutines.suspendCancellableCoroutine
9
+ import java.util.*
10
+ import javax.inject.Inject
11
+ import kotlin.coroutines.resume
12
+
13
+ class PostDataSource @Inject constructor(
14
+ private val db : FirebaseFirestore
15
+ ) {
16
+
17
+ suspend fun createRecruitPost (
18
+ author : User ,
19
+ updatedAt : Long ,
20
+ groupInfo : GroupInfo
21
+ ): Boolean {
22
+ return suspendCancellableCoroutine { cancellableContinuation ->
23
+ val postId = UUID .randomUUID().toString()
24
+ db.collection(CollectionId .POST_COLLECTION )
25
+ .document(postId)
26
+ .set(
27
+ RecruitPost (
28
+ postId = postId,
29
+ author = author,
30
+ updatedAt = updatedAt,
31
+ groupInfo = groupInfo
32
+ )
33
+ ).addOnSuccessListener {
34
+ cancellableContinuation.resume(true )
35
+ }.addOnFailureListener {
36
+ cancellableContinuation.resume(false )
37
+ }
38
+ }
39
+ }
40
+ }
Original file line number Diff line number Diff line change
1
+ package com.whyranoid.data.Post
2
+
3
+ import com.whyranoid.domain.model.GroupInfo
4
+ import com.whyranoid.domain.model.Post
5
+ import com.whyranoid.domain.model.RunningHistory
6
+ import com.whyranoid.domain.model.User
7
+ import com.whyranoid.domain.repository.PostRepository
8
+ import kotlinx.coroutines.flow.Flow
9
+ import javax.inject.Inject
10
+
11
+ class PostRepositoryImpl @Inject constructor(
12
+ private val postDataSource : PostDataSource
13
+ ) : PostRepository {
14
+
15
+ // TODO : 페이징처리하기
16
+ override fun getPagingPosts (): Flow <List <Post >> {
17
+ TODO (" Not yet implemented" )
18
+ }
19
+
20
+ override suspend fun createPost (
21
+ user : User ,
22
+ postContent : String ,
23
+ runningHistory : RunningHistory ,
24
+ updatedAt : Long
25
+ ): Boolean {
26
+ TODO (" Not yet implemented" )
27
+ }
28
+
29
+ override suspend fun createRecruitPost (
30
+ author : User ,
31
+ updatedAt : Long ,
32
+ groupInfo : GroupInfo
33
+ ): Boolean {
34
+ return postDataSource.createRecruitPost(author, updatedAt, groupInfo)
35
+ }
36
+
37
+ override suspend fun deletePost (postId : String ): Boolean {
38
+ TODO (" Not yet implemented" )
39
+ }
40
+
41
+ override suspend fun updatePost (postId : String , postContent : String , updatedAt : Long ): Boolean {
42
+ TODO (" Not yet implemented" )
43
+ }
44
+ }
Original file line number Diff line number Diff line change
1
+ package com.whyranoid.data.di
2
+
3
+ import com.whyranoid.data.Post.PostRepositoryImpl
4
+ import com.whyranoid.domain.repository.PostRepository
5
+ import dagger.Binds
6
+ import dagger.Module
7
+ import dagger.hilt.InstallIn
8
+ import dagger.hilt.components.SingletonComponent
9
+
10
+ @Module
11
+ @InstallIn(SingletonComponent ::class )
12
+ abstract class PostModule {
13
+
14
+ @Binds
15
+ abstract fun bindPostRepository (postRepositoryImpl : PostRepositoryImpl ): PostRepository
16
+ }
Original file line number Diff line number Diff line change
1
+ package com.whyranoid.data.model
2
+
3
+ import com.whyranoid.domain.model.RecruitPost
4
+ import com.whyranoid.domain.model.toRule
5
+
6
+ sealed interface PostResponse {
7
+ val postId: String
8
+ val author: UserResponse
9
+ val updatedAt: Long
10
+ }
11
+
12
+ data class RecruitPostResponse (
13
+ override val postId : String = " " ,
14
+ override val author : UserResponse = UserResponse (),
15
+ override val updatedAt : Long = 0L ,
16
+ val groupInfo : GroupInfoResponse = GroupInfoResponse ()
17
+ ) : PostResponse
18
+
19
+ fun RecruitPostResponse.toRecruitPost (): RecruitPost {
20
+ val leader = this .author.toUser()
21
+ return RecruitPost (
22
+ postId = this .postId,
23
+ author = leader,
24
+ updatedAt = this .updatedAt,
25
+ groupInfo = this .groupInfo.toGroupInfo(
26
+ leader,
27
+ this .groupInfo.rules.map {
28
+ it.toRule()
29
+ }
30
+ )
31
+ )
32
+ }
Original file line number Diff line number Diff line change 1
1
package com.whyranoid.domain.repository
2
2
3
- import androidx.paging.PagingData
3
+ import com.whyranoid.domain.model.GroupInfo
4
4
import com.whyranoid.domain.model.Post
5
5
import com.whyranoid.domain.model.RunningHistory
6
6
import com.whyranoid.domain.model.User
7
7
import kotlinx.coroutines.flow.Flow
8
8
9
9
interface PostRepository {
10
10
11
+ // TODO : 페이징 처리
11
12
// 글(홍보 / 인증) 페이징으로 가져오기 - 리모트
12
- fun getPagingPosts (): Flow <PagingData <Post >>
13
+ fun getPagingPosts (): Flow <List <Post >>
13
14
14
15
// 글 작성하기 - 리모트
15
16
suspend fun createPost (
@@ -19,6 +20,12 @@ interface PostRepository {
19
20
updatedAt : Long
20
21
): Boolean
21
22
23
+ suspend fun createRecruitPost (
24
+ author : User ,
25
+ updatedAt : Long = 0L,
26
+ groupInfo : GroupInfo
27
+ ): Boolean
28
+
22
29
// 글 삭제하기 - 리모트
23
30
suspend fun deletePost (postId : String ): Boolean
24
31
Original file line number Diff line number Diff line change 1
1
package com.whyranoid.domain.usecase
2
2
3
- import androidx.paging.PagingData
4
3
import com.whyranoid.domain.model.Post
5
4
import com.whyranoid.domain.repository.PostRepository
6
5
import kotlinx.coroutines.flow.Flow
7
6
import javax.inject.Inject
8
7
9
8
class GetPagingPostsUseCase @Inject constructor(private val postRepository : PostRepository ) {
10
- operator fun invoke (): Flow <PagingData <Post >> {
9
+ operator fun invoke (): Flow <List <Post >> {
11
10
return postRepository.getPagingPosts()
12
11
}
13
12
}
You can’t perform that action at this time.
0 commit comments