Skip to content
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

Open
wants to merge 33 commits into
base: develop-xml
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
c3591ce
[mod] #18 SignUpViewModel ์˜ˆ์™ธ์ฒ˜๋ฆฌ ๋ณ€๊ฒฝ
cacaocoffee Jun 3, 2024
7e3a2b4
[mod] #18 api login ๋ณ€๊ฒฝ
cacaocoffee Jun 3, 2024
e9bb79d
[mod] #18 api getUsrInfo ๋ณ€๊ฒฝ
cacaocoffee Jun 4, 2024
ae881b6
[mod] #18 datasource -> dto ๋กœ ๋ณ€๊ฒฝ
cacaocoffee Jun 4, 2024
23151c3
[chore] #18 ์ฝ”๋“œ์ •๋ฆฌ
cacaocoffee Jun 4, 2024
b41a135
[add] #18 repository ์ƒ์„ฑ
cacaocoffee Jun 4, 2024
f1ad914
[add] #18 LoginViewModelFactory ์ถ”๊ฐ€
cacaocoffee Jun 5, 2024
8339904
[mod] #18 Login ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋กœ ๋กœ์ง ๋ณ€๊ฒฝ
cacaocoffee Jun 5, 2024
ad8381d
[mod] #18 signup repository ํŒจํ„ด์ ์šฉ
cacaocoffee Jun 7, 2024
4784add
[mod] #18 signup usecase ๋ถ„๋ฆฌ
cacaocoffee Jun 7, 2024
adb8543
[mod] #18 login usecase ๋ถ„๋ฆฌ
cacaocoffee Jun 7, 2024
6029ae8
[chore] #18 data <-domain ์˜์กด์„ฑ ๋ถ„๋ฆฌ๋ฅผ ์œ„ํ•ด dto์™€ ๋กœ์ง๋ณ€๊ฒฝ
cacaocoffee Jun 7, 2024
2cc557b
[chore] #18 data <-domain ์˜์กด์„ฑ ๋ถ„๋ฆฌ๋ฅผ ์œ„ํ•ด dto์™€ ๋กœ์ง๋ณ€๊ฒฝ
cacaocoffee Jun 7, 2024
1c197b0
Merge remote-tracking branch 'origin/feat/week-xml-07' into feat/weekโ€ฆ
cacaocoffee Jun 7, 2024
3e6e6ba
[mod] #18 usecase ๋ณ€๊ฒฝ
cacaocoffee Jun 12, 2024
d752e67
[mod] #18 mapper ์ถ”๊ฐ€ ์˜์กด์„ฑ๋ณ€๊ฒฝ
cacaocoffee Jun 12, 2024
05219f1
[Chore] #18 user ํด๋” Ui๋กœ ๋ณ€๊ฒฝ
cacaocoffee Jun 12, 2024
29a96db
[Chore] #18 ViewModelFactory ํ•˜๋‚˜๋กœ ํ†ตํ•ฉ
cacaocoffee Jun 12, 2024
381ecab
[Mod] #18 AuthService ์ˆ˜์ •
cacaocoffee Jun 14, 2024
f639c9a
[Add] #18 getErrorMessage,ApiError ,BaseResponseEntity ์ถ”๊ฐ€
cacaocoffee Jun 14, 2024
06dbdef
[Mod] #18 ์ฝ”๋“œ๋ฆฌ๋ทฐ๋ฐ˜์˜
cacaocoffee Jun 14, 2024
f4bb9c1
[Mod] #18 AuthRequestModel ->UserEntity ์ด๋ฆ„๋ณ€๊ฒฝ
cacaocoffee Jun 14, 2024
32a8c17
[Feat] #18 getinfo domain๊ณผ data ์˜์—ญ ์ถ”๊ฐ€ ๋ฐ ์ˆ˜์ •
cacaocoffee Jun 14, 2024
d91ec8a
[Feat] #18 getinfo repository ํŒจํ„ด ์ ์šฉ
cacaocoffee Jun 14, 2024
94ace2d
[Chore] #18 ์ฝ”๋“œ ์ •๋ฆฌ
cacaocoffee Jun 14, 2024
46038a3
[Chore] #18 ์ฝ”๋“œ ๋ฆฌ๋ทฐ ๋ฐ˜์˜ viewmodel ํƒ€์ž…๋ช…์‹œ
cacaocoffee Jun 14, 2024
a2f41df
[Add] #18 hilt gradle ์ถ”๊ฐ€
cacaocoffee Jun 18, 2024
60b29dc
[Add] #18 HiltAndroidApp ์ ์šฉ app ์ถ”๊ฐ€
cacaocoffee Jun 19, 2024
0c69554
[Add] #18 Api, DataModule ์ถ”๊ฐ€
cacaocoffee Jun 19, 2024
b374cf0
[Mod] #18 hilt ์ ์šฉ
cacaocoffee Jun 19, 2024
df0c370
[Del] #18 hilt ์ ์šฉ ํ›„ ์•ˆ์“ฐ๋Š” ํŒŒ์ผ ์ œ๊ฑฐ
cacaocoffee Jun 19, 2024
e2a65aa
[Mod] #18 ApiModule ์œ„์น˜ ๋ณ€๊ฒฝ
cacaocoffee Jun 19, 2024
256d629
[Mod] #18 kapt -> ksp
cacaocoffee Jun 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions app/src/main/java/com/sopt/now/data/AuthRepositoryImpl.kt
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())
}
}
13 changes: 5 additions & 8 deletions app/src/main/java/com/sopt/now/data/api/AuthService.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package com.sopt.now.data.api

