From 189f67413c2497a3de0caa784e08d4d30b05b7aa Mon Sep 17 00:00:00 2001 From: SYAAINN Date: Wed, 4 Dec 2024 11:35:18 +0900 Subject: [PATCH] =?UTF-8?q?[feat/#10]=20response=20body=EA=B0=80=20?= =?UTF-8?q?=EC=97=86=EB=8A=94=20=EA=B2=BD=EC=9A=B0=20Response=20=EA=B0=9D?= =?UTF-8?q?=EC=B2=B4=EB=A5=BC=20=EC=9D=B4=EC=9A=A9=ED=95=98=EC=97=AC=20?= =?UTF-8?q?=EC=84=9C=EB=B2=84=ED=86=B5=EC=8B=A0=20=EC=83=81=ED=83=9C?= =?UTF-8?q?=EB=A5=BC=20=EA=B2=80=EC=82=AC=ED=95=A9=EB=8B=88=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../remote/datasource/UserRemoteDataSource.kt | 3 ++- .../datasourceimpl/UserRemoteDataSourceImpl.kt | 3 ++- .../and/data/remote/service/AuthService.kt | 5 ++--- .../and/data/remote/service/UserService.kt | 9 +++++---- .../data/repositoryimpl/UserRepositoryImpl.kt | 18 +++++++++++++----- .../ui/main/screen/UserInfoUpdateState.kt | 10 ++++------ 6 files changed, 28 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/org/sopt/and/data/remote/datasource/UserRemoteDataSource.kt b/app/src/main/java/org/sopt/and/data/remote/datasource/UserRemoteDataSource.kt index 69f7e41..124011e 100644 --- a/app/src/main/java/org/sopt/and/data/remote/datasource/UserRemoteDataSource.kt +++ b/app/src/main/java/org/sopt/and/data/remote/datasource/UserRemoteDataSource.kt @@ -3,9 +3,10 @@ package org.sopt.and.data.remote.datasource import org.sopt.and.data.remote.model.base.ApiResponse import org.sopt.and.data.remote.model.request.UserInfoUpdateRequestDto import org.sopt.and.data.remote.model.response.HobbyResponseDto +import retrofit2.Response interface UserRemoteDataSource { suspend fun getMyHobby(token: String): ApiResponse suspend fun getOthersHobby(token: String, userNo: Int): ApiResponse - suspend fun updateUserInfo(token: String, userInfoUpdateRequestDto: UserInfoUpdateRequestDto): ApiResponse + suspend fun updateUserInfo(token: String, userInfoUpdateRequestDto: UserInfoUpdateRequestDto): Response } \ No newline at end of file diff --git a/app/src/main/java/org/sopt/and/data/remote/datasourceimpl/UserRemoteDataSourceImpl.kt b/app/src/main/java/org/sopt/and/data/remote/datasourceimpl/UserRemoteDataSourceImpl.kt index 8dbeb99..518c330 100644 --- a/app/src/main/java/org/sopt/and/data/remote/datasourceimpl/UserRemoteDataSourceImpl.kt +++ b/app/src/main/java/org/sopt/and/data/remote/datasourceimpl/UserRemoteDataSourceImpl.kt @@ -5,6 +5,7 @@ import org.sopt.and.data.remote.model.base.ApiResponse import org.sopt.and.data.remote.model.request.UserInfoUpdateRequestDto import org.sopt.and.data.remote.model.response.HobbyResponseDto import org.sopt.and.data.remote.service.UserService +import retrofit2.Response import javax.inject.Inject class UserRemoteDataSourceImpl @Inject constructor( @@ -20,6 +21,6 @@ class UserRemoteDataSourceImpl @Inject constructor( override suspend fun updateUserInfo( token: String, userInfoUpdateRequestDto: UserInfoUpdateRequestDto - ): ApiResponse = + ): Response = userService.updateUserInfo(token = token, userInfoUpdateRequestDto = userInfoUpdateRequestDto) } \ No newline at end of file diff --git a/app/src/main/java/org/sopt/and/data/remote/service/AuthService.kt b/app/src/main/java/org/sopt/and/data/remote/service/AuthService.kt index 0348f0d..8b2c459 100644 --- a/app/src/main/java/org/sopt/and/data/remote/service/AuthService.kt +++ b/app/src/main/java/org/sopt/and/data/remote/service/AuthService.kt @@ -5,18 +5,17 @@ import org.sopt.and.data.remote.model.request.LoginRequestDto import org.sopt.and.data.remote.model.request.UserRegistrationRequestDto import org.sopt.and.data.remote.model.response.LoginResponseDto import org.sopt.and.data.remote.model.response.UserRegistrationResponseDto -import retrofit2.Call import retrofit2.http.Body import retrofit2.http.POST interface AuthService { @POST("user") - fun registerUser( + suspend fun registerUser( @Body userRegistrationRequestDto: UserRegistrationRequestDto ): ApiResponse @POST("login") - fun login( + suspend fun login( @Body loginRequestDto: LoginRequestDto ): ApiResponse } \ No newline at end of file diff --git a/app/src/main/java/org/sopt/and/data/remote/service/UserService.kt b/app/src/main/java/org/sopt/and/data/remote/service/UserService.kt index 0ae9d5e..2e05891 100644 --- a/app/src/main/java/org/sopt/and/data/remote/service/UserService.kt +++ b/app/src/main/java/org/sopt/and/data/remote/service/UserService.kt @@ -3,6 +3,7 @@ package org.sopt.and.data.remote.service import org.sopt.and.data.remote.model.base.ApiResponse import org.sopt.and.data.remote.model.request.UserInfoUpdateRequestDto import org.sopt.and.data.remote.model.response.HobbyResponseDto +import retrofit2.Response import retrofit2.http.Body import retrofit2.http.GET import retrofit2.http.Header @@ -11,19 +12,19 @@ import retrofit2.http.Path interface UserService { @GET("user/my-hobby") - fun getMyHobby( + suspend fun getMyHobby( @Header("token") token: String ): ApiResponse @GET("user/{no}/hobby") - fun getOthersHobby( + suspend fun getOthersHobby( @Header("token") token: String, @Path("no") userNo: Int ): ApiResponse @PUT("user") - fun updateUserInfo( + suspend fun updateUserInfo( @Header("token") token: String, @Body userInfoUpdateRequestDto: UserInfoUpdateRequestDto - ): ApiResponse + ): Response } \ No newline at end of file diff --git a/app/src/main/java/org/sopt/and/data/repositoryimpl/UserRepositoryImpl.kt b/app/src/main/java/org/sopt/and/data/repositoryimpl/UserRepositoryImpl.kt index fb9001f..b02efd8 100644 --- a/app/src/main/java/org/sopt/and/data/repositoryimpl/UserRepositoryImpl.kt +++ b/app/src/main/java/org/sopt/and/data/repositoryimpl/UserRepositoryImpl.kt @@ -10,7 +10,7 @@ import javax.inject.Inject class UserRepositoryImpl @Inject constructor( private val userRemoteDataSource: UserRemoteDataSource -): UserRepository { +) : UserRepository { override suspend fun getMyHobby(token: String): Result { return runCatching { userRemoteDataSource.getMyHobby(token = token).handleApiResponse().getOrThrow().toDomain() @@ -29,10 +29,18 @@ class UserRepositoryImpl @Inject constructor( hobby: String? ): Result { return runCatching { - userRemoteDataSource.updateUserInfo(token = token, userInfoUpdateRequestDto = UserInfoUpdateRequestDto( - password = password, - hobby = hobby - )).handleApiResponse().getOrThrow() + val response = userRemoteDataSource.updateUserInfo( + token = token, + userInfoUpdateRequestDto = UserInfoUpdateRequestDto( + password = password, + hobby = hobby + ) + ) + if(response.isSuccessful) { + Result.success(Unit) + } else { + Result.failure(Exception("Error : ${response.code()} ${response.message()}")) + } } } } \ No newline at end of file diff --git a/app/src/main/java/org/sopt/and/presentation/ui/main/screen/UserInfoUpdateState.kt b/app/src/main/java/org/sopt/and/presentation/ui/main/screen/UserInfoUpdateState.kt index 4bf1da3..9ef94f2 100644 --- a/app/src/main/java/org/sopt/and/presentation/ui/main/screen/UserInfoUpdateState.kt +++ b/app/src/main/java/org/sopt/and/presentation/ui/main/screen/UserInfoUpdateState.kt @@ -1,10 +1,8 @@ package org.sopt.and.presentation.ui.main.screen -import org.sopt.and.domain.model.Hobby - sealed class UserInfoUpdateState { - data object Idle: UserInfoUpdateState() - data object Loading: UserInfoUpdateState() - data object Success: UserInfoUpdateState() - data class Failure(val errorMessage: String): UserInfoUpdateState() + data object Idle : UserInfoUpdateState() + data object Loading : UserInfoUpdateState() + data object Success : UserInfoUpdateState() + data class Failure(val errorMessage: String) : UserInfoUpdateState() } \ No newline at end of file