Skip to content

Commit

Permalink
[Mod] #18 AuthRequestModel ->UserEntity 이름변경
Browse files Browse the repository at this point in the history
  • Loading branch information
cacaocoffee committed Jun 14, 2024
1 parent 06dbdef commit f4bb9c1
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 32 deletions.
6 changes: 3 additions & 3 deletions app/src/main/java/com/sopt/now/data/dto/Mapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ package com.sopt.now.data.dto
import com.sopt.now.data.dto.request.RequestLoginDto
import com.sopt.now.data.dto.request.RequestSignUpDto
import com.sopt.now.data.dto.response.BaseResponse
import com.sopt.now.domain.entity.AuthRequestModel
import com.sopt.now.domain.entity.UserEntity
import com.sopt.now.domain.entity.BaseResponseEntity

internal fun AuthRequestModel.toRequestLoginDto(): RequestLoginDto =
internal fun UserEntity.toRequestLoginDto(): RequestLoginDto =
RequestLoginDto(
authenticationId = authenticationId,
password = password
)

internal fun AuthRequestModel.toRequestSignUpDto(): RequestSignUpDto =
internal fun UserEntity.toRequestSignUpDto(): RequestSignUpDto =
RequestSignUpDto(
authenticationId = authenticationId,
password = password,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import com.sopt.now.data.dto.toRequestSignUpDto
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.AuthRequestModel
import com.sopt.now.domain.entity.UserEntity
import com.sopt.now.domain.entity.BaseResponseEntity
import com.sopt.now.domain.repository.AuthRepository
import retrofit2.Response

class AuthRepositoryImpl(private val authService: AuthService) : AuthRepository {
override suspend fun login(authData: AuthRequestModel): Result<Int?> =
override suspend fun login(authData: UserEntity): Result<Int?> =
runCatching {
val response: Response<BaseResponse<Unit>> = authService.login(authData.toRequestLoginDto())
if (response.isSuccessful) {
Expand All @@ -25,7 +25,7 @@ class AuthRepositoryImpl(private val authService: AuthService) : AuthRepository
}
}

override suspend fun signUp(authData: AuthRequestModel): Result<BaseResponseEntity> {
override suspend fun signUp(authData: UserEntity): Result<BaseResponseEntity> {
return runCatching {
authService.signUp(authData.toRequestSignUpDto()).toBaseResponseEntity()
}.onFailure { throwable ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.sopt.now.domain.entity


data class AuthRequestModel(
data class UserEntity(
val authenticationId: String,
val password: String,
val nickname: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.sopt.now.domain.repository

import com.sopt.now.domain.entity.AuthRequestModel
import com.sopt.now.domain.entity.UserEntity
import com.sopt.now.domain.entity.BaseResponseEntity

interface AuthRepository {
suspend fun login(authData: AuthRequestModel): Result<Int?>
suspend fun signUp(authData: AuthRequestModel): Result<BaseResponseEntity>
suspend fun login(authData: UserEntity): Result<Int?>
suspend fun signUp(authData: UserEntity): Result<BaseResponseEntity>
}
4 changes: 2 additions & 2 deletions app/src/main/java/com/sopt/now/domain/usecase/LogInUseCase.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.sopt.now.domain.usecase

import com.sopt.now.domain.entity.AuthRequestModel
import com.sopt.now.domain.entity.UserEntity
import com.sopt.now.domain.repository.AuthRepository

class LogInUseCase(private val authRepository: AuthRepository) {

suspend operator fun invoke(request: AuthRequestModel):Result<Int?> =
suspend operator fun invoke(request: UserEntity):Result<Int?> =
authRepository.login(request)
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.sopt.now.domain.usecase

import com.sopt.now.domain.entity.AuthRequestModel
import com.sopt.now.domain.entity.UserEntity
import com.sopt.now.domain.entity.BaseResponseEntity
import com.sopt.now.domain.repository.AuthRepository

class SignUpUseCase(private val authRepository: AuthRepository) {

suspend operator fun invoke(request: AuthRequestModel):Result<BaseResponseEntity> =
suspend operator fun invoke(request: UserEntity):Result<BaseResponseEntity> =
authRepository.signUp(request)
}
4 changes: 2 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 @@ -8,7 +8,7 @@ import androidx.activity.viewModels
import com.sopt.now.R
import com.sopt.now.ui.model.User
import com.sopt.now.databinding.ActivityLoginBinding
import com.sopt.now.domain.entity.AuthRequestModel
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
Expand Down Expand Up @@ -85,7 +85,7 @@ class LoginActivity : BindingActivity<ActivityLoginBinding>(R.layout.activity_lo
}

private fun getLoginRequest() =
AuthRequestModel(
UserEntity(
authenticationId = binding.etLoginId.text.toString(),
password = binding.etLoginPassword.text.toString(),
nickname = "",
Expand Down
13 changes: 2 additions & 11 deletions app/src/main/java/com/sopt/now/ui/login/LoginViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,16 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.sopt.now.ui.model.User
import com.sopt.now.domain.entity.AuthRequestModel
import com.sopt.now.domain.entity.UserEntity
import com.sopt.now.domain.usecase.LogInUseCase
import com.sopt.now.util.StringNetworkError.FAIL_ERROR
import com.sopt.now.util.StringNetworkError.LOGIN
import com.sopt.now.util.UiState
import kotlinx.coroutines.launch
import org.json.JSONObject
import retrofit2.HttpException

class LoginViewModel(private val logInUseCase: LogInUseCase) : ViewModel() {
private val _loginState = MutableLiveData<UiState<User>>()
val loginState = _loginState

fun login(request: AuthRequestModel) {
fun login(request: UserEntity) {
_loginState.value = UiState.Loading
viewModelScope.launch {
logInUseCase(request)
Expand All @@ -38,10 +34,5 @@ class LoginViewModel(private val logInUseCase: LogInUseCase) : ViewModel() {
}
}
}

companion object {
private const val MESSAGE = "message"
private const val LOCATION = "location"
}
}

4 changes: 2 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,7 +7,7 @@ import androidx.activity.viewModels
import com.sopt.now.R
import com.sopt.now.ui.model.User
import com.sopt.now.databinding.ActivitySignUpBinding
import com.sopt.now.domain.entity.AuthRequestModel
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
Expand Down Expand Up @@ -61,7 +61,7 @@ class SignUpActivity : BindingActivity<ActivitySignUpBinding>(R.layout.activity_
finish()
}

private fun getSignUpRequestDto() = AuthRequestModel(
private fun getSignUpRequestDto() = UserEntity(
authenticationId = binding.etSignupId.text.toString(),
password = binding.etSignupPassword.text.toString(),
nickname = binding.etSignupNickname.text.toString(),
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/java/com/sopt/now/ui/signup/SignUpViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.sopt.now.ui.model.User
import com.sopt.now.domain.entity.AuthRequestModel
import com.sopt.now.domain.entity.UserEntity
import com.sopt.now.domain.usecase.SignUpUseCase
import com.sopt.now.util.UiState
import kotlinx.coroutines.launch
import org.json.JSONObject
import retrofit2.HttpException

class SignUpViewModel(private val signUpUseCase: SignUpUseCase) : ViewModel() {
private val _signUpState = MutableLiveData<UiState<User>>()
val signUpState = _signUpState

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

0 comments on commit f4bb9c1

Please sign in to comment.