Skip to content

Commit

Permalink
[fix] : domain 영역 entity로 변경, ui영역 model 삭제
Browse files Browse the repository at this point in the history
  • Loading branch information
chanubc committed Jan 3, 2024
1 parent d6cbccb commit bb7110e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import androidx.lifecycle.lifecycleScope
import kotlinx.coroutines.launch
import org.sopt.dosopttemplate.R
import org.sopt.dosopttemplate.databinding.ActivitySignUpBinding
import org.sopt.dosopttemplate.ui.model.User
import org.sopt.dosopttemplate.domain.entity.UserEntity
import org.sopt.dosopttemplate.utils.UiState
import org.sopt.dosopttemplate.utils.ViewModelFactory
import org.sopt.dosopttemplate.utils.toast
Expand Down Expand Up @@ -39,23 +39,23 @@ class SignUpActivity : AppCompatActivity() {

private fun initSignUp() {
binding.btnLogin.setOnClickListener {
val userEntity = User(
val userEntity = UserEntity(
id = binding.editId.text.toString(),
pwd = binding.editPwd.text.toString(),
nickName = binding.editNickname.text.toString(),
mbti = binding.editMbti.text.toString(),
)
viewModel.postSignUp(userEntity)
observeSignUpState(userEntity)
observeSignUpState()
}
}

private fun observeSignUpState(userEntity: User) {
private fun observeSignUpState() {
lifecycleScope.launch {
viewModel.signUpState.collect {
when (it) {
is UiState.Success -> {
sendUserData(userEntity)
sendUserData(it.data)
toast(getString(R.string.toast_signUp_compeleted))
}

Expand All @@ -66,7 +66,7 @@ class SignUpActivity : AppCompatActivity() {
}
}

private fun sendUserData(userEntity: User) {
private fun sendUserData(userEntity: UserEntity) {
val intent = Intent(this@SignUpActivity, LoginActivity::class.java)
intent.putExtra(USER_TAG, userEntity)
// LoginActivity로 결과를 반환
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.sopt.dosopttemplate.ui.login

import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
Expand All @@ -9,14 +8,13 @@ import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.launch
import org.sopt.dosopttemplate.data.dto.remote.request.RequestSignUpDto
import org.sopt.dosopttemplate.data.repositoryimpl.AuthRepository
import org.sopt.dosopttemplate.ui.model.User
import org.sopt.dosopttemplate.domain.entity.UserEntity
import org.sopt.dosopttemplate.domain.repository.AuthDomainRepository
import org.sopt.dosopttemplate.utils.UiState

class SignUpViewModel(private val authRepository: AuthRepository) : ViewModel() {
private val _signUpState = MutableStateFlow<UiState<User>>(UiState.Loading)
val signUpState: StateFlow<UiState<User>> = _signUpState.asStateFlow()
class SignUpViewModel(private val authRepository: AuthDomainRepository) : ViewModel() {
private val _signUpState = MutableStateFlow<UiState<UserEntity>>(UiState.Loading)
val signUpState: StateFlow<UiState<UserEntity>> = _signUpState.asStateFlow()

private val id = MutableLiveData<String>()
private val password = MutableLiveData<String>()
Expand Down Expand Up @@ -104,23 +102,14 @@ class SignUpViewModel(private val authRepository: AuthRepository) : ViewModel()
_isBtnSelected.value = isIdValid && isPasswordValid && isNickNameValid && isMbtiValid
}

fun postSignUp(userEntity: User) {
fun postSignUp(userEntity: UserEntity) {
viewModelScope.launch {
authRepository.postSignUp(
RequestSignUpDto(
userEntity.id,
userEntity.pwd,
userEntity.nickName,
),
).onSuccess {
if (it.isSuccessful) {
authRepository.signUp(userEntity)
.onSuccess {
_signUpState.value = UiState.Success(userEntity)
} else {
}.onFailure {
_signUpState.value = UiState.Error
}
}.onFailure {
Log.e("SignUpActivity", "Error: ${it.message}")
}
}
}
}
12 changes: 0 additions & 12 deletions app/src/main/java/org/sopt/dosopttemplate/ui/model/User.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.sopt.dosopttemplate.ui.model

import org.sopt.dosopttemplate.domain.entity.UserEntity

object UserInfo {
var userInfoList = User(
var userInfoList = UserEntity(
id = "",
pwd = "",
nickName = "",
Expand Down

0 comments on commit bb7110e

Please sign in to comment.