-
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 xml 07 #19
base: develop-xml
Are you sure you want to change the base?
Feat/week xml 07 #19
Conversation
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.
์๋
ํ์ธ์ ๋ช
์๋ ๋ง์ง๋ง ์ฃผ์ฐจ ์ฝ๋๋ฆฌ๋ทฐ๋ฅผ ๋งก๊ฒ๋ ๋ช
์ OB ์์ฌ์์
๋๋ค!
์ ๋ฒ์ ๋ฆฌ๋ทฐ ํ ๋์ ๋นํด ํญํ์ ์ผ๋ก ์ฑ์ฅํ์ ๋ชจ์ต์ ๋ณธ ๊ฒ ๊ฐ์์ ์ ๋ง ์กด๊ฒฝ์ ํํฉ๋๋ค.
34๊ธฐ YB๋ถ๋ค์ ์ ๋ง ๋ค๋ค ์ค๋ ฅ์ด ์ถ์คํ์ ๊ฒ ๊ฐ๊ตฐ์, ์๋๋ก์ด๋ ์ฑ ์ํคํ
์ฒ์ ์ธ์ธํ ์ฝํ๋ฆฐ ๋ฌธ๋ฒ์ ๊ฐ๋
์ ์ฑ์ฐ์๋ฉด ๋ ๊ดด๋ฌผ๊ฐ์ ๊ฐ๋ฐ์๊ฐ ๋์ค ๊ฒ ๊ฐ์ต๋๋ค.
์ธ๋ฏธ๋ ์์ฃผํ์๋๋ผ ์ ๋ง ๊ณ ์ํ์
จ์ต๋๋ค. ํ๋ณต ์ฑ์ผ ํ์๊ธธ ๐
import androidx.lifecycle.viewModelScope | ||
import com.sopt.now.data.model.User | ||
import com.sopt.now.util.StringNetworkError.FAIL_ERROR | ||
import com.sopt.now.util.StringNetworkError.LOGIN | ||
import com.sopt.now.util.StringNetworkError.SERVER_ERROR | ||
import com.sopt.now.domain.entity.request.AuthRequestModel | ||
import com.sopt.now.domain.usecase.LogInUseCase |
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.
์ง๋ ๋ฆฌ๋ทฐ์์๋ ๋ง์๋๋ ธ๋ ๋ฌธ์ ์ธ๋ฐ
์ง๊ธ ์๋๋ก์ด๋ ์ฑ ์ํคํ
์ฒ๋ฅผ ์ ์ฉ์ค์ด์๋ผ๋ฉด ui -> domain -> data ํ์์ผ๋ก ์ฐธ์กฐ๊ฐ ๋์ด์ผํ ๊ฒ์
๋๋ค.
ํ์ง๋ง data์ model๋ฅผ ๋ถ๋ฌ์์ ์ฌ์ฉ์ค์ด๋ ui๊ฐ domain๊ณผ data๋ฅผ ๋ชจ๋ ์ฐธ์กฐํ๋ ๋ชจ์์์ด์ฃ
์ด๋ป๊ฒ ์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ ์ง ๊ณ ๋ฏผํด๋ณด์๋ ๊ฒ๋ ์ข์ ๊ฒ ๊ฐ์ต๋๋ค.
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.
๋๋ฌด ์๋ชป์ฐ๊ณ ์์๋ค์..
๋ง์ํด์ฃผ์ ์ฃผ์ ์ ์ํคํ
์ฒ ์ฌ๋ฌ ๊ด๋ จ๋ ์๋ฃ ์ฐพ์๋ณด๊ณ ๊ณต๋ถํ๋ค๊ณ ๋ต๋ณ์ ๋๋ฌด ๋ฆ๊ฒ ๋ฌ์๋ค์
์ ๋๋ก ํ์ง๋ ๋ชจ๋ฅด์ง๋ง clean ์ํคํ ์ฒ์ ๋ํด์ ์ฐพ์ ๊ณต๋ถํ๊ณ ์ ์ฉ์ ํ๋ ค ๋ ธ๋ ฅ์ ํ์ต๋๋ค.
์ฑ์ผ์ ์ ๋๋ก ๋ค์ด๊ฐ์ ์ ๊ตฌ๊ธ๊ถ์ฅ์ํคํ ์ฒ๋ ์ ๋๋ก ํ์ธํด๋ณด๊ณ ๊ฐ๋ ค๊ตฌ์ ๊ฐ์ฌํฉ๋๋ค.
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.
๋ฉ์ง ์ฑ์ฅ ๊ธฐ๋ํ๊ฒ ์ต๋๋ค!
private val _loginState = MutableLiveData<UiState<User>>() | ||
val loginState = _loginState |
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.
์ฌ์ํ์ง๋ง ๋ณ์์ ํ์ ์ ๋ช ์์ ์ผ๋ก ์ ์ธํด์ฃผ๋ ๊ฒ์ด ์ข์ต๋๋ค.
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.
๋ต ๊ฐ์ฌํฉ๋๋ค! ํ์ ๋ช ์ํ๋ ๊ฒ ์ ์ง์ผ๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค! ์ฌ์ค ๋ช ์ํ๋ ๊ฒ ์ข์ ๊ฑด ์ค ๋ชฐ๋์ด์
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.
์ปดํจํฐ๊ด์ ์์ ์ถ๋ก ํ๋ ๊ฒ๋ณด๋ค ๋ช ์๋์ด์๋๊ฑธ ๊ฐ์ ธ๋ค ์ฐ๋๊ฒ ์ข๊ฒ ๋ค๋ ์๊ฐ์ ๋๋ค.
private fun getLoginRequest() = | ||
AuthRequestModel( | ||
authenticationId = binding.etLoginId.text.toString(), | ||
password = binding.etLoginPassword.text.toString() | ||
password = binding.etLoginPassword.text.toString(), | ||
nickname = "", | ||
phone = "" | ||
) |
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.
๋ฐ์ดํฐ ๋ฐ์ธ๋ฉ์ ์ฌ์ฉํ๋ฉด ์ด ๊ท์ฐฎ์ ๊ณผ์ ์ ํํผํ ์๋ ์์ต๋๋ค!
class LoginViewModelFactory : ViewModelProvider.Factory { | ||
override fun <T : ViewModel> create(modelClass: Class<T>): T { | ||
if (modelClass.isAssignableFrom(LoginViewModel::class.java)) { | ||
val repository = | ||
AuthRepositoryImpl(ServicePool.authService) | ||
val logInUseCase = LogInUseCase(repository) | ||
return LoginViewModel(logInUseCase) as T | ||
} else { | ||
throw IllegalArgumentException("Failed to create ViewModel: ${modelClass.name}") | ||
} | ||
} | ||
} |
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.
ViewModelFactory๋ฅผ ์ฌ์ฉํ๋ค๋ณด๋ฉด ๋ทฐ๋ชจ๋ธ๋ง๋ค ๋ทฐ๋ชจ๋ธํํ ๋ฆฌ๊ฐ ์์ฑ๋๋ ๋ถํธํจ์ด ์๊ธฐ๋ ๊ฒ์ ๋๋ผ์
จ์ ๊ฒ๋๋ค.
ํ๋ก์ ํธ์ ์ ์ฉํ ์ง๋ ๋ชจ๋ฅด๊ฒ ์ง๋ง Hilt๋ก ๋ง์ด๊ทธ๋ ์ด์
ํ๋ฉด์ ์๋ DI๊ฐ ์ด๋ค ์ด์ ์ ๊ฐ์ ธ์ค๋์ง ์์๋ณด์๋ฉด ์ ๋ง ๋์์ด ๋ง์ด ๋ ๊ฒ ๊ฐ์ต๋๋ค.
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.
๋ง์ต๋๋ค.. ์ ๋ ๊ทธ๋ ๊ฒ ํ๋๋ ๋ฒ๊ฑฐ๋กญ๋๋ผ๊ตฌ์ ์ ๋ Hilt ๋ค์์ ๊ผญ ์ ์ฉํด๋ด์ผ๊ฒ ์ต๋๋ค!!
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.
์ฐ์ viewmodel ํฉํ ๋ฆฌ ํ๋๋ก ์์
์ ํ์ต๋๋ค. hilt์ ๋ํด์ ๊ณต๋ถํ๊ณ ์ ์ฉํด๋ณด๋ ๋จ๊ณ์ ์์ด์.
ํผ์์ด์ด ๋๋ ์กฐ์ธ ๊ฐ์ฌํฉ๋๋ค..
viewModelScope.launch { | ||
runCatching { | ||
infoService.getUserInfo(userid) | ||
}.onSuccess { response -> |
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.
์ฌ๊ธฐ๋ repository ํจํด์ด ์ ์ฉ๋์ด ์์ง ์์๊ฑด๊ฐ์?
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.
๋ต ๋น์์ login๊ณผ signup์ ํ๋ฉด์ ์ ๊ฐ ๊ณต๋ถํ๊ฑฐ์ ๋ํ ํ์ ์ด ์์์ด์...
๋ญ๊ฐ ์ด๋ ๊ฒ ์ง๋ ๊ฒ์ด ๋ง๋๊ฑด๊ฐ ๊ณ ๋ฏผ์ด ๋ค๋ฉด์ ํ์คํ ํ๊ณ ์ ์ฉ์ ํ๊ธฐ๋ก ํ์์ต๋๋ค!
์ง๊ธ์ ์ถ๊ฐํด์ ๋ฃ์ด๋์์ด์!
data class AuthRequestModel( | ||
val authenticationId: String, | ||
val password: String, | ||
val nickname: String, | ||
val phone: String, | ||
) { | ||
fun toRequestSignup(): RequestSignUpDto = | ||
RequestSignUpDto(authenticationId, password, nickname, phone) | ||
|
||
fun toRequestLogin(): RequestLoginDto = RequestLoginDto(authenticationId, password) | ||
fun toUserWithUserId(userid: String): User = | ||
User( | ||
id = authenticationId, | ||
password = password, | ||
nickname = nickname, | ||
phoneNumber = phone, | ||
userId = userid | ||
) | ||
} |
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.
AuthRequestModel
๋ฅผ ์ฐ์๊ฒ๋ ์ด์ ๊ฐ ๊ถ๊ธํฉ๋๋ค!
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.
data ์์ญ์์ ui ์ ์ฌ์ฉํ๊ธฐ์ ์ค๊ฐ๋ค๋ฆฌ๋ก ์๊ฐํ๊ณ ์ถ๊ฐํ์ต๋๋ค.
์ ๋น์์ ์์กด๊ด๊ณ๊ฐ ํท๊ฐ๋ ค ๋๋ฌด ์๋ชป์ง๊ณ ๋ฃ์๋ค์.. ์ฌ์๋ ๋ฆฌ๋ทฐ ๋๋ถ์ ์ ์ฌ์ฉํ๋๊ฐ์ ๋ํ ๋ณธ์ง์ ์ธ ๊ณ ๋ฏผ์ ํ ์์ ํ์ต๋๋ค ๊ฐ์ฌํด์
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.
์ฐธ์ ํ ์ ๊ทผ์ธ ๊ฒ ๊ฐ์์ ์ด๋ฐ ๋ณธ์ธ๋ง์ ์ ๊ทผ๋ ์ข๋ค๊ณ ์๊ฐํฉ๋๋ค
import retrofit2.Response | ||
|
||
interface AuthRepository { | ||
suspend fun logIn(authData: AuthRequestModel): Result<Response<BaseResponse<Unit>>> |
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.
login์ ํต์์ ์ผ๋ก ํ๋จ์ด๋ก ์ธ์ํฉ๋๋ค!
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.
๊ฐ์ฌํฉ๋๋ค ๋ญ๊ฐ.. ๊ฐ์๊ธฐ ํท๊ฐ๋ ธ์ด์..
companion object { | ||
const val MESSAGE = "message" | ||
const val LOCATION = "location" | ||
} |
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.
private๋ฅผ ๋ฐ๋ก ๋ถ์ด์์ง ์์ผ์ จ๋๋ฐ ๋ค๋ฅธ ๊ณณ์์ ์ฌ์ฉํ๋ ๊ฒ ์ผ๊น์?
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.
์์ต๋๋ค private ๋ถ์ด๋๊ฑธ ๊น๋จน์๋ค์ ๊ฐ์ฌํฉ๋๋ค.
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.
์ฝ๋๋ฆฌ๋ทฐ ํญ์ ๋ง์ด ๋ฐ๊ธฐ๋ง ํ๊ณ ์์ง์ ์ฝ๋ฆฌ๋ฅผ ๋ชป ๋ฌ์๋๋ฆฐ ๊ฒ ๊ฐ์์ ์์ํด์ใ
ใ
(๋ค์ ๊ธฐ์์ ์ ๊ฐ ๋ ๋ฐ์ ํด์ ๊ณ์ ๋ฌ์๋๋ฆฌ๊ณ ์ถ๋ค์ ใ
)
์ด๋ฒ ๊ณผ์ ๋ ์๊ณ ๋ง์ผ์
จ์ต๋๋ค!!
class LoginViewModelFactory : ViewModelProvider.Factory { | ||
override fun <T : ViewModel> create(modelClass: Class<T>): T { | ||
if (modelClass.isAssignableFrom(LoginViewModel::class.java)) { | ||
val repository = | ||
AuthRepositoryImpl(ServicePool.authService) | ||
val logInUseCase = LogInUseCase(repository) | ||
return LoginViewModel(logInUseCase) as T | ||
} else { | ||
throw IllegalArgumentException("Failed to create ViewModel: ${modelClass.name}") | ||
} | ||
} | ||
} |
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.
๋ง์ต๋๋ค.. ์ ๋ ๊ทธ๋ ๊ฒ ํ๋๋ ๋ฒ๊ฑฐ๋กญ๋๋ผ๊ตฌ์ ์ ๋ Hilt ๋ค์์ ๊ผญ ์ ์ฉํด๋ด์ผ๊ฒ ์ต๋๋ค!!
|
||
class LogInUseCase(private val authRepository: AuthRepository) { | ||
suspend fun execute(request: AuthRequestModel): UiState<User> { | ||
return withContext(Dispatchers.IO) { | ||
try { | ||
val result = authRepository.logIn(request) | ||
result.fold( | ||
onSuccess = { response -> | ||
if (response.isSuccessful) { | ||
UiState.Success( | ||
User( | ||
request.authenticationId, | ||
request.password, | ||
"", | ||
"", | ||
userId = response.headers()[LOCATION].toString() | ||
) | ||
) |
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.
์.. UseCase ๋ถ๋ฆฌ.. ์๊ณ ์์๋๋ฐ!!!
๋ฉ์ ธ์.. ๊ฐ๋
์ฑ์ด ํจ ์ข๋ค์
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.
์๋์์ ใ ใ ๋ถ๋ฆฌ๋ํ๋๋ฐ ๋๋ฌด ์๋ชปํด์.. ๋ฐ๋ ์ฝ๋์ฒ๋ผ ํด์ผํ๋๊ฑธ๋ก ์๊ณ ์์ด์
viewModelScope.launch { | ||
_loginState.value = logInUseCase.execute(request) | ||
} |
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.
์์ด ๋ง ์์ํด์ง๋ค์
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.
์ด๋ฌ๋ฉด ์๋๋์ ใ
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.
์๊ณ ํ์ จ์ต๋๋ค!
|
||
class LogInUseCase(private val authRepository: AuthRepository) { | ||
suspend fun execute(request: AuthRequestModel): UiState<User> { | ||
return withContext(Dispatchers.IO) { |
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.
withContext๋ก๋ ์ฝ๋ฃจํด์ ์คํํ ์ ์๊ตฐ์! ์์๊ฐ์!!
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.
๋ต ๊ทธ๋ฐ๋ฐ usecase์์ ์ด๋ ๊ฒ ์ฐ๋ฉด์๋ผ์! domain ์์ญ์ ์๋ฒํต์ ์ด๋ ์ฌ๋ฌ ๊ณผ์ ์ด ๋ค์ด๊ฐ๊ฒ ๋์ด์ ์ ๋ชป ์ง ์ฝ๋์ ๋๋ค!
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.
ํ ํ๊ธฐ ๋์ ๊ณ ์ ๋ง์ผ์
จ์ต๋๋ค!!
๋๋ฌด๋ ์ด์ฌํ ์ํด์ฃผ์ด์ ๊ณ ๋ง์์ใ
ใ
ใ
ใ
์์ธํ ์ฌํญ์ ๋ฐ๋ก ๊ฐ์ธํก ๋๋ฆด๊ฒ์!
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.
์ผ๋จ ์ด ๋ก์ง์ data์์ญ์ ์์ด์ผ ํ๋ ๋ก์ง์
๋๋ค!
repositoryํจํด์ ์ํ๋ฉด data์์ญ์์ ์๋ฒ ํต์ ๊ณผ ๊ฐ์ ๋ก์ง์ ๋ด๋น ํ๊ฒ ๋๋๋ฐ
domain์ ์ด๋ฌํ ์๋ฒํต์ ๋ก์ง์ ๋ด๋นํ๋ ๊ฒ์ด ์๋ repository ์ธํฐํ์ด์ค๋ฅผ ํตํด ๋ฐ์ดํฐ๋ฅผ ์์ฒญํ๋ ์ญํ ๋ง ์ํํ๊ฒ ๋ฉ๋๋ค. ์ค์ ๊ตฌํ์ data์์ ํ๊ฒ๋๊ณ ์ด๋ฅผ ์์กด์ฑ ์ญ์ ์ด๋ผ๊ณ ๋ถ๋ฆ
๋๋ค.
domain์ usecase๋ ์ด๋ฌํ interface๋ฅผ ์ฐธ์กฐํ์ฌ ํน์ ๋น์ฆ๋์ค ๋ก์ง์ ์บก์ํ ํฉ๋๋ค.
์ง๊ธ data ๋ ์ด์ด์ ๋ถ๋ฆฌ๊ฐ ๋ชฉ์ ์ธ์ง ํน์ ํด๋ฆฐ์ํคํ ์ณ์์ ๊ตฌ์กฐ๊ฐ ๋ชฉ์ ์ธ์ง ํ์คํ๊ฒ ์ ํ๊ณ ๋ค์ ๋ฆฌํฉํ ๋ง ํด๋ณด๋ฉด ์ข์๊ฒ ๊ฐ์์!!
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.
์ ๋ง ๊ฐ์ฌํฉ๋๋ค
ํด๋ฆฐ์ํคํ
์ฒ๋ฅผ ์ ์ฉํด๋ณด์! ๋ผ๊ณ ํ๊ธดํ๋๋ฐ ๋ง์ ํ๋ฉด์ ์ด์ํ๊ฑฐ ๊ฐ๋๋ผ๊ตฌ์...
์ ๊ฐ ํ๋ ๋ฐฉ๋ฉด์ด ๋ง๋ ์ถ๊ธฐ๋ ํ์๋๋ฐ ๋๋ถ์ ์๋ฌธ์ ์ ๋ง์ด ํด๊ฒฐํ๊ณ ์์
ํ ์ ์์์ด์.
์ง๊ธ ์์ ํ ๋ฐฉ์์ด ์ ๋ต์ด ์๋ ์๋ ์๋๋ผ๋ ๋๋ถ์ ๋ง์ ๊ฑธ ์๊ฒ ๋์์ด์ ๊ฐ์ฌํฉ๋๋ค.
์ดํ์ ์์ธํ ์ค๋ช
๋๋ถ์ ํ์ฌ ๊ณต๋ถํ๊ณ ์ ์ฉ์ ํด๋ดค์ด์ datasource ๋ก ๋ถ๋ฆฌํ๊ณ hilt ์ ์ฉ๋ ๋
ธ๋ ฅํด๋ณด๊ฒ ์ต๋๋ค..
data class AuthRequestModel( | ||
val authenticationId: String, | ||
val password: String, | ||
val nickname: String, | ||
val phone: String, | ||
) { | ||
fun toRequestSignup(): RequestSignUpDto = | ||
RequestSignUpDto(authenticationId, password, nickname, phone) | ||
|
||
fun toRequestLogin(): RequestLoginDto = RequestLoginDto(authenticationId, password) | ||
fun toUserWithUserId(userid: String): User = | ||
User( | ||
id = authenticationId, | ||
password = password, | ||
nickname = nickname, | ||
phoneNumber = phone, | ||
userId = userid | ||
) | ||
} |
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.
domain์์ dto๋ฅผ ์ฐธ์กฐํ๋ ๊ฒ์ด ์๋ data์์ dto๋ฅผ ์ฐธ์กฐํด์ผ ํฉ๋๋ค!
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.
๋ต ๊ฐ์ฌํฉ๋๋ค. ์๊ทธ๋๋ ์ฝ๋ ์ง๋ฉด์ ๋ญ๊ฐ ์๋ชป๋์๋ค๋ ์๊ฐ์ด ๋ค์ด์ ๊ณ ๋ฏผ๋ง์ด ํ์๋๋ฐ ๋๋ถ์ ๊ธธ์ ์ฐพ์ ์ ์์์ด์
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.
๋๋ฌด ๋๋ ๋ฆ์ ๋ต๋ณ ๋๋ ค ์ฃ์กํฉ๋๋ค. ๋ค๋ค ๋ถ์กฑํ ์ ์๊ฒ๋ comment์ ๋์ ์ฃผ์ ์ ๊ณ ๋ง์์ ์ํธ ํ๋ํ๋ ๋์ ์ฌ๋ฌ๋ถ์ ์ฝ๋๋ฆฌ๋ทฐ๊ฐ ๋๋ฌด๋๋ ํฐ ๋์์ด ๋์์ต๋๋ค.
๋ค์ ํ๋ฒ ๋๋ฌด ๊ฐ์ฌ๋๋ฆฝ๋๋ค. ํฐ ๋์ ๋ฐ์์ด์.
companion object { | ||
const val MESSAGE = "message" | ||
const val LOCATION = "location" | ||
} |
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.
์์ต๋๋ค private ๋ถ์ด๋๊ฑธ ๊น๋จน์๋ค์ ๊ฐ์ฌํฉ๋๋ค.
|
||
class LogInUseCase(private val authRepository: AuthRepository) { | ||
suspend fun execute(request: AuthRequestModel): UiState<User> { | ||
return withContext(Dispatchers.IO) { |
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.
๋ต ๊ทธ๋ฐ๋ฐ usecase์์ ์ด๋ ๊ฒ ์ฐ๋ฉด์๋ผ์! domain ์์ญ์ ์๋ฒํต์ ์ด๋ ์ฌ๋ฌ ๊ณผ์ ์ด ๋ค์ด๊ฐ๊ฒ ๋์ด์ ์ ๋ชป ์ง ์ฝ๋์ ๋๋ค!
|
||
class LogInUseCase(private val authRepository: AuthRepository) { | ||
suspend fun execute(request: AuthRequestModel): UiState<User> { | ||
return withContext(Dispatchers.IO) { | ||
try { | ||
val result = authRepository.logIn(request) | ||
result.fold( | ||
onSuccess = { response -> | ||
if (response.isSuccessful) { | ||
UiState.Success( | ||
User( | ||
request.authenticationId, | ||
request.password, | ||
"", | ||
"", | ||
userId = response.headers()[LOCATION].toString() | ||
) | ||
) |
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.
์๋์์ ใ ใ ๋ถ๋ฆฌ๋ํ๋๋ฐ ๋๋ฌด ์๋ชปํด์.. ๋ฐ๋ ์ฝ๋์ฒ๋ผ ํด์ผํ๋๊ฑธ๋ก ์๊ณ ์์ด์
data class AuthRequestModel( | ||
val authenticationId: String, | ||
val password: String, | ||
val nickname: String, | ||
val phone: String, | ||
) { | ||
fun toRequestSignup(): RequestSignUpDto = | ||
RequestSignUpDto(authenticationId, password, nickname, phone) | ||
|
||
fun toRequestLogin(): RequestLoginDto = RequestLoginDto(authenticationId, password) | ||
fun toUserWithUserId(userid: String): User = | ||
User( | ||
id = authenticationId, | ||
password = password, | ||
nickname = nickname, | ||
phoneNumber = phone, | ||
userId = userid | ||
) | ||
} |
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.
data ์์ญ์์ ui ์ ์ฌ์ฉํ๊ธฐ์ ์ค๊ฐ๋ค๋ฆฌ๋ก ์๊ฐํ๊ณ ์ถ๊ฐํ์ต๋๋ค.
์ ๋น์์ ์์กด๊ด๊ณ๊ฐ ํท๊ฐ๋ ค ๋๋ฌด ์๋ชป์ง๊ณ ๋ฃ์๋ค์.. ์ฌ์๋ ๋ฆฌ๋ทฐ ๋๋ถ์ ์ ์ฌ์ฉํ๋๊ฐ์ ๋ํ ๋ณธ์ง์ ์ธ ๊ณ ๋ฏผ์ ํ ์์ ํ์ต๋๋ค ๊ฐ์ฌํด์
data class AuthRequestModel( | ||
val authenticationId: String, | ||
val password: String, | ||
val nickname: String, | ||
val phone: String, | ||
) { | ||
fun toRequestSignup(): RequestSignUpDto = | ||
RequestSignUpDto(authenticationId, password, nickname, phone) | ||
|
||
fun toRequestLogin(): RequestLoginDto = RequestLoginDto(authenticationId, password) | ||
fun toUserWithUserId(userid: String): User = | ||
User( | ||
id = authenticationId, | ||
password = password, | ||
nickname = nickname, | ||
phoneNumber = phone, | ||
userId = userid | ||
) | ||
} |
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.
๋ต ๊ฐ์ฌํฉ๋๋ค. ์๊ทธ๋๋ ์ฝ๋ ์ง๋ฉด์ ๋ญ๊ฐ ์๋ชป๋์๋ค๋ ์๊ฐ์ด ๋ค์ด์ ๊ณ ๋ฏผ๋ง์ด ํ์๋๋ฐ ๋๋ถ์ ๊ธธ์ ์ฐพ์ ์ ์์์ด์
private val _loginState = MutableLiveData<UiState<User>>() | ||
val loginState = _loginState |
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.
๋ต ๊ฐ์ฌํฉ๋๋ค! ํ์ ๋ช ์ํ๋ ๊ฒ ์ ์ง์ผ๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค! ์ฌ์ค ๋ช ์ํ๋ ๊ฒ ์ข์ ๊ฑด ์ค ๋ชฐ๋์ด์
viewModelScope.launch { | ||
_loginState.value = logInUseCase.execute(request) | ||
} |
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.
์ด๋ฌ๋ฉด ์๋๋์ ใ
class LoginViewModelFactory : ViewModelProvider.Factory { | ||
override fun <T : ViewModel> create(modelClass: Class<T>): T { | ||
if (modelClass.isAssignableFrom(LoginViewModel::class.java)) { | ||
val repository = | ||
AuthRepositoryImpl(ServicePool.authService) | ||
val logInUseCase = LogInUseCase(repository) | ||
return LoginViewModel(logInUseCase) as T | ||
} else { | ||
throw IllegalArgumentException("Failed to create ViewModel: ${modelClass.name}") | ||
} | ||
} | ||
} |
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.
์ฐ์ viewmodel ํฉํ ๋ฆฌ ํ๋๋ก ์์
์ ํ์ต๋๋ค. hilt์ ๋ํด์ ๊ณต๋ถํ๊ณ ์ ์ฉํด๋ณด๋ ๋จ๊ณ์ ์์ด์.
ํผ์์ด์ด ๋๋ ์กฐ์ธ ๊ฐ์ฌํฉ๋๋ค..
viewModelScope.launch { | ||
runCatching { | ||
infoService.getUserInfo(userid) | ||
}.onSuccess { response -> |
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.
๋ต ๋น์์ login๊ณผ signup์ ํ๋ฉด์ ์ ๊ฐ ๊ณต๋ถํ๊ฑฐ์ ๋ํ ํ์ ์ด ์์์ด์...
๋ญ๊ฐ ์ด๋ ๊ฒ ์ง๋ ๊ฒ์ด ๋ง๋๊ฑด๊ฐ ๊ณ ๋ฏผ์ด ๋ค๋ฉด์ ํ์คํ ํ๊ณ ์ ์ฉ์ ํ๊ธฐ๋ก ํ์์ต๋๋ค!
์ง๊ธ์ ์ถ๊ฐํด์ ๋ฃ์ด๋์์ด์!
import androidx.lifecycle.viewModelScope | ||
import com.sopt.now.data.model.User | ||
import com.sopt.now.util.StringNetworkError.FAIL_ERROR | ||
import com.sopt.now.util.StringNetworkError.LOGIN | ||
import com.sopt.now.util.StringNetworkError.SERVER_ERROR | ||
import com.sopt.now.domain.entity.request.AuthRequestModel | ||
import com.sopt.now.domain.usecase.LogInUseCase |
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.
๋๋ฌด ์๋ชป์ฐ๊ณ ์์๋ค์..
๋ง์ํด์ฃผ์ ์ฃผ์ ์ ์ํคํ
์ฒ ์ฌ๋ฌ ๊ด๋ จ๋ ์๋ฃ ์ฐพ์๋ณด๊ณ ๊ณต๋ถํ๋ค๊ณ ๋ต๋ณ์ ๋๋ฌด ๋ฆ๊ฒ ๋ฌ์๋ค์
์ ๋๋ก ํ์ง๋ ๋ชจ๋ฅด์ง๋ง clean ์ํคํ ์ฒ์ ๋ํด์ ์ฐพ์ ๊ณต๋ถํ๊ณ ์ ์ฉ์ ํ๋ ค ๋ ธ๋ ฅ์ ํ์ต๋๋ค.
์ฑ์ผ์ ์ ๋๋ก ๋ค์ด๊ฐ์ ์ ๊ตฌ๊ธ๊ถ์ฅ์ํคํ ์ฒ๋ ์ ๋๋ก ํ์ธํด๋ณด๊ณ ๊ฐ๋ ค๊ตฌ์ ๊ฐ์ฌํฉ๋๋ค.
๐ Related issue
โ๏ธ Work Description
๐ธ Screenshot
4.mp4
๐ Uncompleted Tasks
๐ข To Reviewers
usecase ๋ถ๋ฆฌ ์ด๋ ๊ฒํ๋๊ฒ ๋ง๋์ง ๊ถ๊ธํฉ๋๋ค.
invoke๋ก ๋ณ๋ ํจ์ ์ ์ธ ์์ดํ๋๊ฒ ์ข์์ง ๊ถ๊ธํฉ๋๋ค.
7์ฃผ์ฐจ ๋์ ๋ถ์กฑํ ์ ์๊ฒ ๋ฆฌ๋ทฐ ๋ง์ด ๋ฌ์์ฃผ์ ์ ๋ค๋ค ๊ฐ์ฌํด์
โ Check List