Allow build
This commit is contained in:
parent
75411627ac
commit
56427a69af
6 changed files with 37 additions and 18 deletions
|
@ -16,6 +16,9 @@ abstract class DatabaseModule {
|
||||||
@Binds
|
@Binds
|
||||||
abstract fun provideUserDAO(impl: FirebaseUserDAO): UserDAO
|
abstract fun provideUserDAO(impl: FirebaseUserDAO): UserDAO
|
||||||
|
|
||||||
|
@Binds
|
||||||
|
abstract fun provideFriendshipDAO(impl: FirebaseFriendshipDAO): FriendshipDAO
|
||||||
|
|
||||||
@Binds
|
@Binds
|
||||||
abstract fun provideTimerDAO(impl: FirebaseTimerDAO): TimerDAO
|
abstract fun provideTimerDAO(impl: FirebaseTimerDAO): TimerDAO
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package be.ugent.sel.studeez.domain.implementation
|
||||||
object FirebaseCollections {
|
object FirebaseCollections {
|
||||||
const val SESSION_COLLECTION = "sessions"
|
const val SESSION_COLLECTION = "sessions"
|
||||||
const val USER_COLLECTION = "users"
|
const val USER_COLLECTION = "users"
|
||||||
|
const val FRIENDS_COLLECTION = "friends"
|
||||||
const val TIMER_COLLECTION = "timers"
|
const val TIMER_COLLECTION = "timers"
|
||||||
const val SUBJECT_COLLECTION = "subjects"
|
const val SUBJECT_COLLECTION = "subjects"
|
||||||
const val TASK_COLLECTION = "tasks"
|
const val TASK_COLLECTION = "tasks"
|
||||||
|
|
|
@ -7,6 +7,7 @@ import be.ugent.sel.studeez.domain.AccountDAO
|
||||||
import be.ugent.sel.studeez.domain.UserDAO
|
import be.ugent.sel.studeez.domain.UserDAO
|
||||||
import com.google.firebase.firestore.DocumentReference
|
import com.google.firebase.firestore.DocumentReference
|
||||||
import com.google.firebase.firestore.FirebaseFirestore
|
import com.google.firebase.firestore.FirebaseFirestore
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.tasks.await
|
import kotlinx.coroutines.tasks.await
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
@ -15,7 +16,30 @@ class FirebaseUserDAO @Inject constructor(
|
||||||
private val auth: AccountDAO
|
private val auth: AccountDAO
|
||||||
) : UserDAO {
|
) : 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()
|
val userDocument = currentUserDocument().get().await()
|
||||||
return User(
|
return User(
|
||||||
username = userDocument.getString(USERNAME_FIELD) ?: "",
|
username = userDocument.getString(USERNAME_FIELD) ?: "",
|
||||||
|
@ -23,7 +47,7 @@ class FirebaseUserDAO @Inject constructor(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun saveUser(
|
override suspend fun saveLoggedInUser(
|
||||||
newUsername: String,
|
newUsername: String,
|
||||||
newBiography: String
|
newBiography: String
|
||||||
) {
|
) {
|
||||||
|
@ -33,16 +57,7 @@ class FirebaseUserDAO @Inject constructor(
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun currentUserDocument(): DocumentReference =
|
override suspend fun deleteLoggedInUserReferences() {
|
||||||
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() {
|
|
||||||
currentUserDocument().delete()
|
currentUserDocument().delete()
|
||||||
.addOnSuccessListener { SnackbarManager.showMessage(R.string.success) }
|
.addOnSuccessListener { SnackbarManager.showMessage(R.string.success) }
|
||||||
.addOnFailureListener { SnackbarManager.showMessage(R.string.generic_error) }
|
.addOnFailureListener { SnackbarManager.showMessage(R.string.generic_error) }
|
||||||
|
|
|
@ -24,7 +24,7 @@ class ProfileEditViewModel @Inject constructor(
|
||||||
|
|
||||||
init {
|
init {
|
||||||
launchCatching {
|
launchCatching {
|
||||||
val user: User = userDAO.getUser()
|
val user: User = userDAO.getLoggedInUser()
|
||||||
uiState.value = uiState.value.copy(
|
uiState.value = uiState.value.copy(
|
||||||
username = user.username,
|
username = user.username,
|
||||||
biography = user.biography
|
biography = user.biography
|
||||||
|
@ -42,7 +42,7 @@ class ProfileEditViewModel @Inject constructor(
|
||||||
|
|
||||||
fun onSaveClick() {
|
fun onSaveClick() {
|
||||||
launchCatching {
|
launchCatching {
|
||||||
userDAO.saveUser(
|
userDAO.saveLoggedInUser(
|
||||||
newUsername = uiState.value.username,
|
newUsername = uiState.value.username,
|
||||||
newBiography = uiState.value.biography
|
newBiography = uiState.value.biography
|
||||||
)
|
)
|
||||||
|
@ -52,7 +52,7 @@ class ProfileEditViewModel @Inject constructor(
|
||||||
|
|
||||||
fun onDeleteClick(openAndPopUp: (String, String) -> Unit) {
|
fun onDeleteClick(openAndPopUp: (String, String) -> Unit) {
|
||||||
launchCatching {
|
launchCatching {
|
||||||
userDAO.deleteUserReferences() // Delete references
|
userDAO.deleteLoggedInUserReferences() // Delete references
|
||||||
accountDAO.deleteAccount() // Delete authentication
|
accountDAO.deleteAccount() // Delete authentication
|
||||||
}
|
}
|
||||||
openAndPopUp(StudeezDestinations.SIGN_UP_SCREEN, StudeezDestinations.EDIT_PROFILE_SCREEN)
|
openAndPopUp(StudeezDestinations.SIGN_UP_SCREEN, StudeezDestinations.EDIT_PROFILE_SCREEN)
|
||||||
|
|
|
@ -14,11 +14,11 @@ class ProfileViewModel @Inject constructor(
|
||||||
) : StudeezViewModel(logService) {
|
) : StudeezViewModel(logService) {
|
||||||
|
|
||||||
suspend fun getUsername(): String {
|
suspend fun getUsername(): String {
|
||||||
return userDAO.getUser().username
|
return userDAO.getLoggedInUser().username
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getBiography(): String {
|
suspend fun getBiography(): String {
|
||||||
return userDAO.getUser().biography
|
return userDAO.getLoggedInUser().biography
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onEditProfileClick(open: (String) -> Unit) {
|
fun onEditProfileClick(open: (String) -> Unit) {
|
||||||
|
|
|
@ -66,7 +66,7 @@ class SignUpViewModel @Inject constructor(
|
||||||
launchCatching {
|
launchCatching {
|
||||||
accountDAO.signUpWithEmailAndPassword(email, password)
|
accountDAO.signUpWithEmailAndPassword(email, password)
|
||||||
accountDAO.signInWithEmailAndPassword(email, password)
|
accountDAO.signInWithEmailAndPassword(email, password)
|
||||||
userDAO.saveUser(username)
|
userDAO.saveLoggedInUser(username)
|
||||||
openAndPopUp(HOME_SCREEN, SIGN_UP_SCREEN)
|
openAndPopUp(HOME_SCREEN, SIGN_UP_SCREEN)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue