From afb7302c065ea8ecf02e84437b7def909075356f Mon Sep 17 00:00:00 2001 From: yihwanggeun Date: Fri, 6 Dec 2024 19:22:40 +0900 Subject: [PATCH 01/18] =?UTF-8?q?#10=20[FIX]=20BaseResponse=20=EA=B5=AC?= =?UTF-8?q?=EC=A1=B0=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/org/sopt/and/core/data/dto/BaseResponse.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/sopt/and/core/data/dto/BaseResponse.kt b/app/src/main/java/org/sopt/and/core/data/dto/BaseResponse.kt index f25cf73..827ab3b 100644 --- a/app/src/main/java/org/sopt/and/core/data/dto/BaseResponse.kt +++ b/app/src/main/java/org/sopt/and/core/data/dto/BaseResponse.kt @@ -1,10 +1,10 @@ package org.sopt.and.core.data.dto +import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable data class BaseResponse ( - val status: Int, - val message: String, - val data: T? = null + @SerialName("result") + val result: T ) From d04a893570814a35c3b1341baeccf98a348073e1 Mon Sep 17 00:00:00 2001 From: yihwanggeun Date: Fri, 6 Dec 2024 21:43:14 +0900 Subject: [PATCH 02/18] =?UTF-8?q?#10=20[FIX]=20Editor=20ImageCard=20?= =?UTF-8?q?=EC=83=81=EB=8B=A8=20Title=20=EC=98=A4=EB=A5=98=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/org/sopt/and/presentation/home/HomeScreen.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/org/sopt/and/presentation/home/HomeScreen.kt b/app/src/main/java/org/sopt/and/presentation/home/HomeScreen.kt index 36ea420..373d6e1 100644 --- a/app/src/main/java/org/sopt/and/presentation/home/HomeScreen.kt +++ b/app/src/main/java/org/sopt/and/presentation/home/HomeScreen.kt @@ -132,7 +132,7 @@ fun HomeScreen( items(uiState.editorPicks) { content -> ImageWithTextCard( imageRes = content.imageRes, - title = "Image${content.title}", + title = context.getString(content.title), modifier = Modifier ) } From 445350c0c836fa66db5f5b3266f067a19ab2b52a Mon Sep 17 00:00:00 2001 From: yihwanggeun Date: Fri, 6 Dec 2024 21:43:41 +0900 Subject: [PATCH 03/18] =?UTF-8?q?#10=20[ADD]=20Network=20Error=20Handler?= =?UTF-8?q?=20=EA=B3=B5=ED=86=B5=20=EB=A1=9C=EC=A7=81=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sopt/and/core/util/DefaultErrorHandler.kt | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 app/src/main/java/org/sopt/and/core/util/DefaultErrorHandler.kt diff --git a/app/src/main/java/org/sopt/and/core/util/DefaultErrorHandler.kt b/app/src/main/java/org/sopt/and/core/util/DefaultErrorHandler.kt new file mode 100644 index 0000000..9060add --- /dev/null +++ b/app/src/main/java/org/sopt/and/core/util/DefaultErrorHandler.kt @@ -0,0 +1,23 @@ +package org.sopt.and.core.util + +import android.content.Context +import retrofit2.HttpException +import org.sopt.and.R + +interface ErrorHandler { + fun handleNetworkError(exception: Throwable?): String +} + +class DefaultErrorHandler(private val context: Context) : ErrorHandler { + override fun handleNetworkError(exception: Throwable?): String { + return when (exception) { + is HttpException -> when (exception.code()) { + 400 -> context.getString(R.string.network_error_400) + 403 -> context.getString(R.string.network_error_403) + 409 -> context.getString(R.string.network_error_409) + else -> context.getString(R.string.network_error) + } + else -> context.getString(R.string.network_error) + } + } +} \ No newline at end of file From 3d0c989f8fa6b4dc24d4dd53db8669ee7eb46b4d Mon Sep 17 00:00:00 2001 From: yihwanggeun Date: Fri, 6 Dec 2024 21:44:12 +0900 Subject: [PATCH 04/18] =?UTF-8?q?#10=20[FIX]=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20Data=20Class=20=EC=82=AD=EC=A0=9C=20=EB=B0=8F=20?= =?UTF-8?q?=ED=8F=B4=EB=8D=94=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/org/sopt/and/core/UserInfo.kt | 5 ----- .../and/{presentation/mypage => domain/entity}/HobbyData.kt | 2 +- .../and/{presentation/auth => domain/entity}/SignInData.kt | 2 +- .../and/{presentation/auth => domain/entity}/SignUpData.kt | 2 +- 4 files changed, 3 insertions(+), 8 deletions(-) delete mode 100644 app/src/main/java/org/sopt/and/core/UserInfo.kt rename app/src/main/java/org/sopt/and/{presentation/mypage => domain/entity}/HobbyData.kt (54%) rename app/src/main/java/org/sopt/and/{presentation/auth => domain/entity}/SignInData.kt (56%) rename app/src/main/java/org/sopt/and/{presentation/auth => domain/entity}/SignUpData.kt (53%) diff --git a/app/src/main/java/org/sopt/and/core/UserInfo.kt b/app/src/main/java/org/sopt/and/core/UserInfo.kt deleted file mode 100644 index a025ab0..0000000 --- a/app/src/main/java/org/sopt/and/core/UserInfo.kt +++ /dev/null @@ -1,5 +0,0 @@ -package org.sopt.and.core - -data class UserInfo ( - val email: String? = "" -) \ No newline at end of file diff --git a/app/src/main/java/org/sopt/and/presentation/mypage/HobbyData.kt b/app/src/main/java/org/sopt/and/domain/entity/HobbyData.kt similarity index 54% rename from app/src/main/java/org/sopt/and/presentation/mypage/HobbyData.kt rename to app/src/main/java/org/sopt/and/domain/entity/HobbyData.kt index 0f813b2..c0f7364 100644 --- a/app/src/main/java/org/sopt/and/presentation/mypage/HobbyData.kt +++ b/app/src/main/java/org/sopt/and/domain/entity/HobbyData.kt @@ -1,4 +1,4 @@ -package org.sopt.and.presentation.mypage +package org.sopt.and.domain.entity data class HobbyResult( val hobby: String diff --git a/app/src/main/java/org/sopt/and/presentation/auth/SignInData.kt b/app/src/main/java/org/sopt/and/domain/entity/SignInData.kt similarity index 56% rename from app/src/main/java/org/sopt/and/presentation/auth/SignInData.kt rename to app/src/main/java/org/sopt/and/domain/entity/SignInData.kt index 49166e7..99657d8 100644 --- a/app/src/main/java/org/sopt/and/presentation/auth/SignInData.kt +++ b/app/src/main/java/org/sopt/and/domain/entity/SignInData.kt @@ -1,4 +1,4 @@ -package org.sopt.and.presentation.auth +package org.sopt.and.domain.entity data class LoginResult( val token: String diff --git a/app/src/main/java/org/sopt/and/presentation/auth/SignUpData.kt b/app/src/main/java/org/sopt/and/domain/entity/SignUpData.kt similarity index 53% rename from app/src/main/java/org/sopt/and/presentation/auth/SignUpData.kt rename to app/src/main/java/org/sopt/and/domain/entity/SignUpData.kt index 5469742..65e998a 100644 --- a/app/src/main/java/org/sopt/and/presentation/auth/SignUpData.kt +++ b/app/src/main/java/org/sopt/and/domain/entity/SignUpData.kt @@ -1,4 +1,4 @@ -package org.sopt.and.presentation.auth +package org.sopt.and.domain.entity data class SignUpResult( val no: Int From f208a2347091971a1ec5db6f7a6dfb908554de67 Mon Sep 17 00:00:00 2001 From: yihwanggeun Date: Fri, 6 Dec 2024 21:45:22 +0900 Subject: [PATCH 05/18] =?UTF-8?q?#10=20[FEAT]=20DataSource=20=EC=9D=B8?= =?UTF-8?q?=ED=84=B0=ED=8E=98=EC=9D=B4=EC=8A=A4=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sopt/and/core/data/datasource/HobbyDataSource.kt | 10 ++++++++++ .../sopt/and/core/data/datasource/SignInDataSource.kt | 11 +++++++++++ .../sopt/and/core/data/datasource/SignUpDataSource.kt | 11 +++++++++++ 3 files changed, 32 insertions(+) create mode 100644 app/src/main/java/org/sopt/and/core/data/datasource/HobbyDataSource.kt create mode 100644 app/src/main/java/org/sopt/and/core/data/datasource/SignInDataSource.kt create mode 100644 app/src/main/java/org/sopt/and/core/data/datasource/SignUpDataSource.kt diff --git a/app/src/main/java/org/sopt/and/core/data/datasource/HobbyDataSource.kt b/app/src/main/java/org/sopt/and/core/data/datasource/HobbyDataSource.kt new file mode 100644 index 0000000..8ea0fd1 --- /dev/null +++ b/app/src/main/java/org/sopt/and/core/data/datasource/HobbyDataSource.kt @@ -0,0 +1,10 @@ +package org.sopt.and.core.data.datasource + +import org.sopt.and.core.data.dto.BaseResponse +import org.sopt.and.core.data.dto.response.GetHobbyResponse + +interface HobbyDataSource { + suspend fun getHobby( + token: String + ): BaseResponse +} \ No newline at end of file diff --git a/app/src/main/java/org/sopt/and/core/data/datasource/SignInDataSource.kt b/app/src/main/java/org/sopt/and/core/data/datasource/SignInDataSource.kt new file mode 100644 index 0000000..13a5b07 --- /dev/null +++ b/app/src/main/java/org/sopt/and/core/data/datasource/SignInDataSource.kt @@ -0,0 +1,11 @@ +package org.sopt.and.core.data.datasource + +import org.sopt.and.core.data.dto.BaseResponse +import org.sopt.and.core.data.dto.reqeust.LoginRequest +import org.sopt.and.core.data.dto.response.LoginResponse + +interface SignInDataSource { + suspend fun postSignIn( + request: LoginRequest + ): BaseResponse +} \ No newline at end of file diff --git a/app/src/main/java/org/sopt/and/core/data/datasource/SignUpDataSource.kt b/app/src/main/java/org/sopt/and/core/data/datasource/SignUpDataSource.kt new file mode 100644 index 0000000..b2be195 --- /dev/null +++ b/app/src/main/java/org/sopt/and/core/data/datasource/SignUpDataSource.kt @@ -0,0 +1,11 @@ +package org.sopt.and.core.data.datasource + +import org.sopt.and.core.data.dto.BaseResponse +import org.sopt.and.core.data.dto.reqeust.CreateUserRequest +import org.sopt.and.core.data.dto.response.CreateUserResponse + +interface SignUpDataSource { + suspend fun postSignUp( + request: CreateUserRequest + ): BaseResponse +} \ No newline at end of file From ca580232f38e8a69f7d879e7cdebb7ee679255c5 Mon Sep 17 00:00:00 2001 From: yihwanggeun Date: Fri, 6 Dec 2024 21:49:15 +0900 Subject: [PATCH 06/18] =?UTF-8?q?#10=20[FEAT]=20DataSourceImpl=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/data/datasourceimpl/HobbyDataSourceImpl.kt | 12 ++++++++++++ .../data/datasourceimpl/SignInDataSourceImpl.kt | 13 +++++++++++++ .../data/datasourceimpl/SignUpDataSourceImpl.kt | 12 ++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 app/src/main/java/org/sopt/and/core/data/datasourceimpl/HobbyDataSourceImpl.kt create mode 100644 app/src/main/java/org/sopt/and/core/data/datasourceimpl/SignInDataSourceImpl.kt create mode 100644 app/src/main/java/org/sopt/and/core/data/datasourceimpl/SignUpDataSourceImpl.kt diff --git a/app/src/main/java/org/sopt/and/core/data/datasourceimpl/HobbyDataSourceImpl.kt b/app/src/main/java/org/sopt/and/core/data/datasourceimpl/HobbyDataSourceImpl.kt new file mode 100644 index 0000000..62b4533 --- /dev/null +++ b/app/src/main/java/org/sopt/and/core/data/datasourceimpl/HobbyDataSourceImpl.kt @@ -0,0 +1,12 @@ +package org.sopt.and.core.data.datasourceimpl + +import org.sopt.and.core.data.datasource.HobbyDataSource +import org.sopt.and.core.data.dto.BaseResponse +import org.sopt.and.core.data.dto.response.GetHobbyResponse +import org.sopt.and.core.data.service.HobbyService + +class HobbyDataSourceImpl( + private val hobbyService: HobbyService +) : HobbyDataSource { + override suspend fun getHobby(token: String): BaseResponse = hobbyService.getMyHobby(token) +} \ No newline at end of file diff --git a/app/src/main/java/org/sopt/and/core/data/datasourceimpl/SignInDataSourceImpl.kt b/app/src/main/java/org/sopt/and/core/data/datasourceimpl/SignInDataSourceImpl.kt new file mode 100644 index 0000000..23d203c --- /dev/null +++ b/app/src/main/java/org/sopt/and/core/data/datasourceimpl/SignInDataSourceImpl.kt @@ -0,0 +1,13 @@ +package org.sopt.and.core.data.datasourceimpl + +import org.sopt.and.core.data.datasource.SignInDataSource +import org.sopt.and.core.data.dto.BaseResponse +import org.sopt.and.core.data.dto.reqeust.LoginRequest +import org.sopt.and.core.data.dto.response.LoginResponse + + +class SignInDataSourceImpl( + private val signInService: SignInDataSource +) : SignInDataSource { + override suspend fun postSignIn(request: LoginRequest): BaseResponse = signInService.postSignIn(request) +} \ No newline at end of file diff --git a/app/src/main/java/org/sopt/and/core/data/datasourceimpl/SignUpDataSourceImpl.kt b/app/src/main/java/org/sopt/and/core/data/datasourceimpl/SignUpDataSourceImpl.kt new file mode 100644 index 0000000..02f0e26 --- /dev/null +++ b/app/src/main/java/org/sopt/and/core/data/datasourceimpl/SignUpDataSourceImpl.kt @@ -0,0 +1,12 @@ +package org.sopt.and.core.data.datasourceimpl + +import org.sopt.and.core.data.datasource.SignUpDataSource +import org.sopt.and.core.data.dto.BaseResponse +import org.sopt.and.core.data.dto.reqeust.CreateUserRequest +import org.sopt.and.core.data.dto.response.CreateUserResponse + +class SignUpDataSourceImpl( + private val signUpService: SignUpDataSource +) : SignUpDataSource { + override suspend fun postSignUp(request: CreateUserRequest): BaseResponse = signUpService.postSignUp(request) +} \ No newline at end of file From 1b58cf5592222c775149aa8548b2aa4c46ba35a1 Mon Sep 17 00:00:00 2001 From: yihwanggeun Date: Fri, 6 Dec 2024 21:49:47 +0900 Subject: [PATCH 07/18] =?UTF-8?q?#10=20[FEAT]=20Repository=20Interface=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/sopt/and/domain/repository/HobbyRepository.kt | 7 +++++++ .../org/sopt/and/domain/repository/SignInRepository.kt | 8 ++++++++ .../org/sopt/and/domain/repository/SignUpRepository.kt | 9 +++++++++ 3 files changed, 24 insertions(+) create mode 100644 app/src/main/java/org/sopt/and/domain/repository/HobbyRepository.kt create mode 100644 app/src/main/java/org/sopt/and/domain/repository/SignInRepository.kt create mode 100644 app/src/main/java/org/sopt/and/domain/repository/SignUpRepository.kt diff --git a/app/src/main/java/org/sopt/and/domain/repository/HobbyRepository.kt b/app/src/main/java/org/sopt/and/domain/repository/HobbyRepository.kt new file mode 100644 index 0000000..cc25ccc --- /dev/null +++ b/app/src/main/java/org/sopt/and/domain/repository/HobbyRepository.kt @@ -0,0 +1,7 @@ +package org.sopt.and.domain.repository + +import org.sopt.and.core.data.service.ServicePool + +interface HobbyRepository { + suspend fun getHobby(token: String): Result +} \ No newline at end of file diff --git a/app/src/main/java/org/sopt/and/domain/repository/SignInRepository.kt b/app/src/main/java/org/sopt/and/domain/repository/SignInRepository.kt new file mode 100644 index 0000000..09ca1bf --- /dev/null +++ b/app/src/main/java/org/sopt/and/domain/repository/SignInRepository.kt @@ -0,0 +1,8 @@ +package org.sopt.and.domain.repository + +import org.sopt.and.core.data.dto.reqeust.LoginRequest +import org.sopt.and.core.data.service.ServicePool + +interface SignInRepository { + suspend fun signIn(username: String, password: String): Result +} \ No newline at end of file diff --git a/app/src/main/java/org/sopt/and/domain/repository/SignUpRepository.kt b/app/src/main/java/org/sopt/and/domain/repository/SignUpRepository.kt new file mode 100644 index 0000000..cd368f4 --- /dev/null +++ b/app/src/main/java/org/sopt/and/domain/repository/SignUpRepository.kt @@ -0,0 +1,9 @@ +package org.sopt.and.domain.repository + +import org.sopt.and.core.data.dto.reqeust.CreateUserRequest +import org.sopt.and.core.data.service.SignUpService +import org.sopt.and.core.data.service.ServicePool + +interface SignUpRepository { + suspend fun signUp(username: String, password: String, hobby: String): Result +} \ No newline at end of file From d40f648424ed8268563567e8e0507b43481d04db Mon Sep 17 00:00:00 2001 From: yihwanggeun Date: Fri, 6 Dec 2024 21:52:46 +0900 Subject: [PATCH 08/18] =?UTF-8?q?#10=20[FEAT]=20RepositoryImpl=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/repositoryimpl/HobbyRepositoryImpl.kt | 12 ++++++++++++ .../data/repositoryimpl/SignInRepositoryImpl.kt | 15 +++++++++++++++ .../data/repositoryimpl/SignUpRepositoryImpl.kt | 14 ++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 app/src/main/java/org/sopt/and/core/data/repositoryimpl/HobbyRepositoryImpl.kt create mode 100644 app/src/main/java/org/sopt/and/core/data/repositoryimpl/SignInRepositoryImpl.kt create mode 100644 app/src/main/java/org/sopt/and/core/data/repositoryimpl/SignUpRepositoryImpl.kt diff --git a/app/src/main/java/org/sopt/and/core/data/repositoryimpl/HobbyRepositoryImpl.kt b/app/src/main/java/org/sopt/and/core/data/repositoryimpl/HobbyRepositoryImpl.kt new file mode 100644 index 0000000..67307a5 --- /dev/null +++ b/app/src/main/java/org/sopt/and/core/data/repositoryimpl/HobbyRepositoryImpl.kt @@ -0,0 +1,12 @@ +package org.sopt.and.core.data.repositoryimpl + +import org.sopt.and.core.data.datasource.HobbyDataSource +import org.sopt.and.core.data.service.HobbyService +import org.sopt.and.domain.repository.HobbyRepository + +class HobbyRepositoryImpl(private val hobbyDataSource: HobbyDataSource) : HobbyRepository { + override suspend fun getHobby(token: String): Result = runCatching { + val response = hobbyDataSource.getHobby(token) + response.result.hobby + } +} \ No newline at end of file diff --git a/app/src/main/java/org/sopt/and/core/data/repositoryimpl/SignInRepositoryImpl.kt b/app/src/main/java/org/sopt/and/core/data/repositoryimpl/SignInRepositoryImpl.kt new file mode 100644 index 0000000..cb39c0f --- /dev/null +++ b/app/src/main/java/org/sopt/and/core/data/repositoryimpl/SignInRepositoryImpl.kt @@ -0,0 +1,15 @@ +package org.sopt.and.core.data.repositoryimpl + +import org.sopt.and.core.data.datasource.SignInDataSource +import org.sopt.and.core.data.dto.reqeust.LoginRequest +import org.sopt.and.core.data.service.HobbyService +import org.sopt.and.core.data.service.SignInService +import org.sopt.and.domain.repository.HobbyRepository +import org.sopt.and.domain.repository.SignInRepository + +class SignInRepositoryImpl(private val signInDataSource: SignInDataSource) : SignInRepository { + override suspend fun signIn(username: String, password: String): Result = runCatching { + val response = signInDataSource.postSignIn(LoginRequest(username, password)) + response.result.token + } +} \ No newline at end of file diff --git a/app/src/main/java/org/sopt/and/core/data/repositoryimpl/SignUpRepositoryImpl.kt b/app/src/main/java/org/sopt/and/core/data/repositoryimpl/SignUpRepositoryImpl.kt new file mode 100644 index 0000000..c7a0ca1 --- /dev/null +++ b/app/src/main/java/org/sopt/and/core/data/repositoryimpl/SignUpRepositoryImpl.kt @@ -0,0 +1,14 @@ +package org.sopt.and.core.data.repositoryimpl + +import org.sopt.and.core.data.datasource.SignUpDataSource +import org.sopt.and.core.data.dto.reqeust.CreateUserRequest +import org.sopt.and.core.data.service.HobbyService +import org.sopt.and.core.data.service.SignUpService +import org.sopt.and.domain.repository.HobbyRepository +import org.sopt.and.domain.repository.SignUpRepository + +class SignUpRepositoryImpl(private val signUpDataSource: SignUpDataSource) : SignUpRepository { + override suspend fun signUp(username: String, password: String, hobby: String): Result = runCatching { + signUpDataSource.postSignUp(CreateUserRequest(username, password, hobby)) + } +} \ No newline at end of file From f2267b76ee3a72870fdb39a8666b95852bfb58f7 Mon Sep 17 00:00:00 2001 From: yihwanggeun Date: Fri, 6 Dec 2024 21:53:10 +0900 Subject: [PATCH 09/18] =?UTF-8?q?#10=20[FIX]=20ApiService=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/sopt/and/core/data/service/HobbyService.kt | 13 +++++++++++++ .../sopt/and/core/data/service/SignInService.kt | 14 ++++++++++++++ .../sopt/and/core/data/service/SignUpService.kt | 14 ++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 app/src/main/java/org/sopt/and/core/data/service/HobbyService.kt create mode 100644 app/src/main/java/org/sopt/and/core/data/service/SignInService.kt create mode 100644 app/src/main/java/org/sopt/and/core/data/service/SignUpService.kt diff --git a/app/src/main/java/org/sopt/and/core/data/service/HobbyService.kt b/app/src/main/java/org/sopt/and/core/data/service/HobbyService.kt new file mode 100644 index 0000000..58e6507 --- /dev/null +++ b/app/src/main/java/org/sopt/and/core/data/service/HobbyService.kt @@ -0,0 +1,13 @@ +package org.sopt.and.core.data.service + +import org.sopt.and.core.data.dto.BaseResponse +import org.sopt.and.core.data.dto.response.GetHobbyResponse +import retrofit2.http.GET +import retrofit2.http.Header + +interface HobbyService { + @GET("user/my-hobby") + suspend fun getMyHobby( + @Header("token") token: String + ): BaseResponse +} \ No newline at end of file diff --git a/app/src/main/java/org/sopt/and/core/data/service/SignInService.kt b/app/src/main/java/org/sopt/and/core/data/service/SignInService.kt new file mode 100644 index 0000000..2578996 --- /dev/null +++ b/app/src/main/java/org/sopt/and/core/data/service/SignInService.kt @@ -0,0 +1,14 @@ +package org.sopt.and.core.data.service + +import org.sopt.and.core.data.dto.BaseResponse +import org.sopt.and.core.data.dto.reqeust.LoginRequest +import org.sopt.and.core.data.dto.response.LoginResponse +import retrofit2.http.Body +import retrofit2.http.POST + +interface SignInService { + @POST("login") + suspend fun login( + @Body request: LoginRequest + ): BaseResponse +} \ No newline at end of file diff --git a/app/src/main/java/org/sopt/and/core/data/service/SignUpService.kt b/app/src/main/java/org/sopt/and/core/data/service/SignUpService.kt new file mode 100644 index 0000000..d97e51b --- /dev/null +++ b/app/src/main/java/org/sopt/and/core/data/service/SignUpService.kt @@ -0,0 +1,14 @@ +package org.sopt.and.core.data.service + +import org.sopt.and.core.data.dto.BaseResponse +import org.sopt.and.core.data.dto.reqeust.CreateUserRequest +import org.sopt.and.core.data.dto.response.CreateUserResponse +import retrofit2.http.Body +import retrofit2.http.POST + +interface SignUpService { + @POST("user") + suspend fun signUp( + @Body request: CreateUserRequest + ): BaseResponse +} \ No newline at end of file From 0c8606715966ede5964a0cdbdea5cfdcfa21af57 Mon Sep 17 00:00:00 2001 From: yihwanggeun Date: Fri, 6 Dec 2024 21:53:38 +0900 Subject: [PATCH 10/18] =?UTF-8?q?#10=20[FEAT]=20ServicePool=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/sopt/and/core/data/service/ServicePool.kt | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 app/src/main/java/org/sopt/and/core/data/service/ServicePool.kt diff --git a/app/src/main/java/org/sopt/and/core/data/service/ServicePool.kt b/app/src/main/java/org/sopt/and/core/data/service/ServicePool.kt new file mode 100644 index 0000000..e6b408a --- /dev/null +++ b/app/src/main/java/org/sopt/and/core/data/service/ServicePool.kt @@ -0,0 +1,9 @@ +package org.sopt.and.core.data.service + +import org.sopt.and.network.RetrofitInstance + +object ServicePool { + val signInService: SignInService = RetrofitInstance.create() + val signUpService: SignUpService = RetrofitInstance.create() + val hobbyService: HobbyService = RetrofitInstance.create() +} \ No newline at end of file From b0fb4b2eb0f25bef229a5b81c144d54eab8d5ad7 Mon Sep 17 00:00:00 2001 From: yihwanggeun Date: Fri, 6 Dec 2024 21:57:46 +0900 Subject: [PATCH 11/18] =?UTF-8?q?#10=20[FIX]=20RepositoryPool=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../and/domain/repository/RepositoryPool.kt | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 app/src/main/java/org/sopt/and/domain/repository/RepositoryPool.kt diff --git a/app/src/main/java/org/sopt/and/domain/repository/RepositoryPool.kt b/app/src/main/java/org/sopt/and/domain/repository/RepositoryPool.kt new file mode 100644 index 0000000..020898a --- /dev/null +++ b/app/src/main/java/org/sopt/and/domain/repository/RepositoryPool.kt @@ -0,0 +1,23 @@ +package org.sopt.and.domain.repository + +import org.sopt.and.core.data.datasourceimpl.HobbyDataSourceImpl +import org.sopt.and.core.data.datasourceimpl.SignInDataSourceImpl +import org.sopt.and.core.data.datasourceimpl.SignUpDataSourceImpl +import org.sopt.and.core.data.repositoryimpl.HobbyRepositoryImpl +import org.sopt.and.core.data.repositoryimpl.SignInRepositoryImpl +import org.sopt.and.core.data.repositoryimpl.SignUpRepositoryImpl +import org.sopt.and.core.data.service.ServicePool + +object RepositoryPool { + val hobbyRepository: HobbyRepository by lazy { + HobbyRepositoryImpl(HobbyDataSourceImpl(ServicePool.hobbyService)) + } + + val signInRepository: SignInRepository by lazy { + SignInRepositoryImpl(SignInDataSourceImpl(ServicePool.signInService)) + } + + val signUpRepository: SignUpRepository by lazy { + SignUpRepositoryImpl(SignUpDataSourceImpl(ServicePool.signUpService)) + } +} From 8ce01284e49c41d77d4412edb8de85c95e70d5cd Mon Sep 17 00:00:00 2001 From: yihwanggeun Date: Fri, 6 Dec 2024 21:58:00 +0900 Subject: [PATCH 12/18] =?UTF-8?q?#10=20[DEL]=20ServicePool=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/org/sopt/and/network/RetrofitInstance.kt | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/src/main/java/org/sopt/and/network/RetrofitInstance.kt b/app/src/main/java/org/sopt/and/network/RetrofitInstance.kt index 09521dd..136fb52 100644 --- a/app/src/main/java/org/sopt/and/network/RetrofitInstance.kt +++ b/app/src/main/java/org/sopt/and/network/RetrofitInstance.kt @@ -33,6 +33,3 @@ object RetrofitInstance { } -object ServicePool { - val authService = RetrofitInstance.create() -} \ No newline at end of file From b1f252e51ce98c384d8ee5bff4894895cdc55a4c Mon Sep 17 00:00:00 2001 From: yihwanggeun Date: Fri, 6 Dec 2024 21:58:17 +0900 Subject: [PATCH 13/18] =?UTF-8?q?#10=20[FIX]=20Param=20=ED=83=80=EC=9E=85?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../and/core/data/datasourceimpl/SignInDataSourceImpl.kt | 5 +++-- .../and/core/data/datasourceimpl/SignUpDataSourceImpl.kt | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/sopt/and/core/data/datasourceimpl/SignInDataSourceImpl.kt b/app/src/main/java/org/sopt/and/core/data/datasourceimpl/SignInDataSourceImpl.kt index 23d203c..f8f40c2 100644 --- a/app/src/main/java/org/sopt/and/core/data/datasourceimpl/SignInDataSourceImpl.kt +++ b/app/src/main/java/org/sopt/and/core/data/datasourceimpl/SignInDataSourceImpl.kt @@ -4,10 +4,11 @@ import org.sopt.and.core.data.datasource.SignInDataSource import org.sopt.and.core.data.dto.BaseResponse import org.sopt.and.core.data.dto.reqeust.LoginRequest import org.sopt.and.core.data.dto.response.LoginResponse +import org.sopt.and.core.data.service.SignInService class SignInDataSourceImpl( - private val signInService: SignInDataSource + private val signInService: SignInService ) : SignInDataSource { - override suspend fun postSignIn(request: LoginRequest): BaseResponse = signInService.postSignIn(request) + override suspend fun postSignIn(request: LoginRequest): BaseResponse = signInService.login(request) } \ No newline at end of file diff --git a/app/src/main/java/org/sopt/and/core/data/datasourceimpl/SignUpDataSourceImpl.kt b/app/src/main/java/org/sopt/and/core/data/datasourceimpl/SignUpDataSourceImpl.kt index 02f0e26..57590ff 100644 --- a/app/src/main/java/org/sopt/and/core/data/datasourceimpl/SignUpDataSourceImpl.kt +++ b/app/src/main/java/org/sopt/and/core/data/datasourceimpl/SignUpDataSourceImpl.kt @@ -4,9 +4,11 @@ import org.sopt.and.core.data.datasource.SignUpDataSource import org.sopt.and.core.data.dto.BaseResponse import org.sopt.and.core.data.dto.reqeust.CreateUserRequest import org.sopt.and.core.data.dto.response.CreateUserResponse +import org.sopt.and.core.data.service.SignInService +import org.sopt.and.core.data.service.SignUpService class SignUpDataSourceImpl( - private val signUpService: SignUpDataSource + private val signUpService: SignUpService ) : SignUpDataSource { - override suspend fun postSignUp(request: CreateUserRequest): BaseResponse = signUpService.postSignUp(request) + override suspend fun postSignUp(request: CreateUserRequest): BaseResponse = signUpService.signUp(request) } \ No newline at end of file From a19e63278f9246f099d1722f15780bbdbad30245 Mon Sep 17 00:00:00 2001 From: yihwanggeun Date: Fri, 6 Dec 2024 21:58:41 +0900 Subject: [PATCH 14/18] =?UTF-8?q?#10=20[FIX]=20BaseResponse=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/data/dto/response/CreateUserResponse.kt | 12 +++--------- .../and/core/data/dto/response/GetHobbyResponse.kt | 13 ++++--------- .../and/core/data/dto/response/LoginResponse.kt | 14 +++++--------- 3 files changed, 12 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/org/sopt/and/core/data/dto/response/CreateUserResponse.kt b/app/src/main/java/org/sopt/and/core/data/dto/response/CreateUserResponse.kt index d794158..1fb3e56 100644 --- a/app/src/main/java/org/sopt/and/core/data/dto/response/CreateUserResponse.kt +++ b/app/src/main/java/org/sopt/and/core/data/dto/response/CreateUserResponse.kt @@ -5,12 +5,6 @@ import kotlinx.serialization.Serializable @Serializable data class CreateUserResponse( - @SerialName("result") - val result: Result -) { - @Serializable - data class Result( - @SerialName("no") - val no: Int - ) -} \ No newline at end of file + @SerialName("no") + val userId: Int +) \ No newline at end of file diff --git a/app/src/main/java/org/sopt/and/core/data/dto/response/GetHobbyResponse.kt b/app/src/main/java/org/sopt/and/core/data/dto/response/GetHobbyResponse.kt index 8434f1a..d46d45b 100644 --- a/app/src/main/java/org/sopt/and/core/data/dto/response/GetHobbyResponse.kt +++ b/app/src/main/java/org/sopt/and/core/data/dto/response/GetHobbyResponse.kt @@ -5,12 +5,7 @@ import kotlinx.serialization.Serializable @Serializable data class GetHobbyResponse( - @SerialName("result") - val result: Result -) { - @Serializable - data class Result( - @SerialName("hobby") - val hobby: String - ) -} + @SerialName("hobby") + val hobby: String +) + diff --git a/app/src/main/java/org/sopt/and/core/data/dto/response/LoginResponse.kt b/app/src/main/java/org/sopt/and/core/data/dto/response/LoginResponse.kt index e4b3038..016c5d5 100644 --- a/app/src/main/java/org/sopt/and/core/data/dto/response/LoginResponse.kt +++ b/app/src/main/java/org/sopt/and/core/data/dto/response/LoginResponse.kt @@ -6,12 +6,8 @@ import kotlinx.serialization.Serializable @Serializable data class LoginResponse( - @SerialName("result") - val result: Result -) { - @Serializable - data class Result( - @SerialName("token") - val token: String - ) -} + @SerialName("token") + val token: String +) + + From fc3c5263fd090a96514c6a96d276a875c478d4cf Mon Sep 17 00:00:00 2001 From: yihwanggeun Date: Fri, 6 Dec 2024 21:59:12 +0900 Subject: [PATCH 15/18] =?UTF-8?q?#10=20[FIX]=20=EC=95=84=ED=82=A4=ED=85=8D?= =?UTF-8?q?=EC=B2=98=20=EB=B3=80=EA=B2=BD=EC=97=90=20=EB=94=B0=EB=A5=B8=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../and/presentation/auth/AuthViewModel.kt | 75 ++++++++----------- .../and/presentation/mypage/MyPageScreen.kt | 1 - .../presentation/mypage/MyPageViewModel.kt | 50 +++++-------- 3 files changed, 50 insertions(+), 76 deletions(-) diff --git a/app/src/main/java/org/sopt/and/presentation/auth/AuthViewModel.kt b/app/src/main/java/org/sopt/and/presentation/auth/AuthViewModel.kt index 3797e36..cef1c66 100644 --- a/app/src/main/java/org/sopt/and/presentation/auth/AuthViewModel.kt +++ b/app/src/main/java/org/sopt/and/presentation/auth/AuthViewModel.kt @@ -2,16 +2,14 @@ package org.sopt.and.presentation.auth import android.app.Application import android.content.Context -import android.util.Log import androidx.lifecycle.AndroidViewModel import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.viewModelScope import kotlinx.coroutines.launch import org.sopt.and.R -import org.sopt.and.core.data.dto.reqeust.CreateUserRequest -import org.sopt.and.core.data.dto.reqeust.LoginRequest -import org.sopt.and.network.ServicePool.authService +import org.sopt.and.core.util.DefaultErrorHandler +import org.sopt.and.domain.repository.RepositoryPool import org.sopt.and.utils.KeyStorage import retrofit2.HttpException @@ -19,6 +17,8 @@ class AuthViewModel(application: Application) : AndroidViewModel(application) { private val context = getApplication().applicationContext + private val errorHandler = DefaultErrorHandler(context) + private val _username = MutableLiveData("") val username: LiveData get() = _username @@ -32,6 +32,9 @@ class AuthViewModel(application: Application) : AndroidViewModel(application) { val signUpSuccess = MutableLiveData(false) val errorMessage = MutableLiveData("") + private val signInRepository = RepositoryPool.signInRepository + private val signUpRepository = RepositoryPool.signUpRepository + fun setUsername(username: String) { _username.value = username } @@ -46,30 +49,18 @@ class AuthViewModel(application: Application) : AndroidViewModel(application) { fun onSignInClick(onSignInSuccess: () -> Unit) { viewModelScope.launch { - try { - val response = authService.login( - LoginRequest( - username = _username.value ?: "", - password = _password.value ?: "" - ) - ) + val result = signInRepository.signIn(_username.value.orEmpty(), _password.value.orEmpty()) + + if (result.isSuccess) { context.getSharedPreferences("auth", Context.MODE_PRIVATE).edit() - .putString("token", response.result.token) + .putString("token", result.getOrNull() ?: "") .apply() signInSuccess.value = true errorMessage.value = context.getString(R.string.signin_success) onSignInSuccess() - } catch (e: HttpException) { - when (e.code()) { - 400 -> errorMessage.value = context.getString(R.string.network_error_400) - 403 -> errorMessage.value = context.getString(R.string.network_error_403) - else -> errorMessage.value = context.getString(R.string.signin_fail) - } - signInSuccess.value = false - } catch (e: Exception) { - errorMessage.value = context.getString(R.string.network_error) - signInSuccess.value = false + } else { + handleSignInError(result.exceptionOrNull()) } } } @@ -81,33 +72,23 @@ class AuthViewModel(application: Application) : AndroidViewModel(application) { return@launch } - if(!isValidPassword(_password.value ?: "")){ + if (!isValidPassword(_password.value ?: "")) { errorMessage.value = context.getString(R.string.sign_up_error_password_form) return@launch } - try { - val response = authService.signUp( - CreateUserRequest( - username = _username.value.orEmpty(), - password = _password.value.orEmpty(), - hobby = _hobby.value.orEmpty() - ) - ) + val result = signUpRepository.signUp( + _username.value.orEmpty(), + _password.value.orEmpty(), + _hobby.value.orEmpty() + ) + + if (result.isSuccess) { signUpSuccess.value = true errorMessage.value = context.getString(R.string.signup_success) onSignUpSuccess() - } catch (e: HttpException) { - when (e.code()) { - 400 -> errorMessage.value = context.getString(R.string.network_error_400) - 409 -> errorMessage.value = context.getString(R.string.network_error_409) - else -> errorMessage.value = context.getString(R.string.signup_fail) - } - signUpSuccess.value = false - } catch (e: Exception) { - Log.e("SignUpError", "Exception occurred: ${e.message}", e) - errorMessage.value = context.getString(R.string.network_error) - signUpSuccess.value = false + } else { + handleSignUpError(result.exceptionOrNull()) } } } @@ -121,5 +102,15 @@ class AuthViewModel(application: Application) : AndroidViewModel(application) { private fun isValidPassword(password: String): Boolean { return Regex(KeyStorage.EMAIL_REGEX).matches(password) } + + private fun handleSignUpError(exception: Throwable?) { + errorMessage.value = errorHandler.handleNetworkError(exception) + signUpSuccess.value = false + } + + private fun handleSignInError(exception: Throwable?) { + errorMessage.value = errorHandler.handleNetworkError(exception) + signInSuccess.value = false + } } diff --git a/app/src/main/java/org/sopt/and/presentation/mypage/MyPageScreen.kt b/app/src/main/java/org/sopt/and/presentation/mypage/MyPageScreen.kt index b1db287..197ecb3 100644 --- a/app/src/main/java/org/sopt/and/presentation/mypage/MyPageScreen.kt +++ b/app/src/main/java/org/sopt/and/presentation/mypage/MyPageScreen.kt @@ -39,7 +39,6 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import org.sopt.and.R -import org.sopt.and.core.UserInfo import androidx.lifecycle.viewmodel.compose.viewModel import org.sopt.and.ui.theme.ANDANDROIDTheme diff --git a/app/src/main/java/org/sopt/and/presentation/mypage/MyPageViewModel.kt b/app/src/main/java/org/sopt/and/presentation/mypage/MyPageViewModel.kt index d6874b2..1a99831 100644 --- a/app/src/main/java/org/sopt/and/presentation/mypage/MyPageViewModel.kt +++ b/app/src/main/java/org/sopt/and/presentation/mypage/MyPageViewModel.kt @@ -1,5 +1,6 @@ package org.sopt.and.presentation.mypage +import android.app.Application import android.content.Context import android.util.Log import androidx.lifecycle.ViewModel @@ -7,51 +8,34 @@ import androidx.lifecycle.viewModelScope import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.launch -import org.sopt.and.network.RetrofitInstance -import org.sopt.and.network.ServicePool.authService +import org.sopt.and.core.util.DefaultErrorHandler +import org.sopt.and.domain.repository.RepositoryPool import retrofit2.HttpException import java.io.IOException class MyPageViewModel : ViewModel() { + + private val _uiState = MutableStateFlow(MyPageUiState()) val uiState = _uiState.asStateFlow() private val _errorMessage = MutableStateFlow(null) val errorMessage = _errorMessage.asStateFlow() + private val hobbyRepository = RepositoryPool.hobbyRepository + fun fetchMyHobby(context: Context) { + val errorHandler = DefaultErrorHandler(context) viewModelScope.launch { - try { - val token = context.getSharedPreferences("auth", Context.MODE_PRIVATE) - .getString("token", "") ?: "" - - val response = authService.getMyHobby(token) - _uiState.value = MyPageUiState(hobby = response.result.hobby) - } catch (e: HttpException) { - when (e.code()) { - 401 -> { - _errorMessage.value = "인증 토큰이 없습니다" - Log.e("MyPage", "Authentication error: Missing token", e) - } - 403 -> { - _errorMessage.value = "유효하지 않은 토큰입니다" - Log.e("MyPage", "Authentication error: Invalid token", e) - } - 404 -> { - _errorMessage.value = "유효하지 못한 요청입니다" - Log.e("MyPage", "Not found error", e) - } - else -> { - _errorMessage.value = "서버 오류가 발생했습니다" - Log.e("MyPage", "Server error: ${e.code()}", e) - } - } - } catch (e: IOException) { - _errorMessage.value = "네트워크 연결을 확인해주세요" - Log.e("MyPage", "Network error", e) - } catch (e: Exception) { - _errorMessage.value = "알 수 없는 오류가 발생했습니다" - Log.e("MyPage", "Unexpected error", e) + val token = context.getSharedPreferences("auth", Context.MODE_PRIVATE) + .getString("token", "") ?: "" + + val result = hobbyRepository.getHobby(token) + + result.onSuccess { hobby -> + _uiState.value = MyPageUiState(hobby = hobby) + }.onFailure { e -> + _errorMessage.value = errorHandler.handleNetworkError(e) } } } From 584d977a43def325c6e0f6fab1e403b3bc116175 Mon Sep 17 00:00:00 2001 From: yihwanggeun Date: Fri, 6 Dec 2024 21:59:44 +0900 Subject: [PATCH 16/18] =?UTF-8?q?#10=20[DEL]=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=ED=8C=8C=EC=9D=BC=20=EB=B0=8F=20Params=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/sopt/and/navigation/NavGraph.kt | 3 +- .../java/org/sopt/and/network/AuthService.kt | 28 ------------------- .../org/sopt/and/presentation/MainActivity.kt | 4 +-- 3 files changed, 2 insertions(+), 33 deletions(-) delete mode 100644 app/src/main/java/org/sopt/and/network/AuthService.kt diff --git a/app/src/main/java/org/sopt/and/navigation/NavGraph.kt b/app/src/main/java/org/sopt/and/navigation/NavGraph.kt index dbfcc94..c2b504d 100644 --- a/app/src/main/java/org/sopt/and/navigation/NavGraph.kt +++ b/app/src/main/java/org/sopt/and/navigation/NavGraph.kt @@ -5,7 +5,6 @@ import androidx.compose.ui.Modifier import androidx.navigation.NavHostController import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable -import org.sopt.and.core.UserInfo import org.sopt.and.presentation.home.HomeScreen import org.sopt.and.presentation.mypage.MyPageScreen import org.sopt.and.presentation.search.SearchScreen @@ -22,7 +21,7 @@ sealed class Screen(val route: String) { } @Composable -fun NavGraph(navController: NavHostController, userInfo: UserInfo) { +fun NavGraph(navController: NavHostController) { NavHost( navController = navController, startDestination = Screen.SignIn.route diff --git a/app/src/main/java/org/sopt/and/network/AuthService.kt b/app/src/main/java/org/sopt/and/network/AuthService.kt deleted file mode 100644 index f78ed50..0000000 --- a/app/src/main/java/org/sopt/and/network/AuthService.kt +++ /dev/null @@ -1,28 +0,0 @@ -package org.sopt.and.network - -import org.sopt.and.core.data.dto.reqeust.CreateUserRequest -import org.sopt.and.core.data.dto.reqeust.LoginRequest -import org.sopt.and.core.data.dto.response.CreateUserResponse -import org.sopt.and.core.data.dto.response.GetHobbyResponse -import org.sopt.and.core.data.dto.response.LoginResponse -import retrofit2.http.Body -import retrofit2.http.GET -import retrofit2.http.Header -import retrofit2.http.POST - -interface AuthService { - @POST("user") - suspend fun signUp( - @Body request: CreateUserRequest - ): CreateUserResponse - - @POST("login") - suspend fun login( - @Body request: LoginRequest - ): LoginResponse - - @GET("user/my-hobby") - suspend fun getMyHobby( - @Header("token") token: String - ): GetHobbyResponse -} \ No newline at end of file diff --git a/app/src/main/java/org/sopt/and/presentation/MainActivity.kt b/app/src/main/java/org/sopt/and/presentation/MainActivity.kt index 8e17af1..e1c4787 100644 --- a/app/src/main/java/org/sopt/and/presentation/MainActivity.kt +++ b/app/src/main/java/org/sopt/and/presentation/MainActivity.kt @@ -16,7 +16,6 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.navigation.compose.currentBackStackEntryAsState import androidx.navigation.compose.rememberNavController import org.sopt.and.R -import org.sopt.and.core.UserInfo import org.sopt.and.navigation.NavGraph import org.sopt.and.navigation.Screen import org.sopt.and.presentation.common.BottomNavigationBar @@ -59,8 +58,7 @@ fun MainScreen(userEmail: String?) { ) { paddingValues -> Box(modifier = Modifier.padding(paddingValues)) { NavGraph( - navController = navController, - userInfo = UserInfo(userEmail) + navController = navController ) } } From bc20526b7306e1838578eafd5e5192ea8163004b Mon Sep 17 00:00:00 2001 From: yihwanggeun Date: Fri, 6 Dec 2024 22:16:12 +0900 Subject: [PATCH 17/18] =?UTF-8?q?#10=20[FIX]=20DataClass=20=EC=9D=B4?= =?UTF-8?q?=EB=A6=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/org/sopt/and/domain/entity/HobbyData.kt | 2 +- app/src/main/java/org/sopt/and/domain/entity/SignInData.kt | 2 +- app/src/main/java/org/sopt/and/domain/entity/SignUpData.kt | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/sopt/and/domain/entity/HobbyData.kt b/app/src/main/java/org/sopt/and/domain/entity/HobbyData.kt index c0f7364..0852df5 100644 --- a/app/src/main/java/org/sopt/and/domain/entity/HobbyData.kt +++ b/app/src/main/java/org/sopt/and/domain/entity/HobbyData.kt @@ -1,5 +1,5 @@ package org.sopt.and.domain.entity -data class HobbyResult( +data class HobbyData( val hobby: String ) diff --git a/app/src/main/java/org/sopt/and/domain/entity/SignInData.kt b/app/src/main/java/org/sopt/and/domain/entity/SignInData.kt index 99657d8..19b44e7 100644 --- a/app/src/main/java/org/sopt/and/domain/entity/SignInData.kt +++ b/app/src/main/java/org/sopt/and/domain/entity/SignInData.kt @@ -1,6 +1,6 @@ package org.sopt.and.domain.entity -data class LoginResult( +data class SignInData( val token: String ) diff --git a/app/src/main/java/org/sopt/and/domain/entity/SignUpData.kt b/app/src/main/java/org/sopt/and/domain/entity/SignUpData.kt index 65e998a..d05c537 100644 --- a/app/src/main/java/org/sopt/and/domain/entity/SignUpData.kt +++ b/app/src/main/java/org/sopt/and/domain/entity/SignUpData.kt @@ -1,5 +1,5 @@ package org.sopt.and.domain.entity -data class SignUpResult( - val no: Int +data class SignUpData( + val userId: Int ) From 98dea2b184aa432dbfeb71844fdd994e4f385c35 Mon Sep 17 00:00:00 2001 From: yihwanggeun Date: Fri, 6 Dec 2024 22:20:25 +0900 Subject: [PATCH 18/18] =?UTF-8?q?#10=20[FIX]=20Return=20=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=84=B0=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/data/datasourceimpl/SignUpDataSourceImpl.kt | 1 - .../core/data/repositoryimpl/HobbyRepositoryImpl.kt | 8 +++++--- .../core/data/repositoryimpl/SignInRepositoryImpl.kt | 8 +++----- .../core/data/repositoryimpl/SignUpRepositoryImpl.kt | 10 +++++----- .../org/sopt/and/domain/repository/HobbyRepository.kt | 5 +++-- .../org/sopt/and/domain/repository/SignInRepository.kt | 5 ++--- .../org/sopt/and/domain/repository/SignUpRepository.kt | 7 +++---- .../org/sopt/and/presentation/auth/AuthViewModel.kt | 7 ++++--- .../sopt/and/presentation/mypage/MyPageViewModel.kt | 4 ++-- 9 files changed, 27 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/org/sopt/and/core/data/datasourceimpl/SignUpDataSourceImpl.kt b/app/src/main/java/org/sopt/and/core/data/datasourceimpl/SignUpDataSourceImpl.kt index 57590ff..2cf98ae 100644 --- a/app/src/main/java/org/sopt/and/core/data/datasourceimpl/SignUpDataSourceImpl.kt +++ b/app/src/main/java/org/sopt/and/core/data/datasourceimpl/SignUpDataSourceImpl.kt @@ -4,7 +4,6 @@ import org.sopt.and.core.data.datasource.SignUpDataSource import org.sopt.and.core.data.dto.BaseResponse import org.sopt.and.core.data.dto.reqeust.CreateUserRequest import org.sopt.and.core.data.dto.response.CreateUserResponse -import org.sopt.and.core.data.service.SignInService import org.sopt.and.core.data.service.SignUpService class SignUpDataSourceImpl( diff --git a/app/src/main/java/org/sopt/and/core/data/repositoryimpl/HobbyRepositoryImpl.kt b/app/src/main/java/org/sopt/and/core/data/repositoryimpl/HobbyRepositoryImpl.kt index 67307a5..930ad5d 100644 --- a/app/src/main/java/org/sopt/and/core/data/repositoryimpl/HobbyRepositoryImpl.kt +++ b/app/src/main/java/org/sopt/and/core/data/repositoryimpl/HobbyRepositoryImpl.kt @@ -1,12 +1,14 @@ package org.sopt.and.core.data.repositoryimpl import org.sopt.and.core.data.datasource.HobbyDataSource -import org.sopt.and.core.data.service.HobbyService +import org.sopt.and.core.data.dto.response.GetHobbyResponse +import org.sopt.and.domain.entity.HobbyData +import org.sopt.and.domain.entity.SignInData import org.sopt.and.domain.repository.HobbyRepository class HobbyRepositoryImpl(private val hobbyDataSource: HobbyDataSource) : HobbyRepository { - override suspend fun getHobby(token: String): Result = runCatching { + override suspend fun getHobby(token: String): Result = runCatching { val response = hobbyDataSource.getHobby(token) - response.result.hobby + HobbyData(response.result.hobby) } } \ No newline at end of file diff --git a/app/src/main/java/org/sopt/and/core/data/repositoryimpl/SignInRepositoryImpl.kt b/app/src/main/java/org/sopt/and/core/data/repositoryimpl/SignInRepositoryImpl.kt index cb39c0f..5cba193 100644 --- a/app/src/main/java/org/sopt/and/core/data/repositoryimpl/SignInRepositoryImpl.kt +++ b/app/src/main/java/org/sopt/and/core/data/repositoryimpl/SignInRepositoryImpl.kt @@ -2,14 +2,12 @@ package org.sopt.and.core.data.repositoryimpl import org.sopt.and.core.data.datasource.SignInDataSource import org.sopt.and.core.data.dto.reqeust.LoginRequest -import org.sopt.and.core.data.service.HobbyService -import org.sopt.and.core.data.service.SignInService -import org.sopt.and.domain.repository.HobbyRepository +import org.sopt.and.domain.entity.SignInData import org.sopt.and.domain.repository.SignInRepository class SignInRepositoryImpl(private val signInDataSource: SignInDataSource) : SignInRepository { - override suspend fun signIn(username: String, password: String): Result = runCatching { + override suspend fun signIn(username: String, password: String): Result = runCatching { val response = signInDataSource.postSignIn(LoginRequest(username, password)) - response.result.token + SignInData(response.result.token) } } \ No newline at end of file diff --git a/app/src/main/java/org/sopt/and/core/data/repositoryimpl/SignUpRepositoryImpl.kt b/app/src/main/java/org/sopt/and/core/data/repositoryimpl/SignUpRepositoryImpl.kt index c7a0ca1..ff1c4ef 100644 --- a/app/src/main/java/org/sopt/and/core/data/repositoryimpl/SignUpRepositoryImpl.kt +++ b/app/src/main/java/org/sopt/and/core/data/repositoryimpl/SignUpRepositoryImpl.kt @@ -2,13 +2,13 @@ package org.sopt.and.core.data.repositoryimpl import org.sopt.and.core.data.datasource.SignUpDataSource import org.sopt.and.core.data.dto.reqeust.CreateUserRequest -import org.sopt.and.core.data.service.HobbyService -import org.sopt.and.core.data.service.SignUpService -import org.sopt.and.domain.repository.HobbyRepository +import org.sopt.and.core.data.dto.response.CreateUserResponse +import org.sopt.and.domain.entity.SignUpData import org.sopt.and.domain.repository.SignUpRepository class SignUpRepositoryImpl(private val signUpDataSource: SignUpDataSource) : SignUpRepository { - override suspend fun signUp(username: String, password: String, hobby: String): Result = runCatching { - signUpDataSource.postSignUp(CreateUserRequest(username, password, hobby)) + override suspend fun signUp(username: String, password: String, hobby: String): Result = runCatching { + val response = signUpDataSource.postSignUp(CreateUserRequest(username, password, hobby)) + SignUpData(response.result.userId) } } \ No newline at end of file diff --git a/app/src/main/java/org/sopt/and/domain/repository/HobbyRepository.kt b/app/src/main/java/org/sopt/and/domain/repository/HobbyRepository.kt index cc25ccc..80981d5 100644 --- a/app/src/main/java/org/sopt/and/domain/repository/HobbyRepository.kt +++ b/app/src/main/java/org/sopt/and/domain/repository/HobbyRepository.kt @@ -1,7 +1,8 @@ package org.sopt.and.domain.repository -import org.sopt.and.core.data.service.ServicePool +import org.sopt.and.core.data.dto.response.GetHobbyResponse +import org.sopt.and.domain.entity.HobbyData interface HobbyRepository { - suspend fun getHobby(token: String): Result + suspend fun getHobby(token: String): Result } \ No newline at end of file diff --git a/app/src/main/java/org/sopt/and/domain/repository/SignInRepository.kt b/app/src/main/java/org/sopt/and/domain/repository/SignInRepository.kt index 09ca1bf..eb74384 100644 --- a/app/src/main/java/org/sopt/and/domain/repository/SignInRepository.kt +++ b/app/src/main/java/org/sopt/and/domain/repository/SignInRepository.kt @@ -1,8 +1,7 @@ package org.sopt.and.domain.repository -import org.sopt.and.core.data.dto.reqeust.LoginRequest -import org.sopt.and.core.data.service.ServicePool +import org.sopt.and.domain.entity.SignInData interface SignInRepository { - suspend fun signIn(username: String, password: String): Result + suspend fun signIn(username: String, password: String): Result } \ No newline at end of file diff --git a/app/src/main/java/org/sopt/and/domain/repository/SignUpRepository.kt b/app/src/main/java/org/sopt/and/domain/repository/SignUpRepository.kt index cd368f4..7fad5e2 100644 --- a/app/src/main/java/org/sopt/and/domain/repository/SignUpRepository.kt +++ b/app/src/main/java/org/sopt/and/domain/repository/SignUpRepository.kt @@ -1,9 +1,8 @@ package org.sopt.and.domain.repository -import org.sopt.and.core.data.dto.reqeust.CreateUserRequest -import org.sopt.and.core.data.service.SignUpService -import org.sopt.and.core.data.service.ServicePool +import org.sopt.and.core.data.dto.response.CreateUserResponse +import org.sopt.and.domain.entity.SignUpData interface SignUpRepository { - suspend fun signUp(username: String, password: String, hobby: String): Result + suspend fun signUp(username: String, password: String, hobby: String): Result } \ No newline at end of file diff --git a/app/src/main/java/org/sopt/and/presentation/auth/AuthViewModel.kt b/app/src/main/java/org/sopt/and/presentation/auth/AuthViewModel.kt index cef1c66..99cf639 100644 --- a/app/src/main/java/org/sopt/and/presentation/auth/AuthViewModel.kt +++ b/app/src/main/java/org/sopt/and/presentation/auth/AuthViewModel.kt @@ -9,6 +9,7 @@ import androidx.lifecycle.viewModelScope import kotlinx.coroutines.launch import org.sopt.and.R import org.sopt.and.core.util.DefaultErrorHandler +import org.sopt.and.domain.entity.SignInData import org.sopt.and.domain.repository.RepositoryPool import org.sopt.and.utils.KeyStorage import retrofit2.HttpException @@ -51,15 +52,15 @@ class AuthViewModel(application: Application) : AndroidViewModel(application) { viewModelScope.launch { val result = signInRepository.signIn(_username.value.orEmpty(), _password.value.orEmpty()) - if (result.isSuccess) { + result.onSuccess { signInData -> context.getSharedPreferences("auth", Context.MODE_PRIVATE).edit() - .putString("token", result.getOrNull() ?: "") + .putString("token", signInData.token.orEmpty()) .apply() signInSuccess.value = true errorMessage.value = context.getString(R.string.signin_success) onSignInSuccess() - } else { + }.onFailure{ handleSignInError(result.exceptionOrNull()) } } diff --git a/app/src/main/java/org/sopt/and/presentation/mypage/MyPageViewModel.kt b/app/src/main/java/org/sopt/and/presentation/mypage/MyPageViewModel.kt index 1a99831..0428f85 100644 --- a/app/src/main/java/org/sopt/and/presentation/mypage/MyPageViewModel.kt +++ b/app/src/main/java/org/sopt/and/presentation/mypage/MyPageViewModel.kt @@ -32,8 +32,8 @@ class MyPageViewModel : ViewModel() { val result = hobbyRepository.getHobby(token) - result.onSuccess { hobby -> - _uiState.value = MyPageUiState(hobby = hobby) + result.onSuccess { hobbyData -> + _uiState.value = MyPageUiState(hobby = hobbyData.hobby) }.onFailure { e -> _errorMessage.value = errorHandler.handleNetworkError(e) }