Skip to content

Commit

Permalink
[Mod] #18 hilt 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
cacaocoffee committed Jun 19, 2024
1 parent 0c69554 commit b374cf0
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ import com.sopt.now.data.dto.toUserEntity
import com.sopt.now.data.repositoryimpl.extension.getResponseErrorMessage
import com.sopt.now.data.repositoryimpl.extension.handleThrowable
import com.sopt.now.domain.entity.ApiError
import com.sopt.now.domain.entity.UserEntity
import com.sopt.now.domain.entity.BaseResponseEntity
import com.sopt.now.domain.entity.UserEntity
import com.sopt.now.domain.repository.AuthRepository
import retrofit2.Response
import javax.inject.Inject

class AuthRepositoryImpl(private val authService: AuthService) : AuthRepository {
class AuthRepositoryImpl @Inject constructor(
private val authService: AuthService
) :
AuthRepository {
override suspend fun login(authData: UserEntity): Result<Int?> =
runCatching {
val response: Response<BaseResponse<Unit>> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package com.sopt.now.domain.usecase

import com.sopt.now.domain.entity.UserEntity
import com.sopt.now.domain.repository.AuthRepository
import javax.inject.Inject

class GetUserInfoUseCase(private val authRepository: AuthRepository) {
class GetUserInfoUseCase @Inject constructor(
private val authRepository: AuthRepository
) {
suspend operator fun invoke(userid: String): Result<UserEntity> =
authRepository.getMemberInfo(userid)
}
7 changes: 5 additions & 2 deletions app/src/main/java/com/sopt/now/domain/usecase/LogInUseCase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ package com.sopt.now.domain.usecase

import com.sopt.now.domain.entity.UserEntity
import com.sopt.now.domain.repository.AuthRepository
import javax.inject.Inject

class LogInUseCase(private val authRepository: AuthRepository) {
class LogInUseCase @Inject constructor(
private val authRepository: AuthRepository
) {

suspend operator fun invoke(request: UserEntity):Result<Int?> =
suspend operator fun invoke(request: UserEntity): Result<Int?> =
authRepository.login(request)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ package com.sopt.now.domain.usecase
import com.sopt.now.domain.entity.UserEntity
import com.sopt.now.domain.entity.BaseResponseEntity
import com.sopt.now.domain.repository.AuthRepository
import javax.inject.Inject

class SignUpUseCase(private val authRepository: AuthRepository) {
class SignUpUseCase @Inject constructor(
private val authRepository: AuthRepository
) {

suspend operator fun invoke(request: UserEntity):Result<BaseResponseEntity> =
suspend operator fun invoke(request: UserEntity): Result<BaseResponseEntity> =
authRepository.signUp(request)
}
5 changes: 3 additions & 2 deletions app/src/main/java/com/sopt/now/ui/login/LoginActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ import com.sopt.now.databinding.ActivityLoginBinding
import com.sopt.now.domain.entity.UserEntity
import com.sopt.now.ui.main.MainActivity
import com.sopt.now.ui.signup.SignUpActivity
import com.sopt.now.ui.ViewModelFactory
import com.sopt.now.util.BindingActivity
import com.sopt.now.util.UiState
import com.sopt.now.util.getSafeParcelable
import com.sopt.now.util.toast
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class LoginActivity : BindingActivity<ActivityLoginBinding>(R.layout.activity_login) {
private lateinit var resultLauncher: ActivityResultLauncher<Intent>
private val viewModel: LoginViewModel by viewModels { ViewModelFactory() }
private val viewModel: LoginViewModel by viewModels()
private lateinit var user: User

override fun onCreate(savedInstanceState: Bundle?) {
Expand Down
9 changes: 7 additions & 2 deletions app/src/main/java/com/sopt/now/ui/login/LoginViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ import com.sopt.now.ui.model.User
import com.sopt.now.domain.entity.UserEntity
import com.sopt.now.domain.usecase.LogInUseCase
import com.sopt.now.util.UiState
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject

class LoginViewModel(private val logInUseCase: LogInUseCase) : ViewModel() {
@HiltViewModel
class LoginViewModel @Inject constructor(
private val logInUseCase: LogInUseCase
) : ViewModel() {
private val _loginState = MutableLiveData<UiState<User>>()
val loginState : LiveData<UiState<User>> = _loginState
val loginState: LiveData<UiState<User>> = _loginState

fun login(request: UserEntity) {
_loginState.value = UiState.Loading
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/com/sopt/now/ui/main/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import androidx.fragment.app.Fragment
import com.sopt.now.R
import com.sopt.now.ui.model.User
import com.sopt.now.databinding.ActivityMainBinding
import com.sopt.now.ui.ViewModelFactory
import com.sopt.now.ui.login.LoginActivity.Companion.TAG_USER
import com.sopt.now.ui.main.home.MainHomeFragment
import com.sopt.now.ui.main.profile.MainProfileFragment
Expand All @@ -15,9 +14,11 @@ import com.sopt.now.util.BindingActivity
import com.sopt.now.util.UiState
import com.sopt.now.util.getSafeParcelable
import com.sopt.now.util.toast
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class MainActivity : BindingActivity<ActivityMainBinding>(R.layout.activity_main) {
private val viewModel: MainViewModel by viewModels { ViewModelFactory() }
private val viewModel: MainViewModel by viewModels()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down
7 changes: 6 additions & 1 deletion app/src/main/java/com/sopt/now/ui/main/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ import com.sopt.now.domain.usecase.GetUserInfoUseCase
import com.sopt.now.util.StringNetworkError.FAIL_ERROR
import com.sopt.now.util.StringNetworkError.LOGIN
import com.sopt.now.util.UiState
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import retrofit2.HttpException
import javax.inject.Inject

class MainViewModel(private val getUserInfoUseCase: GetUserInfoUseCase) : ViewModel() {
@HiltViewModel
class MainViewModel @Inject constructor(
private val getUserInfoUseCase: GetUserInfoUseCase
) : ViewModel() {
private val _userData: MutableLiveData<List<Profile>> = MutableLiveData()
val userData: LiveData<List<Profile>> = _userData

Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/com/sopt/now/ui/signup/SignUpActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ import com.sopt.now.R
import com.sopt.now.ui.model.User
import com.sopt.now.databinding.ActivitySignUpBinding
import com.sopt.now.domain.entity.UserEntity
import com.sopt.now.ui.ViewModelFactory
import com.sopt.now.ui.login.LoginActivity
import com.sopt.now.ui.login.LoginActivity.Companion.TAG_USER
import com.sopt.now.util.BindingActivity
import com.sopt.now.util.UiState
import com.sopt.now.util.toast
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class SignUpActivity : BindingActivity<ActivitySignUpBinding>(R.layout.activity_sign_up) {
private val viewModel by viewModels<SignUpViewModel> { ViewModelFactory() }
private val viewModel: SignUpViewModel by viewModels()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down
9 changes: 7 additions & 2 deletions app/src/main/java/com/sopt/now/ui/signup/SignUpViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ import com.sopt.now.domain.entity.UserEntity
import com.sopt.now.domain.usecase.SignUpUseCase
import com.sopt.now.ui.model.User
import com.sopt.now.util.UiState
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject

class SignUpViewModel(private val signUpUseCase: SignUpUseCase) : ViewModel() {
@HiltViewModel
class SignUpViewModel @Inject constructor(
private val signUpUseCase: SignUpUseCase
) : ViewModel() {
private val _signUpState = MutableLiveData<UiState<User>>()
val signUpState:LiveData<UiState<User>> = _signUpState
val signUpState: LiveData<UiState<User>> = _signUpState

fun signUp(request: UserEntity) {
_signUpState.value = UiState.Loading
Expand Down

0 comments on commit b374cf0

Please sign in to comment.