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/#7 week4 #8

Open
wants to merge 22 commits into
base: develop
Choose a base branch
from
Open

Feat/#7 week4 #8

wants to merge 22 commits into from

Conversation

hyoeunjoo
Copy link
Collaborator

Related issue ๐Ÿ› 

Work Description โœ๏ธ

  • ์„œ๋ฒ„ํ†ต์‹  ๊ตฌํ˜„

Screenshot ๐Ÿ“ธ

4.mp4

Uncompleted Tasks ๐Ÿ˜…

  • ์ŠคํŠธ๋ง์ถ”์ถœ

To Reviewers ๐Ÿ“ข

์Œ.. ๋” ์ข‹์€ ์ฝ”๋“œ๊ฐ€ ๋ถ„๋ช… ์žˆ์„ ๊ฒƒ ๊ฐ™์€๋ฐ.. ์ข‹์€ ๋กœ์ง์œผ๋กœ ์ฝ”๋“œ๋ฅผ ์งฐ๋Š”์ง€ ์ž˜ ๋ชจ๋ฅด๊ฒ ์Šต๋‹ˆ๋‹คใ… ใ…  ๊ทธ๋ƒฅ ๋งˆ๊ตฌ ๋•Œ๋ ค์ฃผ์‹œ๋ฉด ๊ฐ์‚ฌํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค ์„œ๋ฒ„ํ†ต์‹  ์ž˜ํ•˜๊ณ ์‹œํผ์š”

๋‹ค๋“ค ํ•ฉ์„ธ ํ™”์ดํŒ…!

Copy link

@imtaejugkim imtaejugkim left a comment

Choose a reason for hiding this comment

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

ํ†ต์‚ฐ ์˜ˆ์™ธ์— ์‚ฌ์†Œํ•œ ๊ฒƒ๋„ ์ฒ˜๋ฆฌํ•˜์‹  ๊ณผ์ •์„ ์ž˜ ๋ณผ ์ˆ˜ ์žˆ๋Š” ์ฝ”๋“œ์˜€์Šต๋‹ˆ๋‹ค..!
hilt ์— ๋Œ€ํ•ด ๋ช…ํ™•ํ•œ ์ง€์‹์ด ์—†๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ๋Š”๋ฐ, ํšจ์€๋‹˜ ์ฝ”๋“œ ๋ณด๊ณ  ๋งŽ์ด ๋ฐฐ์šธ ์ˆ˜ ์žˆ๋Š” ๊ธฐํšŒ์˜€์Šต๋‹ˆ๋‹ค. ๊ฐ ๋ ˆ์ด์–ด์— ๋ช…์‹œํ•œ ๋ถ€๋ถ„๋“ค ๋‹ค์‹œ ํ•œ๋ฒˆ ์ฐธ๊ณ ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค!

Comment on lines +48 to +54
hilt-core = { group = "com.google.dagger", name = "hilt-core", version.ref = "hilt" }
hilt-compiler = { group = "com.google.dagger", name = "hilt-compiler", version.ref = "hilt" }
hilt-android = { group = "com.google.dagger", name = "hilt-android", version.ref = "hilt" }
hilt-android-testing = { group = "com.google.dagger", name = "hilt-android-testing", version.ref = "hilt" }
hilt-android-compiler = { group = "com.google.dagger", name = "hilt-android-compiler", version.ref = "hilt" }
hilt-navigation-compose = { group = "androidx.hilt", name = "hilt-navigation-compose", version.ref = "hiltNavigationCompose" }
hilt-manager = {group = "androidx.hilt" , name = "hilt-compiler", version.ref = "hiltManager"}

Choose a reason for hiding this comment

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

