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