Skip to content

Commit f0a50cc

Browse files
committed
✨ 홍보글 작성 로직 추가
1 parent 9786256 commit f0a50cc

File tree

4 files changed

+55
-48
lines changed

4 files changed

+55
-48
lines changed

data/src/main/java/com/whyranoid/data/Post/PostDataSource.kt

Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@ package com.whyranoid.data.Post
22

33
import com.google.firebase.firestore.FirebaseFirestore
44
import com.whyranoid.data.constant.CollectionId
5-
import com.whyranoid.domain.model.GroupInfo
5+
import com.whyranoid.data.model.GroupInfoResponse
6+
import com.whyranoid.data.model.UserResponse
7+
import com.whyranoid.data.model.toGroupInfo
8+
import com.whyranoid.data.model.toUser
69
import com.whyranoid.domain.model.RecruitPost
7-
import com.whyranoid.domain.model.User
10+
import com.whyranoid.domain.model.toRule
811
import kotlinx.coroutines.suspendCancellableCoroutine
12+
import kotlinx.coroutines.tasks.await
913
import java.util.*
1014
import javax.inject.Inject
1115
import kotlin.coroutines.resume
@@ -15,26 +19,49 @@ class PostDataSource @Inject constructor(
1519
) {
1620

1721
suspend fun createRecruitPost(
18-
author: User,
22+
authorUid: String,
1923
updatedAt: Long,
20-
groupInfo: GroupInfo
24+
groupUid: String
2125
): 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)
26+
val postId = UUID.randomUUID().toString()
27+
28+
val author = db.collection(CollectionId.USERS_COLLECTION)
29+
.document(authorUid)
30+
.get()
31+
.await()
32+
.toObject(UserResponse::class.java)
33+
?.toUser()
34+
35+
author?.let {
36+
val groupInfo = db.collection(CollectionId.GROUPS_COLLECTION)
37+
.document(groupUid)
38+
.get()
39+
.await()
40+
.toObject(GroupInfoResponse::class.java)
41+
42+
groupInfo?.let {
43+
return suspendCancellableCoroutine { cancellableContinuation ->
44+
45+
db.collection(CollectionId.POST_COLLECTION)
46+
.document(postId)
47+
.set(
48+
RecruitPost(
49+
postId = postId,
50+
author = author,
51+
updatedAt = updatedAt,
52+
groupInfo = groupInfo.toGroupInfo(
53+
leader = author,
54+
rules = groupInfo.rules.map { it.toRule() }
55+
)
56+
)
57+
).addOnSuccessListener {
58+
cancellableContinuation.resume(true)
59+
}.addOnFailureListener {
60+
cancellableContinuation.resume(false)
61+
}
3762
}
63+
}
3864
}
65+
return false
3966
}
4067
}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.whyranoid.data.Post
22

3-
import com.whyranoid.domain.model.GroupInfo
43
import com.whyranoid.domain.model.Post
54
import com.whyranoid.domain.model.RunningHistory
65
import com.whyranoid.domain.model.User
@@ -27,11 +26,11 @@ class PostRepositoryImpl @Inject constructor(
2726
}
2827

2928
override suspend fun createRecruitPost(
30-
author: User,
29+
authorUid: String,
3130
updatedAt: Long,
32-
groupInfo: GroupInfo
31+
groupUid: String
3332
): Boolean {
34-
return postDataSource.createRecruitPost(author, updatedAt, groupInfo)
33+
return postDataSource.createRecruitPost(authorUid, updatedAt, groupUid)
3534
}
3635

3736
override suspend fun deletePost(postId: String): Boolean {
Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,14 @@
11
package com.whyranoid.data.model
22

3-
import com.whyranoid.domain.model.RecruitPost
4-
import com.whyranoid.domain.model.toRule
5-
63
sealed interface PostResponse {
74
val postId: String
8-
val author: UserResponse
5+
val author: String
96
val updatedAt: Long
107
}
118

129
data class RecruitPostResponse(
1310
override val postId: String = "",
14-
override val author: UserResponse = UserResponse(),
11+
override val author: String = "",
1512
override val updatedAt: Long = 0L,
16-
val groupInfo: GroupInfoResponse = GroupInfoResponse()
13+
val groupUid: String = ""
1714
) : 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-
}

domain/src/main/java/com/whyranoid/domain/repository/PostRepository.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.whyranoid.domain.repository
22

3-
import com.whyranoid.domain.model.GroupInfo
43
import com.whyranoid.domain.model.Post
54
import com.whyranoid.domain.model.RunningHistory
65
import com.whyranoid.domain.model.User
@@ -21,9 +20,9 @@ interface PostRepository {
2120
): Boolean
2221

2322
suspend fun createRecruitPost(
24-
author: User,
25-
updatedAt: Long = 0L,
26-
groupInfo: GroupInfo
23+
authorUid: String,
24+
updatedAt: Long,
25+
groupUid: String
2726
): Boolean
2827

2928
// 글 삭제하기 - 리모트

0 commit comments

Comments
 (0)