-
Notifications
You must be signed in to change notification settings - Fork 0
π :: (#48)- User μλ²ν΅μ μ μν μΈν μ νμ΅λλ€ #50
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
Changes from 17 commits
b7380a1
c3e93b7
e472c3a
7b31216
916338a
a0b8d83
2b5e757
a2b4879
dd27058
b65c5af
3d0132e
24575b4
31dfe27
9754c92
49dc5e9
e720c22
163bd06
cde2a15
def4677
d93c9b9
95c9bd0
ca0302f
4879191
51069c8
8911cdf
796e680
cc2ae64
ff3cfd4
8691bca
14ecf7b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package remote.api.auth | ||
|
|
||
| import remote.dto.users.response.UsersResponse | ||
| import retrofit2.http.GET | ||
|
|
||
| interface UsersAPi { | ||
| @GET("/{user_id}/profile") | ||
| suspend fun getUsers(): List<UsersResponse> | ||
|
Comment on lines
+7
to
+8
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. API μλν¬μΈνΈμ λ°ν νμ μ λΆμΌμΉ
λͺ©μ μ λ°λΌ μλν¬μΈνΈ λλ ν¨μλͺ μ μμ ν΄μΌ ν©λλ€.
@GET("/{user_id}/profile")
-suspend fun getUsers(): List<UsersResponse>
+suspend fun getUserProfile(@Path("user_id") userId: String): UsersResponse
-@GET("/{user_id}/profile")
+@GET("/users/profiles")
suspend fun getUsers(): List<UsersResponse>
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package remote.datasource.users | ||
|
|
||
| import kotlinx.coroutines.flow.Flow | ||
| import remote.dto.users.response.UsersResponse | ||
|
|
||
| interface UsersDataSource { | ||
|
|
||
|
|
||
| fun getUsers(): Flow<List<UsersResponse>> | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package remote.datasource.users | ||
|
|
||
| import kotlinx.coroutines.flow.Flow | ||
| import remote.api.auth.UsersAPi | ||
| import remote.dto.users.response.UsersResponse | ||
| import util.performApiRequest | ||
| import javax.inject.Inject | ||
|
|
||
| class UsersDataSourceImpl @Inject constructor( | ||
| private val usersService: UsersAPi | ||
| ): UsersDataSource | ||
| { | ||
|
|
||
| override fun getUsers(): Flow<List<UsersResponse>> = | ||
| performApiRequest { usersService.getUsers() } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package remote.dto.users.response | ||
|
|
||
| import com.squareup.moshi.Json | ||
| import com.squareup.moshi.JsonClass | ||
| import model.myrank.response.MyRankResponseModel | ||
| import model.users.response.UsersResponseModel | ||
| import remote.dto.myrank.response.MyRankResponse | ||
| import java.util.UUID | ||
|
|
||
| @JsonClass(generateAdapter = true) | ||
| data class UsersResponse ( | ||
| @Json(name = "userId") val userId: UUID, | ||
| @Json(name = "clean-Point") val cleanPoint: Int, | ||
| @Json(name = "to-day-Clean") val todayClean: String, | ||
| @Json(name = "name") val name: String, | ||
| @Json(name = "penalty-Point") val penaltyPoint: Int, | ||
| @Json(name = "Mybecause") val Mybecause: String, | ||
|
||
| @Json(name = "because") val because: String, | ||
| @Json(name = "Point-List") val PointList: Int, | ||
|
|
||
| ) | ||
|
|
||
| fun UsersResponse.toModel() = UsersResponseModel( | ||
| userId = userId, | ||
| cleanPoint = cleanPoint, | ||
| todayClean = todayClean, | ||
| name = name, | ||
| penaltyPoint = penaltyPoint, | ||
| Mybecause = Mybecause, | ||
| because = because, | ||
| PointList = PointList | ||
|
|
||
| ) | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,18 @@ | ||||||||||||||||||||||||
| package repoistory | ||||||||||||||||||||||||
|
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. ν¨ν€μ§ μ΄λ¦ μ€νλ₯Ό μμ ν΄μ£ΌμΈμ
-package repoistory
+package repositoryπ Committable suggestion
Suggested change
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| import kotlinx.coroutines.flow.Flow | ||||||||||||||||||||||||
| import kotlinx.coroutines.flow.map | ||||||||||||||||||||||||
| import model.users.response.UsersResponseModel | ||||||||||||||||||||||||
| import remote.datasource.users.UsersDataSource | ||||||||||||||||||||||||
| import remote.dto.users.response.toModel | ||||||||||||||||||||||||
| import reopoistory.UsersRepository | ||||||||||||||||||||||||
| import javax.inject.Inject | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| class UsersRepositoryImpl @Inject constructor( | ||||||||||||||||||||||||
| private val usersDataSource: UsersDataSource | ||||||||||||||||||||||||
| ): UsersRepository { | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| override suspend fun getUsers(): Flow<List<UsersResponseModel>> { | ||||||||||||||||||||||||
| return usersDataSource.getUsers().map { list -> list.map { it.toModel() } } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
Comment on lines
+15
to
+17
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. π οΈ Refactor suggestion μλ¬ μ²λ¦¬ λ‘μ§ μΆκ°λ₯Ό κ³ λ €ν΄λ³΄μΈμ λ°μ΄ν° μμ€μμ λ°μν μ μλ μμΈ μν©μ λν μ²λ¦¬κ° νμν΄ λ³΄μ λλ€. override suspend fun getUsers(): Flow<List<UsersResponseModel>> {
- return usersDataSource.getUsers().map { list -> list.map { it.toModel() } }
+ return usersDataSource.getUsers()
+ .map { list -> list.map { it.toModel() } }
+ .catch { exception ->
+ // μ μ ν λ‘κΉ
μΆκ°
+ throw exception
+ }
}π Committable suggestion
Suggested change
|
||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,14 @@ | ||||||||||||||||||||||||||||||||||||||||||
| package model.users.response | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| import java.util.UUID | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| data class UsersResponseModel ( | ||||||||||||||||||||||||||||||||||||||||||
| val userId: UUID, | ||||||||||||||||||||||||||||||||||||||||||
| val cleanPoint: Int, | ||||||||||||||||||||||||||||||||||||||||||
| val todayClean: String, | ||||||||||||||||||||||||||||||||||||||||||
| val name: String, | ||||||||||||||||||||||||||||||||||||||||||
| val penaltyPoint: Int, | ||||||||||||||||||||||||||||||||||||||||||
| val Mybecause: String, | ||||||||||||||||||||||||||||||||||||||||||
| val because: String, | ||||||||||||||||||||||||||||||||||||||||||
| val PointList: Int, | ||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
5
to
14
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 class UsersResponseModel (
val userId: UUID,
- val cleanPoint: Int,
+ val cleanPoint: Int = 0,
val todayClean: String,
val name: String,
- val penaltyPoint: Int,
+ val penaltyPoint: Int = 0,
- val Mybecause: String,
+ val myReason: String,
- val because: String,
+ val penaltyReason: String,
- val PointList: Int,
+ val pointList: Int,
)π Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,9 @@ | ||||||
| package reopoistory | ||||||
|
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.
νμ¬ ν¨ν€μ§ λͺ
μ΄ λ€μκ³Ό κ°μ΄ μμ νμΈμ: -package reopoistory
+package repositoryπ Committable suggestion
Suggested change
|
||||||
|
|
||||||
| import kotlinx.coroutines.flow.Flow | ||||||
| import model.users.response.UsersResponseModel | ||||||
|
|
||||||
| interface UsersRepository { | ||||||
|
|
||||||
| suspend fun getUsers(): Flow<List<UsersResponseModel>> | ||||||
|
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. π οΈ Refactor suggestion
λ€μκ³Ό κ°μ΄ μμ νμΈμ: - suspend fun getUsers(): Flow<List<UsersResponseModel>>
+ fun getUsers(): Flow<List<UsersResponseModel>>π Committable suggestion
Suggested change
|
||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package usecase.Users | ||
|
|
||
| import kotlinx.coroutines.flow.Flow | ||
| import model.users.response.UsersResponseModel | ||
| import reopoistory.UsersRepository | ||
| import javax.inject.Inject | ||
|
|
||
| class GetUsersUseCase @Inject constructor( | ||
| private val usersRepository: UsersRepository | ||
| ){ | ||
| suspend operator fun invoke(): Flow<List<UsersResponseModel>> = | ||
| usersRepository.getUsers() | ||
| } | ||
|
Comment on lines
+11
to
+13
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. π οΈ Refactor suggestion μλ¬ μ²λ¦¬ λ‘μ§μ΄ νμν©λλ€. νμ¬ κ΅¬νμ κΈ°λ³Έμ μΈ λ°μ΄ν° νλ¦λ§ μ²λ¦¬νκ³ μμ΅λλ€. λ€μκ³Ό κ°μ μλ¬ μ²λ¦¬λ₯Ό μΆκ°νλ κ²μ΄ μ’κ² μ΅λλ€:
suspend operator fun invoke(): Flow<List<UsersResponseModel>> =
- usersRepository.getUsers()
+ try {
+ usersRepository.getUsers()
+ } catch (e: Exception) {
+ throw UserException("μ¬μ©μ μ 보λ₯Ό κ°μ Έμ€λλ° μ€ν¨νμ΅λλ€", e)
+ }
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| import java.io.FileInputStream | ||
| import java.util.Properties | ||
|
|
||
|
|
||
| plugins { | ||
| id(Dependency.Gradle.KOTLIN) | ||
|
|
@@ -13,15 +12,11 @@ android { | |
| compileSdk = ProjectProperties.Versions.COMPILE_SDK | ||
|
|
||
| defaultConfig { | ||
|
|
||
| minSdk = ProjectProperties.Versions.MIN_SDK | ||
| targetSdk = ProjectProperties.Versions.TARGET_SDK | ||
|
|
||
|
|
||
| testInstrumentationRunner = ProjectProperties.Test.TEST_RUNNER | ||
| vectorDrawables { | ||
| useSupportLibrary = true | ||
| } | ||
| consumerProguardFiles(ProjectProperties.Files.CONSUMER_PROGUARD_FILES) | ||
|
|
||
|
|
||
| } | ||
|
|
||
|
|
@@ -35,28 +30,24 @@ android { | |
| } | ||
| } | ||
| compileOptions { | ||
| sourceCompatibility = ProjectProperties.Versions.JAVA_VERSION | ||
| sourceCompatibility = ProjectProperties.Versions.JAVA_VERSION | ||
| targetCompatibility = ProjectProperties.Versions.JAVA_VERSION | ||
| } | ||
| kotlinOptions { | ||
| jvmTarget = ProjectProperties.Versions.JVM_TARGET | ||
| } | ||
| buildFeatures { | ||
| compose = true | ||
| buildConfig = true | ||
| } | ||
| composeOptions { | ||
| kotlinCompilerExtensionVersion = Versions.COMPOSE | ||
| } | ||
| packaging { | ||
| resources { | ||
| excludes += "/META-INF/{AL2.0,LGPL2.1}" | ||
| } | ||
| buildFeatures { | ||
| compose = true | ||
| buildConfig = true | ||
| } | ||
| } | ||
|
|
||
| dependencies { | ||
| implementation(project(":domain")) | ||
|
|
||
| implementation(Dependency.AndroidX.CORE_KTX) | ||
| implementation(Dependency.AndroidX.LIFECYCLE) | ||
| implementation(Dependency.AndroidX.SPLASH) | ||
|
|
@@ -71,6 +62,7 @@ dependencies { | |
| implementation(Dependency.Compose.COMPOSE_MATERIAL3) | ||
| implementation(Dependency.Compose.COMPOSE_MATERIAL) | ||
| implementation(Dependency.Compose.COMPOSE_NAVIGATION) | ||
| implementation(libs.lifecycle.viewmodel.android) | ||
|
||
| debugImplementation(Dependency.Compose.COMPOSE_TOOLING) | ||
|
|
||
| implementation(Dependency.Hilt.HILT) | ||
|
|
@@ -92,6 +84,5 @@ dependencies { | |
| implementation(Dependency.Google.SWIPE_REFRESH) | ||
|
|
||
| implementation(Dependency.Compose.COMPOSE_IMMUTABLELIST) | ||
|
|
||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,17 @@ | ||||||
| package Untill | ||||||
|
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. ν¨ν€μ§ μ΄λ¦ μ€νλ₯Ό μμ ν΄μ£ΌμΈμ
-package Untill
+package utilπ Committable suggestion
Suggested change
|
||||||
|
|
||||||
| import kotlinx.coroutines.flow.Flow | ||||||
| import kotlinx.coroutines.flow.catch | ||||||
| import kotlinx.coroutines.flow.map | ||||||
| import kotlinx.coroutines.flow.onStart | ||||||
|
|
||||||
| sealed interface Result<out T>{ | ||||||
| data class Success<out T>(val data: T) : Result<T> | ||||||
| data class Error(val exception: Throwable) : Result<Nothing> | ||||||
| object Loading : Result<Nothing> | ||||||
|
|
||||||
| } | ||||||
|
|
||||||
| fun <T> Flow<T>.asResult(): Flow<Result<T>> = map<T, Result<T>> { Result.Success(it) } | ||||||
| .onStart { emit(Result.Loading) } | ||||||
| .catch { emit(Result.Error(it)) } | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package viewModel.UIstate | ||
|
|
||
| import model.users.response.UsersResponseModel | ||
|
|
||
| sealed interface UsersUiState { | ||
| object Loading : UsersUiState | ||
| object Empty : UsersUiState | ||
| data class Success(val data: List<UsersResponseModel>) : UsersUiState | ||
| object Fail : UsersUiState | ||
| } |
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.
π οΈ Refactor suggestion
μν¬νΈ κ²½λ‘λ₯Ό νμ€νν΄μ£ΌμΈμ
μν¬νΈ λ¬Έμ΄ μΌκ΄μ± μμ΄ μμ±λμ΄ μμ΅λλ€. λͺ¨λ μν¬νΈλ₯Ό νλ‘μ νΈ λ£¨νΈλΆν° μμνλλ‘ μμ ν΄μ£ΌμΈμ.