#59 implementation of UserDAO
This commit is contained in:
		
							parent
							
								
									e7ab3aadc1
								
							
						
					
					
						commit
						b3de23dc54
					
				
					 1 changed files with 27 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -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"
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in a new issue