hilt ์ฃผ์ž…์„ ์‚ฌ์šฉํ•˜์…จ๋„ค์š”! ์ €๋Š” ์ด๋ฒˆ ๊ณผ์ œ์—์„œ ์‚ฌ์šฉํ•ด๋ณด๋ ค๋‹ค๊ฐ€, ๋ช…ํ™•ํ•œ ์ง€์‹์ด ์•„๋‹Œ ๊ฒƒ ๊ฐ™์•„ ๋ฆฌํŒฉํ† ๋ง ๊ฐ„ ์ง„ํ–‰ํ•ด๋ณด๋Š” ๊ฒƒ์œผ๋กœ ํ•˜์˜€์Šต๋‹ˆ๋‹ค..! ํšจ์€๋‹˜ ์ฝ”๋“œ๋ณด๊ณ  ํ•˜๋‚˜ํ•˜๋‚˜ ์ดํ•ดํ•ด๋ณด๋„๋ก ํ• ๊ฒŒ์š”!

Comment on lines +6 to +22
@Serializable
data class BaseResponse<T>(
@SerialName("result")
val result: T? = null,
@SerialName("code")
val code: String? = null,
@SerialName("error")
val error: BaseError? = null,
) {
@Serializable
data class BaseError(
@SerialName("code")
val code: Int,
@SerialName("message")
val message: String,
)
}

Choose a reason for hiding this comment

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

๊ณตํ†ต๋˜๋Š” response๋ฅผ BaseResponse๋กœ ๋‘๊ณ , T๋ฅผ ์‚ฌ์šฉํ•ด์„œ ํ•ด๋‹น ํ•„๋“œ์— ๋ฐ›๋Š” result ๊ฐ’์„ ์ •์˜ํ•œ ๊ฒƒ ์ด๊ตฐ์š”! ์ฐธ๊ณ ํ•˜๊ฒ ์Šต๋‹ˆ๋‹น

Comment on lines +9 to +12
fun LoginInfo.toRequestLogin(): RequestLoginDto = RequestLoginDto(
userName = this.userName,
password = this.password
)

Choose a reason for hiding this comment

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

์ €์˜ domain์— ๋Œ€ํ•œ ์ง€์‹์ด ๋ช…ํ™•ํ•˜์ง€ ์•Š์•˜๋Š”๋ฐ, ์ด ์ฝ”๋“œ์ฒ˜๋Ÿผ ์„œ๋ฒ„์—์„œ ๋ฐ›์€ ๋ฐ์ดํ„ฐ๋ฅผ ํด๋ผ์ด์–ธํŠธ์—์„œ ๋งž๋Š” ๋ฐ์ดํ„ฐ (์˜ˆ๋ฅผ ๋“ค๋ฉด ๋ฐ์ดํ„ฐ ํด๋ž˜์Šค๋กœ ์ •์˜)๋กœ ๊ฐ€๊ณตํ•ด์ฃผ๋Š” ์—ญํ• ์ด๋ผ๊ณ  ์ƒ๊ฐํ•˜๋ฉด ๋ ๊นŒ์š”?

Comment on lines +14 to +16
fun ResponseLoginDto.toResponseLoginModel(): ResponseLoginModel = ResponseLoginModel(
token = this.token
)

Choose a reason for hiding this comment

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

viewModel์—์„œ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐˆ์•„ ๋ผ์šฐ๋Š” ๋ฐฉ๋ฒ•๋„ ์žˆ๊ตฐ์š”..! State๊ฐ™์€ ๊ฒƒ์„ ์‚ฌ์šฉํ•˜๋ฉด ๋ฐ”๋กœ ๋ณ€๊ฒฝ์ด ๋˜๊ฒ ๋„ค์š”!

Comment on lines +3 to +19
sealed class Error(message: String?) : Exception(message) {
data class ApiError(
val errorMessage: String?,
) : Error(errorMessage)

data class NetWorkConnectError(
val errorMessage: String,
) : Error(errorMessage)

data class TimeOutError(
val errorMessage: String,
) : Error(errorMessage)

data class UnknownError(
val errorMessage: String,
) : Error(errorMessage)
}

Choose a reason for hiding this comment

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

๊ฐ ์—๋Ÿฌ ์ •๋ฆฌ์— ์ •์„ฑ์ด ๋ณด์ž…๋‹ˆ๋‹ค..1

