#59 implementation of UserDAO

This commit is contained in:
lbarraga 2023-04-13 17:20:31 +02:00
parent e7ab3aadc1
commit b3de23dc54

View file

@ -1,2 +1,29 @@
package be.ugent.sel.studeez.domain.implementation
import be.ugent.sel.studeez.domain.AccountDAO
import be.ugent.sel.studeez.domain.UserDAO
import com.google.firebase.firestore.DocumentReference
import com.google.firebase.firestore.FirebaseFirestore
import kotlinx.coroutines.tasks.await
import javax.inject.Inject
class FirebaseUserDAO @Inject constructor(
private val firestore: FirebaseFirestore,
private val auth: AccountDAO
) : UserDAO {
override suspend fun getUserName(): String? {
return currentUserDocument().get().await().getString("username")
}
override suspend fun save(newUsername: String) {
currentUserDocument().set(mapOf("username" to newUsername))
}
private fun currentUserDocument(): DocumentReference =
firestore.collection(USER_COLLECTION).document(auth.currentUserId)
companion object {
private const val USER_COLLECTION = "users"
}
}