#59 username is now saved to user document on register
This commit is contained in:
		
							parent
							
								
									57d959a510
								
							
						
					
					
						commit
						e7ab3aadc1
					
				
					 4 changed files with 23 additions and 3 deletions
				
			
		|  | @ -2,7 +2,9 @@ package be.ugent.sel.studeez.di | ||||||
| 
 | 
 | ||||||
| import be.ugent.sel.studeez.domain.AccountDAO | import be.ugent.sel.studeez.domain.AccountDAO | ||||||
| import be.ugent.sel.studeez.domain.LogService | import be.ugent.sel.studeez.domain.LogService | ||||||
|  | import be.ugent.sel.studeez.domain.UserDAO | ||||||
| import be.ugent.sel.studeez.domain.implementation.FirebaseAccountDAO | import be.ugent.sel.studeez.domain.implementation.FirebaseAccountDAO | ||||||
|  | import be.ugent.sel.studeez.domain.implementation.FirebaseUserDAO | ||||||
| import be.ugent.sel.studeez.domain.implementation.LogServiceImpl | import be.ugent.sel.studeez.domain.implementation.LogServiceImpl | ||||||
| import dagger.Binds | import dagger.Binds | ||||||
| import dagger.Module | import dagger.Module | ||||||
|  | @ -14,6 +16,8 @@ import dagger.hilt.components.SingletonComponent | ||||||
| abstract class DatabaseModule { | abstract class DatabaseModule { | ||||||
|     @Binds abstract fun provideAccountDAO(impl: FirebaseAccountDAO): AccountDAO |     @Binds abstract fun provideAccountDAO(impl: FirebaseAccountDAO): AccountDAO | ||||||
| 
 | 
 | ||||||
|  |     @Binds abstract fun provideUserDAO(impl: FirebaseUserDAO): UserDAO | ||||||
|  | 
 | ||||||
|     @Binds abstract fun provideLogService(impl: LogServiceImpl): LogService |     @Binds abstract fun provideLogService(impl: LogServiceImpl): LogService | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
							
								
								
									
										4
									
								
								app/src/main/java/be/ugent/sel/studeez/domain/UserDAO.kt
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								app/src/main/java/be/ugent/sel/studeez/domain/UserDAO.kt
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,4 @@ | ||||||
|  | package be.ugent.sel.studeez.domain | ||||||
|  | 
 | ||||||
|  | interface UserDAO { | ||||||
|  | } | ||||||
|  | @ -0,0 +1,2 @@ | ||||||
|  | package be.ugent.sel.studeez.domain.implementation | ||||||
|  | 
 | ||||||
|  | @ -7,21 +7,29 @@ import be.ugent.sel.studeez.common.ext.passwordMatches | ||||||
| import be.ugent.sel.studeez.common.snackbar.SnackbarManager | import be.ugent.sel.studeez.common.snackbar.SnackbarManager | ||||||
| import be.ugent.sel.studeez.domain.AccountDAO | import be.ugent.sel.studeez.domain.AccountDAO | ||||||
| import be.ugent.sel.studeez.domain.LogService | import be.ugent.sel.studeez.domain.LogService | ||||||
|  | import be.ugent.sel.studeez.domain.UserDAO | ||||||
|  | import be.ugent.sel.studeez.navigation.StudeezDestinations.HOME_SCREEN | ||||||
| import be.ugent.sel.studeez.navigation.StudeezDestinations.LOGIN_SCREEN | import be.ugent.sel.studeez.navigation.StudeezDestinations.LOGIN_SCREEN | ||||||
| import be.ugent.sel.studeez.navigation.StudeezDestinations.SIGN_UP_SCREEN | import be.ugent.sel.studeez.navigation.StudeezDestinations.SIGN_UP_SCREEN | ||||||
| import be.ugent.sel.studeez.screens.StudeezViewModel | import be.ugent.sel.studeez.screens.StudeezViewModel | ||||||
| import dagger.hilt.android.lifecycle.HiltViewModel | import dagger.hilt.android.lifecycle.HiltViewModel | ||||||
|  | import kotlinx.coroutines.flow.FlowCollector | ||||||
|  | import kotlinx.coroutines.flow.first | ||||||
|  | import kotlinx.coroutines.flow.take | ||||||
| import be.ugent.sel.studeez.R.string as AppText | import be.ugent.sel.studeez.R.string as AppText | ||||||
| import javax.inject.Inject | import javax.inject.Inject | ||||||
| 
 | 
 | ||||||
| @HiltViewModel | @HiltViewModel | ||||||
| class SignUpViewModel @Inject constructor( | class SignUpViewModel @Inject constructor( | ||||||
|     private val accountService: AccountDAO, |     private val accountDAO: AccountDAO, | ||||||
|  |     private val userDAO: UserDAO, | ||||||
|     logService: LogService |     logService: LogService | ||||||
|     ) : StudeezViewModel(logService) { |     ) : StudeezViewModel(logService) { | ||||||
|     var uiState = mutableStateOf(SignUpUiState()) |     var uiState = mutableStateOf(SignUpUiState()) | ||||||
|         private set |         private set | ||||||
| 
 | 
 | ||||||
|  |     private val username | ||||||
|  |         get() = uiState.value.username | ||||||
|     private val email |     private val email | ||||||
|         get() = uiState.value.email |         get() = uiState.value.email | ||||||
|     private val password |     private val password | ||||||
|  | @ -59,8 +67,10 @@ class SignUpViewModel @Inject constructor( | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         launchCatching { |         launchCatching { | ||||||
|             accountService.signUpWithEmailAndPassword(email, password) |             accountDAO.signUpWithEmailAndPassword(email, password) | ||||||
|             openAndPopUp(LOGIN_SCREEN, SIGN_UP_SCREEN) |             accountDAO.signInWithEmailAndPassword(email, password) | ||||||
|  |             userDAO.save(username) | ||||||
|  |             openAndPopUp(HOME_SCREEN, SIGN_UP_SCREEN) | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Reference in a new issue
	
	 lbarraga
						lbarraga