-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/week xml07 #19
base: develop-xml
Are you sure you want to change the base?
Feat/week xml07 #19
Changes from all commits
edb66a8
d4bc82f
3ef6911
d97ecc0
b9cc67b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.sopt.now.config | ||
|
||
import android.os.Bundle | ||
import android.os.PersistableBundle | ||
import android.view.LayoutInflater | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.viewbinding.ViewBinding | ||
|
||
abstract class BaseActivity<B : ViewBinding>(private val inflate: (LayoutInflater) -> B) : | ||
AppCompatActivity() { | ||
protected lateinit var binding: B | ||
|
||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
binding = inflate(layoutInflater).apply { | ||
setContentView(root) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.sopt.now.config | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.annotation.LayoutRes | ||
import androidx.fragment.app.Fragment | ||
import androidx.viewbinding.ViewBinding | ||
|
||
abstract class BaseFragment<B : ViewBinding>( | ||
private val bind: (View) -> B, | ||
@LayoutRes layoutResId: Int | ||
) : Fragment(layoutResId) { | ||
private var _binding: B? = null | ||
protected val binding get() = requireNotNull(_binding) | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? { | ||
_binding = super.onCreateView(inflater, container, savedInstanceState)?.let { bind(it) } | ||
return binding.root | ||
} | ||
|
||
override fun onDestroyView() { | ||
_binding = null | ||
super.onDestroyView() | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.sopt.now.data | ||
|
||
import com.sopt.now.datasource.AuthService | ||
import com.sopt.now.model.login.RequestLoginDto | ||
import com.sopt.now.model.signup.RequestSignUpDto | ||
import com.sopt.now.repository.AuthRepository | ||
import com.sopt.now.config.BaseResponse | ||
import retrofit2.Response | ||
|
||
class AuthRepositoryImpl( | ||
private val authService: AuthService | ||
): AuthRepository { | ||
override suspend fun loginUser(data: RequestLoginDto): Response<BaseResponse<Unit>> { | ||
return authService.login(data) | ||
} | ||
|
||
override suspend fun signupUser(data: RequestSignUpDto): Response<BaseResponse<Unit>> { | ||
return authService.signUp(data) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.sopt.now.data | ||
|
||
import com.sopt.now.datasource.InfoService | ||
import com.sopt.now.model.info.UserInfo | ||
import com.sopt.now.repository.MyPageRepository | ||
import com.sopt.now.config.BaseResponse | ||
import retrofit2.Response | ||
|
||
class MyPageRepositoryImpl( | ||
private val infoService: InfoService | ||
) : MyPageRepository { | ||
override suspend fun getUserInfo(): Response<BaseResponse<UserInfo>> { | ||
return infoService.getUserInfo() | ||
} | ||
|
||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. νμ¬ λ·°λͺ¨λΈμ μλ² ν΅μ λ‘μ§λ€μ uiλ¨μ λ·°λͺ¨λΈμ΄ μλ dataλ¨μ repostiory implμμ μννλκ² λ μ’μ κ² κ°μμ! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,33 @@ | ||
package com.sopt.now.presentation.auth.login | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.sopt.now.ApplicationClass.SharedPreferences.editor | ||
import com.sopt.now.model.login.RequestLoginDto | ||
import com.sopt.now.repository.AuthRepository | ||
import com.sopt.now.utils.Constants.Companion.MEMBER_ID | ||
import com.sopt.now.utils.NetworkUtil | ||
import com.sopt.now.utils.ServicePool.loginService | ||
import com.sopt.now.utils.UiState | ||
import dagger.hilt.android.HiltAndroidApp | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
import kotlinx.coroutines.launch | ||
import javax.inject.Inject | ||
|
||
class LoginViewModel : ViewModel() { | ||
@HiltViewModel | ||
class LoginViewModel @Inject constructor( | ||
private val authRepository: AuthRepository | ||
) : ViewModel() { | ||
private val _state = MutableStateFlow<UiState<Unit>>(UiState.LOADING) | ||
val state get() = _state.asStateFlow() | ||
Comment on lines
23
to
24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. μ¬μνμ§λ§ λ³μμ νμ μ λͺ μμ μΌλ‘ μ μ΄μ£Όλ κ²μ΄ μ’μ΅λλ€! |
||
|
||
fun postLogin(data: RequestLoginDto) { | ||
viewModelScope.launch(Dispatchers.IO) { | ||
_state.value = UiState.LOADING | ||
runCatching { | ||
loginService.login(data) | ||
authRepository.loginUser(data) | ||
}.onSuccess { | ||
if (it.isSuccessful) { | ||
editor.putString(MEMBER_ID, it.headers()["location"]) | ||
|
@@ -33,12 +36,14 @@ class LoginViewModel : ViewModel() { | |
_state.value = UiState.SUCCESS(null) | ||
} else { | ||
_state.value = UiState.FAILURE( | ||
it.errorBody()?.let { e -> NetworkUtil.getErrorResponse(e)?.message }.toString() | ||
it.errorBody()?.let { e -> NetworkUtil.getErrorResponse(e)?.message } | ||
.toString() | ||
) | ||
} | ||
}.onFailure { | ||
it.printStackTrace() | ||
} | ||
|
||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,30 @@ | ||
package com.sopt.now.presentation.auth.signup | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.sopt.now.model.signup.RequestSignUpDto | ||
import com.sopt.now.repository.AuthRepository | ||
import com.sopt.now.utils.NetworkUtil | ||
import com.sopt.now.utils.ServicePool.authService | ||
import com.sopt.now.utils.UiState | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
import kotlinx.coroutines.launch | ||
import javax.inject.Inject | ||
|
||
class SignUpViewModel : ViewModel() { | ||
@HiltViewModel | ||
class SignUpViewModel @Inject constructor( | ||
private val authRepository: AuthRepository | ||
) : ViewModel() { | ||
private val _state = MutableStateFlow<UiState<Unit>>(UiState.LOADING) | ||
val state = _state.asStateFlow() | ||
val state get() = _state.asStateFlow() | ||
|
||
fun signUp(data: RequestSignUpDto) { | ||
viewModelScope.launch(Dispatchers.IO) { | ||
_state.value = UiState.LOADING | ||
runCatching { | ||
authService.signUp(data) | ||
authRepository.signupUser(data) | ||
}.onSuccess { | ||
if (it.isSuccessful) _state.value = UiState.SUCCESS(null) | ||
else { | ||
Comment on lines
+16
to
30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. μ μ§μ§ λ©μλ€..μ΄ μΈλ |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ν€μΌ.. λ―μ°λ€..