Skip to content

Commit

Permalink
[FEATURE] #32 : 운영진 코드 검증 로직 및 운영진 등록 로직 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
jeongjaino committed Oct 21, 2023
1 parent 92cd288 commit 926a90b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ package com.wap.wapp.core.data.repository.manage

interface ManageRepository {
suspend fun getManager(userId: String): Result<Unit>

suspend fun postManager(userId: String): Result<Unit>

suspend fun postManagerCode(code: String): Result<Unit>
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,12 @@ class ManageRepositoryImpl @Inject constructor(
override suspend fun getManager(userId: String): Result<Unit> {
return manageDataSource.getManager(userId)
}

override suspend fun postManager(userId: String): Result<Unit> {
return manageDataSource.postManager(userId)
}

override suspend fun postManagerCode(code: String): Result<Unit> {
return manageDataSource.postManagerCode(code)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ package com.wap.wapp.core.network.source.manage

interface ManageDataSource {
suspend fun getManager(userId: String): Result<Unit>

suspend fun postManager(userId: String): Result<Unit>

suspend fun postManagerCode(code: String): Result<Unit>
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.wap.wapp.core.network.source.manage

import com.google.firebase.firestore.FirebaseFirestore
import com.google.firebase.firestore.SetOptions
import com.wap.wapp.core.network.constant.CODES_COLLECTION
import com.wap.wapp.core.network.constant.MANAGER_COLLECTION
import com.wap.wapp.core.network.utils.await
import javax.inject.Inject
Expand All @@ -10,10 +12,35 @@ class ManageDataSourceImpl @Inject constructor(
) : ManageDataSource {
override suspend fun getManager(userId: String): Result<Unit> {
return runCatching {
val result = firebaseFirestore.collection(MANAGER_COLLECTION)
.whereEqualTo("userId", userId)
.get()
.await()

check(result.isEmpty.not())
}
}

override suspend fun postManager(userId: String): Result<Unit> {
return runCatching {
val userIdMap = mapOf("userId" to userId)
val setOption = SetOptions.merge()

firebaseFirestore.collection(MANAGER_COLLECTION)
.document(userId)
.set(userIdMap, setOption)
.await()
}
}

override suspend fun postManagerCode(code: String): Result<Unit> {
return runCatching {
val result = firebaseFirestore.collection(CODES_COLLECTION)
.whereEqualTo("manager", code)
.get()
.await()

check(result.isEmpty.not())
}
}
}

0 comments on commit 926a90b

Please sign in to comment.