Skip to content

Commit 2ca3d88

Browse files
authored
🔀 #54 from boostcampwm-2022/feat/duplicateCheckGroupName
그룹 생성 및 수정 시 그룹 이름 중복확인 기능 추가, FinishNotifiacation관련 수정
2 parents 40007b3 + c06457c commit 2ca3d88

File tree

18 files changed

+182
-66
lines changed

18 files changed

+182
-66
lines changed

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

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

33
import com.google.firebase.firestore.FirebaseFirestore
4+
import com.google.firebase.firestore.Query
45
import com.whyranoid.data.constant.CollectionId
56
import com.whyranoid.data.model.GroupInfoResponse
67
import com.whyranoid.data.model.RecruitPostResponse
@@ -26,6 +27,7 @@ class PostDataSource @Inject constructor(
2627
fun getAllPostFlow(): Flow<List<Post>> =
2728
callbackFlow {
2829
db.collection(CollectionId.POST_COLLECTION)
30+
.orderBy("updatedAt", Query.Direction.DESCENDING)
2931
.addSnapshotListener { snapshot, _ ->
3032
val recruitPostList = mutableListOf<Post>()
3133
snapshot?.forEach { docuemnt ->

data/src/main/java/com/whyranoid/data/constant/CollectionId.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ object CollectionId {
99
const val START_NOTIFICATION = "start"
1010
const val FINISH_NOTIFICATION = "finish"
1111
const val POST_COLLECTION = "Posts"
12+
const val RUNNING_HISTORY_COLLECTION = "RunningHistory"
1213
}

data/src/main/java/com/whyranoid/data/group/GroupDataSource.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import kotlinx.coroutines.channels.awaitClose
2020
import kotlinx.coroutines.flow.Flow
2121
import kotlinx.coroutines.flow.callbackFlow
2222
import kotlinx.coroutines.suspendCancellableCoroutine
23+
import kotlinx.coroutines.tasks.await
2324
import java.util.UUID
2425
import javax.inject.Inject
2526
import kotlin.coroutines.resume
@@ -152,4 +153,13 @@ class GroupDataSource @Inject constructor(
152153
}
153154
awaitClose()
154155
}
156+
157+
suspend fun isDuplicatedGroupName(groupName: String): Boolean {
158+
return db.collection(GROUPS_COLLECTION)
159+
.whereEqualTo(GROUP_NAME, groupName)
160+
.get()
161+
.await()
162+
.isEmpty
163+
.not()
164+
}
155165
}

data/src/main/java/com/whyranoid/data/group/GroupRepositoryImpl.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,8 @@ class GroupRepositoryImpl @Inject constructor(
5858
): Boolean {
5959
return groupDataSource.createGroup(groupName, introduce, rules, uid)
6060
}
61+
62+
override suspend fun isDuplicatedGroupName(groupName: String): Boolean {
63+
return groupDataSource.isDuplicatedGroupName(groupName)
64+
}
6165
}

data/src/main/java/com/whyranoid/data/groupnotification/GroupNotificationDataSource.kt

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ package com.whyranoid.data.groupnotification
33
import com.google.firebase.firestore.FirebaseFirestore
44
import com.whyranoid.data.constant.CollectionId.FINISH_NOTIFICATION
55
import com.whyranoid.data.constant.CollectionId.GROUP_NOTIFICATIONS_COLLECTION
6+
import com.whyranoid.data.constant.CollectionId.RUNNING_HISTORY_COLLECTION
67
import com.whyranoid.data.constant.CollectionId.START_NOTIFICATION
78
import com.whyranoid.data.model.FinishNotificationResponse
89
import com.whyranoid.data.model.StartNotificationResponse
9-
import com.whyranoid.data.model.toFinishNotification
1010
import com.whyranoid.data.model.toStartNotification
11+
import com.whyranoid.domain.model.FinishNotification
1112
import com.whyranoid.domain.model.GroupNotification
13+
import com.whyranoid.domain.model.RunningHistory
1214
import com.whyranoid.domain.model.StartNotification
1315
import kotlinx.coroutines.Dispatchers
1416
import kotlinx.coroutines.FlowPreview
@@ -79,11 +81,28 @@ class GroupNotificationDataSource @Inject constructor(
7981
.addSnapshotListener { snapshot, error ->
8082
val finishNotificationList = mutableListOf<GroupNotification>()
8183
snapshot?.forEach { document ->
82-
val finishNotification =
84+
val finishNotificationResponse =
8385
document.toObject(FinishNotificationResponse::class.java)
84-
finishNotificationList.add(finishNotification.toFinishNotification())
86+
87+
finishNotificationResponse.let { finishNotificationResponse ->
88+
db.collection(RUNNING_HISTORY_COLLECTION)
89+
.document(finishNotificationResponse.historyId)
90+
.get()
91+
.addOnSuccessListener {
92+
val runningHistory = it.toObject(RunningHistory::class.java)
93+
94+
runningHistory?.let {
95+
finishNotificationList.add(
96+
FinishNotification(
97+
uid = finishNotificationResponse.uid,
98+
runningHistory = runningHistory
99+
)
100+
)
101+
}
102+
trySend(finishNotificationList)
103+
}
104+
}
85105
}
86-
trySend(finishNotificationList)
87106
}
88107

89108
awaitClose()
Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.whyranoid.data.model
22

3-
import com.whyranoid.domain.model.FinishNotification
4-
import com.whyranoid.domain.model.RunningHistory
53
import com.whyranoid.domain.model.StartNotification
64

75
sealed interface GroupNotificationResponse {
@@ -18,29 +16,11 @@ data class StartNotificationResponse(
1816
data class FinishNotificationResponse(
1917
override val type: String = "",
2018
override val uid: String = "",
21-
val finishedAt: Long = 0L,
22-
val historyId: String = "",
23-
val pace: Double = 0.0,
24-
val startedAt: Long = 0L,
25-
val totalDistance: Double = 0.0,
26-
val totalRunningTime: Int = 0
19+
val historyId: String = ""
2720
) : GroupNotificationResponse
2821

2922
fun StartNotificationResponse.toStartNotification() =
3023
StartNotification(
3124
uid = this.uid,
3225
startedAt = this.startedAt
3326
)
34-
35-
fun FinishNotificationResponse.toFinishNotification() =
36-
FinishNotification(
37-
uid = this.uid,
38-
runningHistory = RunningHistory(
39-
historyId = this.historyId,
40-
startedAt = this.startedAt,
41-
finishedAt = this.finishedAt,
42-
totalRunningTime = this.totalRunningTime,
43-
pace = this.pace,
44-
totalDistance = this.totalDistance
45-
)
46-
)
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package com.whyranoid.domain.model
22

33
data class RunningHistory(
4-
val historyId: String,
5-
val startedAt: Long,
6-
val finishedAt: Long,
7-
val totalRunningTime: Int,
8-
val pace: Double,
9-
val totalDistance: Double
4+
val historyId: String = "",
5+
val startedAt: Long = 0L,
6+
val finishedAt: Long = 0L,
7+
val totalRunningTime: Int = 0,
8+
val pace: Double = 0.0,
9+
val totalDistance: Double = 0.0
1010
)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,6 @@ interface GroupRepository {
4040
rules: List<String>,
4141
uid: String
4242
): Boolean
43+
44+
suspend fun isDuplicatedGroupName(groupName: String): Boolean
4345
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.whyranoid.domain.usecase
2+
3+
import com.whyranoid.domain.repository.GroupRepository
4+
import javax.inject.Inject
5+
6+
class CheckIsDuplicatedGroupNameUseCase @Inject constructor(
7+
private val groupRepository: GroupRepository
8+
) {
9+
10+
suspend operator fun invoke(groupName: String): Boolean {
11+
return groupRepository.isDuplicatedGroupName(groupName)
12+
}
13+
}

presentation/src/main/java/com/whyranoid/presentation/community/group/create/CreateGroupFragment.kt

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@ internal class CreateGroupFragment :
3434
handleEvent(event)
3535
}
3636
}
37-
38-
viewLifecycleOwner.repeatWhenUiStarted {
39-
viewModel.rules.collect {
40-
println("테스트 $it")
41-
}
42-
}
4337
}
4438

4539
private fun handleEvent(event: Event) {
@@ -60,6 +54,22 @@ internal class CreateGroupFragment :
6054
).show()
6155
}
6256
}
57+
is Event.DuplicateCheckButtonClick -> {
58+
if (event.isDuplicatedGroupName) {
59+
Snackbar.make(
60+
binding.root,
61+
getString(R.string.text_duplicated_group_name),
62+
Snackbar.LENGTH_SHORT
63+
).show()
64+
} else {
65+
Snackbar.make(
66+
binding.root,
67+
getString(R.string.text_un_duplicated_group_name),
68+
Snackbar.LENGTH_SHORT
69+
).show()
70+
binding.etGroupName.isEnabled = false
71+
}
72+
}
6373
is Event.WarningButtonClick -> {
6474
Snackbar.make(
6575
binding.root,
@@ -106,7 +116,7 @@ internal class CreateGroupFragment :
106116
}
107117

108118
viewLifecycleOwner.repeatWhenUiStarted {
109-
viewModel.isButtonEnable.collect { isEnable ->
119+
viewModel.isGroupCreateButtonEnable.collect { isEnable ->
110120
if (isEnable) {
111121
binding.topAppBar.menu.setGroupVisible(R.id.ready_to_create, true)
112122
binding.topAppBar.menu.setGroupVisible(R.id.not_ready_to_create, false)

0 commit comments

Comments
 (0)