import com.sopt.now.data.datasouce.request.RequestLoginDto
import com.sopt.now.data.datasouce.request.RequestSignUpDto
import com.sopt.now.data.datasouce.response.BaseResponse
import com.sopt.now.data.datasouce.response.ResponseLoginDto
import com.sopt.now.data.datasouce.response.ResponseSignUpDto
import retrofit2.Call
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 retrofit2.Response
import retrofit2.http.Body
import retrofit2.http.POST
Expand All @@ -18,7 +15,7 @@ interface AuthService {


@POST("member/login")
fun login(
suspend fun login(
@Body request: RequestLoginDto,
): Call<BaseResponse<Unit>>
): Response<BaseResponse<Unit>>
}
8 changes: 4 additions & 4 deletions app/src/main/java/com/sopt/now/data/api/InfoService.kt
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
@@ -1,4 +1,4 @@
package com.sopt.now.data.datasouce.request
package com.sopt.now.data.dto.request

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.sopt.now.data.datasouce.request
package com.sopt.now.data.dto.request

import com.sopt.now.data.model.User
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

Expand All @@ -14,7 +13,4 @@ data class RequestSignUpDto(
val nickname: String,
@SerialName("phone")
val phone: String,
) {
fun toUserWithUserId(userid: String): User =
User(id = authenticationId, password = password, nickname = nickname, phoneNumber = phone, userId = userid)
}
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.sopt.now.data.datasouce.response
package com.sopt.now.data.dto.response

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
Expand Down
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
)
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AuthRequestModel๋ฅผ ์“ฐ์‹œ๊ฒŒ๋œ ์ด์œ ๊ฐ€ ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data ์˜์—ญ์—์„œ ui ์— ์‚ฌ์šฉํ•˜๊ธฐ์— ์ค‘๊ฐ„๋‹ค๋ฆฌ๋กœ ์ƒ๊ฐํ•˜๊ณ  ์ถ”๊ฐ€ํ–ˆ์Šต๋‹ˆ๋‹ค.
์ € ๋‹น์‹œ์— ์˜์กด๊ด€๊ณ„๊ฐ€ ํ—ท๊ฐˆ๋ ค ๋„ˆ๋ฌด ์ž˜๋ชป์งœ๊ณ  ๋„ฃ์—ˆ๋„ค์š”.. ์žฌ์›๋‹˜ ๋ฆฌ๋ทฐ ๋•๋ถ„์— ์™œ ์‚ฌ์šฉํ•˜๋Š”๊ฐ€์— ๋Œ€ํ•œ ๋ณธ์งˆ์ ์ธ ๊ณ ๋ฏผ์„ ํ•™ ์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค ๊ฐ์‚ฌํ•ด์š”

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ฐธ์‹ ํ•œ ์ ‘๊ทผ์ธ ๊ฒƒ ๊ฐ™์•„์š” ์ด๋Ÿฐ ๋ณธ์ธ๋งŒ์˜ ์ ‘๊ทผ๋„ ์ข‹๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

domain์—์„œ dto๋ฅผ ์ฐธ์กฐํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹Œ data์—์„œ dto๋ฅผ ์ฐธ์กฐํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋„ต ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค. ์•ˆ๊ทธ๋ž˜๋„ ์ฝ”๋“œ ์งœ๋ฉด์„œ ๋ญ”๊ฐ€ ์ž˜๋ชป๋˜์—ˆ๋‹ค๋Š” ์ƒ๊ฐ์ด ๋“ค์–ด์„œ ๊ณ ๋ฏผ๋งŽ์ด ํ–ˆ์—ˆ๋Š”๋ฐ ๋•๋ถ„์— ๊ธธ์„ ์ฐพ์„ ์ˆ˜ ์žˆ์—ˆ์–ด์š”

10 changes: 10 additions & 0 deletions app/src/main/java/com/sopt/now/domain/repository/AuthRepository.kt
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>>>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