Copy link

Choose a reason for hiding this comment

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

์ง„์งœ ์ •์„ฑ ๊ตฟ๊ตฟ....๐Ÿ‘๐Ÿป๐Ÿ‘๐Ÿป๐Ÿ‘๐Ÿป

Comment on lines +10 to +37
private const val UNKNOWN_ERROR_MESSAGE = "Unknown error"
private const val NETWORK_CONNECT_ERROR_MESSAGE = "๋„คํŠธ์›Œํฌ ์—ฐ๊ฒฐ์ด ์›ํ™œํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค"
private const val INTERNET_CONNECTION_ERROR_MESSAGE = "์ธํ„ฐ๋„ท์— ์—ฐ๊ฒฐํ•ด ์ฃผ์„ธ์š”"
private const val TIMEOUT_ERROR_MESSAGE = "์„œ๋ฒ„๊ฐ€ ์‘๋‹ตํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค"
private const val NULL_ERROR_MESSAGE = "error message is null"

private fun HttpException.getErrorMessage(): String {
val errorBody = response()?.errorBody()?.string() ?: return UNKNOWN_ERROR_MESSAGE
return parseErrorMessage(errorBody)
}

private fun parseErrorMessage(errorBody: String): String =
try {
val errorResponse = Json.decodeFromString<BaseResponse<BaseResponse.BaseError>>(errorBody)
errorResponse.error?.message ?: NULL_ERROR_MESSAGE
} catch (e: Exception) {
UNKNOWN_ERROR_MESSAGE
}

fun Throwable.toCustomError(): Throwable = when (this) {
is HttpException -> Error.ApiError(this.getErrorMessage())
is UnknownHostException -> Error.NetWorkConnectError(NETWORK_CONNECT_ERROR_MESSAGE)
is ConnectException -> Error.NetWorkConnectError(INTERNET_CONNECTION_ERROR_MESSAGE)
is SocketTimeoutException -> Error.TimeOutError(TIMEOUT_ERROR_MESSAGE)
else -> Error.UnknownError(this.message ?: UNKNOWN_ERROR_MESSAGE)
}

fun <T> Throwable.handleThrowable(): Result<T> = Result.failure(this.toCustomError())

Choose a reason for hiding this comment

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

api ๋ช…์„ธ์— ๋ช…์‹œ๋œ ์˜ค๋ฅ˜ ๋ฟ ์•„๋‹ˆ๋ผ ํด๋ผ์ด์–ธํŠธ์™€ ๊ทธ ์™ธ ๋ฐœ์ƒํ•˜๋Š” ์˜ค๋ฅ˜์— ๋Œ€ํ•œ ์ •์˜๋ฅผ ์ด๋ ‡๊ฒŒ ํ•  ์ˆ˜๋„ ์žˆ๊ตฐ์š”

Copy link

@sayyyho sayyyho left a comment

Choose a reason for hiding this comment

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

4์ฃผ์ฐจ ๊ณผ์ œ ์ˆ˜ํ–‰ํ•˜๋Š๋ผ ๊ณ ์ƒ ๋งŽ์œผ์…จ์Šต๋‹ˆ๋‹ค!! ๋งค์ฃผ ์ฝ”๋ฆฌ์กฐ์žฅ๋‹˜ ์ฝ”๋“œ ๋ฆฌ๋ทฐํ•˜๋ฉด์„œ ๋งŽ์ด ๋ฐฐ์›Œ๊ฐˆ ์ˆ˜ ์žˆ์–ด์„œ ์œ ์ตํ•ฉ๋‹ˆ๋‹ค. ํ•ฉ์„ธ๋„ ํ™”์ดํŒ…์ž…๋‹ˆ๋‹ค!!

Comment on lines +1 to +31
package org.sopt.and

