#44 use interface for DAO's
This commit is contained in:
		
							parent
							
								
									cdc29c1674
								
							
						
					
					
						commit
						0e2b5f3c7d
					
				
					 8 changed files with 3 additions and 95 deletions
				
			
		|  | @ -19,7 +19,7 @@ package be.ugent.sel.studeez.domain.account | |||
| import be.ugent.sel.studeez.data.local.models.User | ||||
| import kotlinx.coroutines.flow.Flow | ||||
| 
 | ||||
| interface AccountService { | ||||
| interface AccountDAO { | ||||
|     val currentUserId: String | ||||
|     val hasUser: Boolean | ||||
| 
 | ||||
|  | @ -1,13 +0,0 @@ | |||
| package be.ugent.sel.studeez.domain.account | ||||
| 
 | ||||
| import com.google.firebase.auth.FirebaseAuth | ||||
| import kotlinx.coroutines.tasks.await | ||||
| import javax.inject.Inject | ||||
| 
 | ||||
| class AuthenticateUseCase @Inject constructor( | ||||
|     private val auth: FirebaseAuth, | ||||
| ) { | ||||
|     suspend operator fun invoke(email: String, password: String) { | ||||
|         auth.signInWithEmailAndPassword(email, password).await() | ||||
|     } | ||||
| } | ||||
|  | @ -1,13 +0,0 @@ | |||
| package be.ugent.sel.studeez.domain.account | ||||
| 
 | ||||
| import com.google.firebase.auth.FirebaseAuth | ||||
| import kotlinx.coroutines.tasks.await | ||||
| import javax.inject.Inject | ||||
| 
 | ||||
| class CreateAnonymousAccountUseCase @Inject constructor( | ||||
|     private val auth: FirebaseAuth, | ||||
| ) { | ||||
|     suspend operator fun invoke() { | ||||
|         auth.signInAnonymously().await() | ||||
|     } | ||||
| } | ||||
|  | @ -1,13 +0,0 @@ | |||
| package be.ugent.sel.studeez.domain.account | ||||
| 
 | ||||
| import com.google.firebase.auth.FirebaseAuth | ||||
| import kotlinx.coroutines.tasks.await | ||||
| import javax.inject.Inject | ||||
| 
 | ||||
| class DeleteAccountUseCase @Inject constructor( | ||||
|     private val auth: FirebaseAuth, | ||||
| ) { | ||||
|     suspend operator fun invoke() { | ||||
|         auth.currentUser!!.delete().await() | ||||
|     } | ||||
| } | ||||
|  | @ -26,9 +26,9 @@ import kotlinx.coroutines.flow.callbackFlow | |||
| import kotlinx.coroutines.tasks.await | ||||
| import javax.inject.Inject | ||||
| 
 | ||||
| class AccountServiceImpl @Inject constructor( | ||||
| class FirebaseAccountDAO @Inject constructor( | ||||
|     private val auth: FirebaseAuth | ||||
| ) : AccountService { | ||||
| ) : AccountDAO { | ||||
| 
 | ||||
|     override val currentUserId: String | ||||
|         get() = auth.currentUser?.uid.orEmpty() | ||||
|  | @ -1,22 +0,0 @@ | |||
| package be.ugent.sel.studeez.domain.account | ||||
| 
 | ||||
| import be.ugent.sel.studeez.domain.trace | ||||
| import com.google.firebase.auth.EmailAuthProvider | ||||
| import com.google.firebase.auth.FirebaseAuth | ||||
| import kotlinx.coroutines.tasks.await | ||||
| import javax.inject.Inject | ||||
| 
 | ||||
| class LinkAccountUseCase @Inject constructor( | ||||
|     private val auth: FirebaseAuth, | ||||
| ) { | ||||
| 
 | ||||
|     suspend operator fun invoke(email: String, password: String): Unit = | ||||
|         trace(LINK_ACCOUNT_TRACE) { | ||||
|             val credential = EmailAuthProvider.getCredential(email, password) | ||||
|             auth.currentUser!!.linkWithCredential(credential).await() | ||||
|         } | ||||
| 
 | ||||
|     companion object { | ||||
|         private const val LINK_ACCOUNT_TRACE = "linkAccount" | ||||
|     } | ||||
| } | ||||
|  | @ -1,13 +0,0 @@ | |||
| package be.ugent.sel.studeez.domain.account | ||||
| 
 | ||||
| import com.google.firebase.auth.FirebaseAuth | ||||
| import kotlinx.coroutines.tasks.await | ||||
| import javax.inject.Inject | ||||
| 
 | ||||
| class SendRecoveryEmailUseCase @Inject constructor( | ||||
|     private val auth: FirebaseAuth, | ||||
| ) { | ||||
|     suspend operator fun invoke(email: String) { | ||||
|         auth.sendPasswordResetEmail(email).await() | ||||
|     } | ||||
| } | ||||
|  | @ -1,18 +0,0 @@ | |||
| package be.ugent.sel.studeez.domain.account | ||||
| 
 | ||||
| import com.google.firebase.auth.FirebaseAuth | ||||
| import javax.inject.Inject | ||||
| 
 | ||||
| class SignOutUseCase @Inject constructor( | ||||
|     private val auth: FirebaseAuth, | ||||
|     private val createAnonymousAccountUseCase: CreateAnonymousAccountUseCase, | ||||
| ) { | ||||
|     suspend operator fun invoke() { | ||||
|         if (auth.currentUser!!.isAnonymous) { | ||||
|             auth.currentUser!!.delete() | ||||
|         } | ||||
|         auth.signOut() | ||||
| 
 | ||||
|         createAnonymousAccountUseCase() | ||||
|     } | ||||
| } | ||||
		Reference in a new issue
	
	 reyniersbram
						reyniersbram