login์€ ํ†ต์ƒ์ ์œผ๋กœ ํ•œ๋‹จ์–ด๋กœ ์ธ์‹ํ•ฉ๋‹ˆ๋‹ค!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค ๋ญ”๊ฐ€.. ๊ฐ‘์ž๊ธฐ ํ—ท๊ฐˆ๋ ธ์–ด์š”..

suspend fun signUp(authData: AuthRequestModel): Result<Response<BaseResponse<Unit>>>
}
54 changes: 54 additions & 0 deletions app/src/main/java/com/sopt/now/domain/usecase/LogInUseCase.kt
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

withContext๋กœ๋„ ์ฝ”๋ฃจํ‹ด์„ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๊ตฐ์š”! ์•Œ์•„๊ฐ€์š”!!

Copy link
Member Author

Choose a reason for hiding this comment

The 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()
)
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์•„.. UseCase ๋ถ„๋ฆฌ.. ์žŠ๊ณ  ์žˆ์—ˆ๋Š”๋ฐ!!!
๋ฉ‹์ ธ์š”.. ๊ฐ€๋…์„ฑ์ด ํ›จ ์ข‹๋„ค์š”

Copy link
Member Author

Choose a reason for hiding this comment

The 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"
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private๋ฅผ ๋”ฐ๋กœ ๋ถ™์ด์‹œ์ง€ ์•Š์œผ์…จ๋Š”๋ฐ ๋‹ค๋ฅธ ๊ณณ์—์„œ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ ์ผ๊นŒ์š”?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์—†์Šต๋‹ˆ๋‹ค private ๋ถ™์ด๋Š”๊ฑธ ๊นŒ๋จน์—ˆ๋„ค์š” ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.

}
45 changes: 45 additions & 0 deletions app/src/main/java/com/sopt/now/domain/usecase/SignUpUseCase.kt
Copy link

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 ๋ ˆ์ด์–ด์˜ ๋ถ„๋ฆฌ๊ฐ€ ๋ชฉ์ ์ธ์ง€ ํ˜น์€ ํด๋ฆฐ์•„ํ‚คํ…์ณ์‹์˜ ๊ตฌ์กฐ๊ฐ€ ๋ชฉ์ ์ธ์ง€ ํ™•์‹คํ•˜๊ฒŒ ์ •ํ•˜๊ณ  ๋‹ค์‹œ ๋ฆฌํŒฉํ† ๋ง ํ•ด๋ณด๋ฉด ์ข‹์„๊ฒƒ ๊ฐ™์•„์š”!!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ •๋ง ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค
ํด๋ฆฐ์•„ํ‚คํ…์ฒ˜๋ฅผ ์ ์šฉํ•ด๋ณด์ž! ๋ผ๊ณ  ํ•˜๊ธดํ–ˆ๋Š”๋ฐ ๋ง‰์ƒ ํ•˜๋ฉด์„œ ์ด์ƒํ•œ๊ฑฐ ๊ฐ™๋”๋ผ๊ตฌ์š”...
์ œ๊ฐ€ ํ•˜๋Š” ๋ฐฉ๋ฉด์ด ๋งž๋‚˜ ์‹ถ๊ธฐ๋„ ํ–ˆ์—ˆ๋Š”๋ฐ ๋•๋ถ„์— ์˜๋ฌธ์ ์„ ๋งŽ์ด ํ•ด๊ฒฐํ•˜๊ณ  ์ž‘์—…ํ•  ์ˆ˜ ์žˆ์—ˆ์–ด์š”.
์ง€๊ธˆ ์ˆ˜์ •ํ•œ ๋ฐฉ์•ˆ์ด ์ •๋‹ต์ด ์•„๋‹ ์ˆ˜๋Š” ์žˆ๋”๋ผ๋„ ๋•๋ถ„์— ๋งŽ์€ ๊ฑธ ์•Œ๊ฒŒ ๋˜์—ˆ์–ด์š” ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.
์ดํ›„์— ์ž์„ธํ•œ ์„ค๋ช… ๋•๋ถ„์— ํ˜„์žฌ ๊ณต๋ถ€ํ•˜๊ณ  ์ ์šฉ์„ ํ•ด๋ดค์–ด์š” datasource ๋กœ ๋ถ„๋ฆฌํ•˜๊ณ  hilt ์ ์šฉ๋„ ๋…ธ๋ ฅํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค..

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"
}
}
14 changes: 8 additions & 6 deletions app/src/main/java/com/sopt/now/ui/login/LoginActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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?) {
Expand Down Expand Up @@ -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 = ""
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋ฐ์ดํ„ฐ ๋ฐ”์ธ๋”ฉ์„ ์‚ฌ์šฉํ•˜๋ฉด ์ด ๊ท€์ฐฎ์€ ๊ณผ์ •์„ ํšŒํ”ผํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค!


companion object {
Expand Down
Loading