-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: integrate
LoginUseCase
into UserUseCase
- Loading branch information
1 parent
5c46289
commit bc675ed
Showing
7 changed files
with
72 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
android/app/src/main/java/com/goliath/emojihub/repositories/RepositoryModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.goliath.emojihub.repositories | ||
|
||
import com.goliath.emojihub.repositories.remote.UserRepository | ||
import com.goliath.emojihub.repositories.remote.UserRepositoryImpl | ||
import dagger.Binds | ||
import dagger.Module | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
|
||
@InstallIn(SingletonComponent::class) | ||
@Module | ||
abstract class RepositoryModule { | ||
@Binds | ||
abstract fun bindsUserRepository(impl: UserRepositoryImpl): UserRepository | ||
} |
16 changes: 0 additions & 16 deletions
16
android/app/src/main/java/com/goliath/emojihub/usecases/LoginUseCase.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 17 additions & 2 deletions
19
android/app/src/main/java/com/goliath/emojihub/viewmodels/UserViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,27 @@ | ||
package com.goliath.emojihub.viewmodels | ||
|
||
import androidx.lifecycle.ViewModel | ||
import com.goliath.emojihub.models.User | ||
import com.goliath.emojihub.usecases.UserUseCase | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
import kotlinx.coroutines.flow.update | ||
import javax.inject.Inject | ||
|
||
|
||
class UserViewModel ( | ||
private val useCase: UserUseCase | ||
private val userUseCase: UserUseCase | ||
): ViewModel() { | ||
|
||
private val _loginState = MutableStateFlow<User?>(null) | ||
val loginState = _loginState.asStateFlow() | ||
|
||
fun fetchUser(id: String) { | ||
useCase.fetchUser(id) | ||
userUseCase.fetchUser(id) | ||
} | ||
|
||
fun registerUser(username: String, password: String) { | ||
_loginState.update { userUseCase.registerUser(username, password) } | ||
} | ||
} |