#18 Edit and delete profile implemented

This commit is contained in:
Tibo De Peuter 2023-04-16 22:40:43 +02:00
parent f263b34c12
commit 5e2c8de521
9 changed files with 32 additions and 25 deletions

View file

@ -29,5 +29,6 @@ interface AccountDAO {
suspend fun sendRecoveryEmail(email: String)
suspend fun signUpWithEmailAndPassword(email: String, password: String)
suspend fun deleteAccount()
suspend fun signOut()
}

View file

@ -4,4 +4,10 @@ interface UserDAO {
suspend fun getUsername(): String?
suspend fun save(newUsername: String)
/**
* Delete all references to this user in the database. Similar to the deleteCascade in
* relational databases.
*/
suspend fun deleteUserReferences()
}

View file

@ -1,19 +1,13 @@
package be.ugent.sel.studeez.domain.implementation
import androidx.compose.runtime.rememberCoroutineScope
import be.ugent.sel.studeez.R
import be.ugent.sel.studeez.common.snackbar.SnackbarManager
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.CoroutineScope
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.tasks.await
import javax.inject.Inject
import kotlin.coroutines.coroutineContext
class FirebaseUserDAO @Inject constructor(
private val firestore: FirebaseFirestore,
@ -34,4 +28,10 @@ class FirebaseUserDAO @Inject constructor(
companion object {
private const val USER_COLLECTION = "users"
}
override suspend fun deleteUserReferences() {
currentUserDocument().delete()
.addOnSuccessListener { SnackbarManager.showMessage(R.string.success) }
.addOnFailureListener { SnackbarManager.showMessage(R.string.generic_error) }
}
}