Allow build

This commit is contained in:
Tibo De Peuter 2023-05-14 09:30:36 +02:00
parent 75411627ac
commit 56427a69af
6 changed files with 37 additions and 18 deletions

View file

@ -16,6 +16,9 @@ abstract class DatabaseModule {
@Binds
abstract fun provideUserDAO(impl: FirebaseUserDAO): UserDAO
@Binds
abstract fun provideFriendshipDAO(impl: FirebaseFriendshipDAO): FriendshipDAO
@Binds
abstract fun provideTimerDAO(impl: FirebaseTimerDAO): TimerDAO

View file

@ -3,6 +3,7 @@ package be.ugent.sel.studeez.domain.implementation
object FirebaseCollections {
const val SESSION_COLLECTION = "sessions"
const val USER_COLLECTION = "users"
const val FRIENDS_COLLECTION = "friends"
const val TIMER_COLLECTION = "timers"
const val SUBJECT_COLLECTION = "subjects"
const val TASK_COLLECTION = "tasks"

View file

@ -7,6 +7,7 @@ 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.flow.Flow
import kotlinx.coroutines.tasks.await
import javax.inject.Inject
@ -15,7 +16,30 @@ class FirebaseUserDAO @Inject constructor(
private val auth: AccountDAO
) : UserDAO {
override suspend fun getUser(): User {
companion object {
private const val USER_COLLECTION = FirebaseCollections.USER_COLLECTION
private const val USERNAME_FIELD = "username"
private const val BIOGRAPHY_FIELD = "biography"
}
private fun currentUserDocument(): DocumentReference =
firestore
.collection(USER_COLLECTION)
.document(auth.currentUserId)
override fun getAllUsers(): Flow<List<User>> {
TODO("Not yet implemented")
}
override fun getUsersWithQuery(): Flow<List<User>> {
TODO("Not yet implemented")
}
override fun getUserDetails(userId: String): Flow<User> {
TODO("Not yet implemented")
}
override suspend fun getLoggedInUser(): User {
val userDocument = currentUserDocument().get().await()
return User(
username = userDocument.getString(USERNAME_FIELD) ?: "",
@ -23,7 +47,7 @@ class FirebaseUserDAO @Inject constructor(
)
}
override suspend fun saveUser(
override suspend fun saveLoggedInUser(
newUsername: String,
newBiography: String
) {
@ -33,16 +57,7 @@ class FirebaseUserDAO @Inject constructor(
))
}
private fun currentUserDocument(): DocumentReference =
firestore.collection(USER_COLLECTION).document(auth.currentUserId)
companion object {
private const val USER_COLLECTION = "users"
private const val USERNAME_FIELD = "username"
private const val BIOGRAPHY_FIELD = "biography"
}
override suspend fun deleteUserReferences() {
override suspend fun deleteLoggedInUserReferences() {
currentUserDocument().delete()
.addOnSuccessListener { SnackbarManager.showMessage(R.string.success) }
.addOnFailureListener { SnackbarManager.showMessage(R.string.generic_error) }

View file

@ -24,7 +24,7 @@ class ProfileEditViewModel @Inject constructor(
init {
launchCatching {
val user: User = userDAO.getUser()
val user: User = userDAO.getLoggedInUser()
uiState.value = uiState.value.copy(
username = user.username,
biography = user.biography
@ -42,7 +42,7 @@ class ProfileEditViewModel @Inject constructor(
fun onSaveClick() {
launchCatching {
userDAO.saveUser(
userDAO.saveLoggedInUser(
newUsername = uiState.value.username,
newBiography = uiState.value.biography
)
@ -52,7 +52,7 @@ class ProfileEditViewModel @Inject constructor(
fun onDeleteClick(openAndPopUp: (String, String) -> Unit) {
launchCatching {
userDAO.deleteUserReferences() // Delete references
userDAO.deleteLoggedInUserReferences() // Delete references
accountDAO.deleteAccount() // Delete authentication
}
openAndPopUp(StudeezDestinations.SIGN_UP_SCREEN, StudeezDestinations.EDIT_PROFILE_SCREEN)

View file

@ -14,11 +14,11 @@ class ProfileViewModel @Inject constructor(
) : StudeezViewModel(logService) {
suspend fun getUsername(): String {
return userDAO.getUser().username
return userDAO.getLoggedInUser().username
}
suspend fun getBiography(): String {
return userDAO.getUser().biography
return userDAO.getLoggedInUser().biography
}
fun onEditProfileClick(open: (String) -> Unit) {

View file

@ -66,7 +66,7 @@ class SignUpViewModel @Inject constructor(
launchCatching {
accountDAO.signUpWithEmailAndPassword(email, password)
accountDAO.signInWithEmailAndPassword(email, password)
userDAO.saveUser(username)
userDAO.saveLoggedInUser(username)
openAndPopUp(HOME_SCREEN, SIGN_UP_SCREEN)
}
}