sealed interface UiState<out T> {
data object Empty : UiState<Nothing>

data object Loading : UiState<Nothing>

data class Success<T>(
val data: T,
) : UiState<T>

data class Failure(
val errorMessage: String,
) : UiState<Nothing>

fun getUiStateModel(): UiStateModel {
return UiStateModel(
this is Empty,
this is Loading,
this is Success,
this is Failure,
)
}
}

data class UiStateModel(
val isEmpty: Boolean = false,
val isLoading: Boolean = true,
val isSuccess: Boolean = false,
val isFailure: Boolean = false,
)
Copy link

Choose a reason for hiding this comment

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

์ด๋ ‡๊ฒŒ UI State๋ฅผ ๊ด€๋ฆฌํ•˜๋‹ˆ ์ •๋ง ์ดํ•ด๋„ ์‰ฝ๊ณ  ์œ ์šฉํ•˜๋„ค์š”

Comment on lines +1 to +10
package org.sopt.and.data.dto.response

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class ResponseLoginDto(
@SerialName("token")
val token: String
)
Copy link

Choose a reason for hiding this comment

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

์ด๋Ÿฐ ์‹์œผ๋กœ ํ† ํฐ๋„ Serializableํ•˜๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ๊ตฌ์กฐํ™”ํ•˜๋ฉด, ๋‹ค๋ฅธ ์ธ์ฆ ๊ด€๋ จ ๋ฐ์ดํ„ฐ์™€ ํ•จ๊ป˜ ํ™•์žฅ ๊ฐ€๋Šฅ์„ฑ์ด ์ƒ๊ธฐ๊ฒ ๊ตฐ์š”.

Comment on lines +1 to +14
package org.sopt.and.data.service

import org.sopt.and.data.dto.BaseResponse
import org.sopt.and.data.dto.response.ResponseMyHobbyDto
import retrofit2.Call
import retrofit2.http.GET
import retrofit2.http.Header

interface MyPageService {
@GET("/user/my-hobby")
suspend fun getMyHobby(
@Header("token") token: String
): BaseResponse<ResponseMyHobbyDto>
}
Copy link

Choose a reason for hiding this comment

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

suspend fun์„ ์ฒ˜์Œ๋ณด๋Š”๋ฐ, ๋” ์ง๊ด€์ ์œผ๋กœ ์ž‘์„ฑ๋ผ์„œ ์ข‹์€ ๊ฑฐ ๊ฐ™์Šต๋‹ˆ๋‹ค!!

Comment on lines +3 to +19
sealed class Error(message: String?) : Exception(message) {
data class ApiError(
val errorMessage: String?,
) : Error(errorMessage)

data class NetWorkConnectError(
val errorMessage: String,
) : Error(errorMessage)

data class TimeOutError(
val errorMessage: String,
) : Error(errorMessage)

data class UnknownError(
val errorMessage: String,
) : Error(errorMessage)
}
Copy link

Choose a reason for hiding this comment

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

์ง„์งœ ์ •์„ฑ ๊ตฟ๊ตฟ....๐Ÿ‘๐Ÿป๐Ÿ‘๐Ÿป๐Ÿ‘๐Ÿป

Comment on lines +40 to +49
fun submitLogin(userInfo: LoginInfo) {
viewModelScope.launch {
loginRepository.postLogin(userInfo)
.onSuccess { response ->
_loginState.emit(UiState.Success(response))
_authToken.emit(response.token)
}
.onFailure { exception ->
_loginState.emit(UiState.Failure("๋กœ๊ทธ์ธ ์‹คํŒจ"))
}
Copy link

Choose a reason for hiding this comment

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

์ฝ”๋“œ๋ฆฌ๋ทฐ ํ•˜๋ฉด์„œ emit๋„ ๊ณต๋ถ€ํ•˜๊ฒŒ ๋˜๋„ค์š”! ๋•๋ถ„์— ๋ฐฐ์›Œ๊ฐ‘๋‹ˆ๋‹ค!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEAT] 4์ฃผ์ฐจ ๊ณผ์ œ ๊ตฌํ˜„
3 participants