-
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
Changes from 14 commits
c3591ce
7e3a2b4
e9bb79d
ae881b6
23151c3
b41a135
f1ad914
8339904
ad8381d
4784add
adb8543
6029ae8
2cc557b
1c197b0
3e6e6ba
d752e67
05219f1
29a96db
381ecab
f639c9a
06dbdef
f4bb9c1
32a8c17
d91ec8a
94ace2d
46038a3
a2f41df
60b29dc
0c69554
b374cf0
df0c370
e2a65aa
256d629
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,19 @@ | ||
package com.sopt.now.data | ||
|
||
import com.sopt.now.data.api.AuthService | ||
import com.sopt.now.data.dto.response.BaseResponse | ||
import com.sopt.now.domain.entity.request.AuthRequestModel | ||
import com.sopt.now.domain.repository.AuthRepository | ||
import retrofit2.Response | ||
|
||
class AuthRepositoryImpl(private val authService: AuthService) : AuthRepository { | ||
override suspend fun logIn(authData: AuthRequestModel): Result<Response<BaseResponse<Unit>>> = | ||
runCatching { | ||
authService.login(authData.toRequestLogin()) | ||
} | ||
|
||
override suspend fun signUp(authData: AuthRequestModel): Result<Response<BaseResponse<Unit>>> = | ||
runCatching { | ||
authService.signUp(authData.toRequestSignup()) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
package com.sopt.now.data.api | ||
|
||
import com.sopt.now.data.datasouce.response.ResponseInfoDto | ||
import retrofit2.Call | ||
import com.sopt.now.data.dto.response.ResponseInfoDto | ||
import retrofit2.Response | ||
import retrofit2.http.GET | ||
import retrofit2.http.Header | ||
|
||
interface InfoService { | ||
@GET("/member/info") | ||
fun getUserInfo( | ||
suspend fun getUserInfo( | ||
@Header("memberid") userId: String, | ||
): Call<ResponseInfoDto> | ||
): Response<ResponseInfoDto> | ||
} |
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.sopt.now.data.dto.response | ||
|
||
import com.sopt.now.data.model.User | ||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class ResponseInfoDto( | ||
@SerialName("code") | ||
val code: Int, | ||
@SerialName("message") | ||
val message: String, | ||
@SerialName("data") | ||
val data: UserData | ||
){ | ||
@Serializable | ||
data class UserData( | ||
@SerialName("authenticationId") | ||
val authenticationId: String, | ||
@SerialName("nickname") | ||
val nickname: String, | ||
@SerialName("phone") | ||
val phone: String, | ||
) { | ||
fun toUser() = User(id = authenticationId, password = "", nickname = nickname, phoneNumber = phone) | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.sopt.now.domain.entity.request | ||
|
||
import com.sopt.now.data.dto.request.RequestLoginDto | ||
import com.sopt.now.data.dto.request.RequestSignUpDto | ||
import com.sopt.now.data.model.User | ||
|
||
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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. ๋ต ๊ฐ์ฌํฉ๋๋ค. ์๊ทธ๋๋ ์ฝ๋ ์ง๋ฉด์ ๋ญ๊ฐ ์๋ชป๋์๋ค๋ ์๊ฐ์ด ๋ค์ด์ ๊ณ ๋ฏผ๋ง์ด ํ์๋๋ฐ ๋๋ถ์ ๊ธธ์ ์ฐพ์ ์ ์์์ด์ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.sopt.now.domain.repository | ||
|
||
import com.sopt.now.data.dto.response.BaseResponse | ||
import com.sopt.now.domain.entity.request.AuthRequestModel | ||
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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. ๊ฐ์ฌํฉ๋๋ค ๋ญ๊ฐ.. ๊ฐ์๊ธฐ ํท๊ฐ๋ ธ์ด์.. |
||
suspend fun signUp(authData: AuthRequestModel): Result<Response<BaseResponse<Unit>>> | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.sopt.now.domain.usecase | ||
|
||
import com.sopt.now.data.dto.request.RequestLoginDto | ||
import com.sopt.now.data.model.User | ||
import com.sopt.now.domain.entity.request.AuthRequestModel | ||
import com.sopt.now.domain.repository.AuthRepository | ||
import com.sopt.now.util.UiState | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
import org.json.JSONObject | ||
import retrofit2.HttpException | ||
|
||
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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. ๋ต ๊ทธ๋ฐ๋ฐ usecase์์ ์ด๋ ๊ฒ ์ฐ๋ฉด์๋ผ์! domain ์์ญ์ ์๋ฒํต์ ์ด๋ ์ฌ๋ฌ ๊ณผ์ ์ด ๋ค์ด๊ฐ๊ฒ ๋์ด์ ์ ๋ชป ์ง ์ฝ๋์ ๋๋ค! |
||
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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. ์๋์์ ใ ใ ๋ถ๋ฆฌ๋ํ๋๋ฐ ๋๋ฌด ์๋ชปํด์.. ๋ฐ๋ ์ฝ๋์ฒ๋ผ ํด์ผํ๋๊ฑธ๋ก ์๊ณ ์์ด์ |
||
} else { | ||
val errorMessage = | ||
JSONObject(response.errorBody()?.string()).getString(MESSAGE) | ||
UiState.Error(errorMessage.toString()) | ||
} | ||
}, | ||
onFailure = { e -> | ||
if (e is HttpException) { | ||
UiState.Error(e.message()) | ||
} else { | ||
UiState.Error(e.message.toString()) | ||
} | ||
} | ||
) | ||
} catch (e: Exception) { | ||
UiState.Error(e.message.toString()) | ||
} | ||
} | ||
} | ||
|
||
companion object { | ||
const val MESSAGE = "message" | ||
const val LOCATION = "location" | ||
} | ||
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. private๋ฅผ ๋ฐ๋ก ๋ถ์ด์์ง ์์ผ์ จ๋๋ฐ ๋ค๋ฅธ ๊ณณ์์ ์ฌ์ฉํ๋ ๊ฒ ์ผ๊น์? 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. ์์ต๋๋ค private ๋ถ์ด๋๊ฑธ ๊น๋จน์๋ค์ ๊ฐ์ฌํฉ๋๋ค. |
||
} |
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. ์ผ๋จ ์ด ๋ก์ง์ data์์ญ์ ์์ด์ผ ํ๋ ๋ก์ง์
๋๋ค! domain์ usecase๋ ์ด๋ฌํ interface๋ฅผ ์ฐธ์กฐํ์ฌ ํน์ ๋น์ฆ๋์ค ๋ก์ง์ ์บก์ํ ํฉ๋๋ค. ์ง๊ธ data ๋ ์ด์ด์ ๋ถ๋ฆฌ๊ฐ ๋ชฉ์ ์ธ์ง ํน์ ํด๋ฆฐ์ํคํ ์ณ์์ ๊ตฌ์กฐ๊ฐ ๋ชฉ์ ์ธ์ง ํ์คํ๊ฒ ์ ํ๊ณ ๋ค์ ๋ฆฌํฉํ ๋ง ํด๋ณด๋ฉด ์ข์๊ฒ ๊ฐ์์!! 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. ์ ๋ง ๊ฐ์ฌํฉ๋๋ค |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.sopt.now.domain.usecase | ||
|
||
import com.sopt.now.data.model.User | ||
import com.sopt.now.domain.entity.request.AuthRequestModel | ||
import com.sopt.now.domain.repository.AuthRepository | ||
import com.sopt.now.util.UiState | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
import org.json.JSONObject | ||
import retrofit2.HttpException | ||
|
||
class SignUpUseCase(private val authRepository: AuthRepository) { | ||
suspend fun execute(request: AuthRequestModel): UiState<User> { | ||
return withContext(Dispatchers.IO) { | ||
try { | ||
val result = authRepository.signUp(request) | ||
result.fold( | ||
onSuccess = { response -> | ||
if (response.isSuccessful) { | ||
UiState.Success(request.toUserWithUserId(response.headers()[LOCATION].toString())) | ||
} else { | ||
val errorMessage = | ||
JSONObject(response.errorBody()?.string()).getString(MESSAGE) | ||
UiState.Error(errorMessage.toString()) | ||
} | ||
}, | ||
onFailure = { e -> | ||
if (e is HttpException) { | ||
UiState.Error(e.message()) | ||
} else { | ||
UiState.Error(e.message.toString()) | ||
} | ||
} | ||
) | ||
} catch (e: Exception) { | ||
UiState.Error(e.message.toString()) | ||
} | ||
} | ||
} | ||
|
||
companion object { | ||
const val MESSAGE = "message" | ||
const val LOCATION = "location" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,8 +7,8 @@ import androidx.activity.result.contract.ActivityResultContracts | |
import androidx.activity.viewModels | ||
import com.sopt.now.R | ||
import com.sopt.now.data.model.User | ||
import com.sopt.now.data.datasouce.request.RequestLoginDto | ||
import com.sopt.now.databinding.ActivityLoginBinding | ||
import com.sopt.now.domain.entity.request.AuthRequestModel | ||
import com.sopt.now.ui.main.MainActivity | ||
import com.sopt.now.ui.signup.SignUpActivity | ||
import com.sopt.now.util.BindingActivity | ||
|
@@ -18,7 +18,7 @@ import com.sopt.now.util.toast | |
|
||
class LoginActivity : BindingActivity<ActivityLoginBinding>(R.layout.activity_login) { | ||
private lateinit var resultLauncher: ActivityResultLauncher<Intent> | ||
private val viewModel by viewModels<LoginViewModel>() | ||
private val viewModel: LoginViewModel by viewModels { LoginViewModelFactory() } | ||
private lateinit var user: User | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
|
@@ -79,14 +79,16 @@ class LoginActivity : BindingActivity<ActivityLoginBinding>(R.layout.activity_lo | |
|
||
private fun initLoginBtnClickListener() { | ||
binding.btnLogin.setOnClickListener { | ||
viewModel.login(getLoginRequestDto()) | ||
viewModel.login(getLoginRequest()) | ||
} | ||
} | ||
|
||
private fun getLoginRequestDto() = | ||
RequestLoginDto( | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. ๋ฐ์ดํฐ ๋ฐ์ธ๋ฉ์ ์ฌ์ฉํ๋ฉด ์ด ๊ท์ฐฎ์ ๊ณผ์ ์ ํํผํ ์๋ ์์ต๋๋ค! |
||
|
||
companion object { | ||
|
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.
์ฐธ์ ํ ์ ๊ทผ์ธ ๊ฒ ๊ฐ์์ ์ด๋ฐ ๋ณธ์ธ๋ง์ ์ ๊ทผ๋ ์ข๋ค๊ณ ์๊ฐํฉ๋๋ค