From 935d201bd5c6361605254ccb02af92425a66fc5f Mon Sep 17 00:00:00 2001 From: SYAAINN Date: Mon, 2 Dec 2024 11:41:30 +0900 Subject: [PATCH] =?UTF-8?q?[feat/#10]=20api=205=EA=B0=9C=EB=A5=BC=20?= =?UTF-8?q?=EC=9C=84=ED=95=9C=20service=EC=99=80=20model=EC=9D=84=20?= =?UTF-8?q?=EC=A0=95=EC=9D=98=ED=95=A9=EB=8B=88=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{ => datasource}/TokenLocalDataSource.kt | 2 +- .../TokenLocalDataSourceImpl.kt | 3 ++- .../model/request/UserInfoUpdateRequestDto.kt | 10 +++++++++ ...obbyResponseDto.kt => HobbyResponseDto.kt} | 2 +- .../and/data/remote/service/AuthService.kt | 5 +++-- .../and/data/remote/service/UserService.kt | 22 ++++++++++++++++--- .../repositoryimpl/TokenRepositoryImpl.kt | 2 +- .../org/sopt/and/di/TokenDataStoreModule.kt | 4 ++-- .../ui/main/screen/MainViewModel.kt | 12 +++++----- 9 files changed, 45 insertions(+), 17 deletions(-) rename app/src/main/java/org/sopt/and/data/local/{ => datasource}/TokenLocalDataSource.kt (64%) rename app/src/main/java/org/sopt/and/data/local/{ => datasourceimpl}/TokenLocalDataSourceImpl.kt (83%) create mode 100644 app/src/main/java/org/sopt/and/data/remote/model/request/UserInfoUpdateRequestDto.kt rename app/src/main/java/org/sopt/and/data/remote/model/response/{GetMyHobbyResponseDto.kt => HobbyResponseDto.kt} (84%) diff --git a/app/src/main/java/org/sopt/and/data/local/TokenLocalDataSource.kt b/app/src/main/java/org/sopt/and/data/local/datasource/TokenLocalDataSource.kt similarity index 64% rename from app/src/main/java/org/sopt/and/data/local/TokenLocalDataSource.kt rename to app/src/main/java/org/sopt/and/data/local/datasource/TokenLocalDataSource.kt index cbe23b9..e6303bb 100644 --- a/app/src/main/java/org/sopt/and/data/local/TokenLocalDataSource.kt +++ b/app/src/main/java/org/sopt/and/data/local/datasource/TokenLocalDataSource.kt @@ -1,4 +1,4 @@ -package org.sopt.and.data.local +package org.sopt.and.data.local.datasource interface TokenLocalDataSource { var token: String diff --git a/app/src/main/java/org/sopt/and/data/local/TokenLocalDataSourceImpl.kt b/app/src/main/java/org/sopt/and/data/local/datasourceimpl/TokenLocalDataSourceImpl.kt similarity index 83% rename from app/src/main/java/org/sopt/and/data/local/TokenLocalDataSourceImpl.kt rename to app/src/main/java/org/sopt/and/data/local/datasourceimpl/TokenLocalDataSourceImpl.kt index 32858b1..b211fcc 100644 --- a/app/src/main/java/org/sopt/and/data/local/TokenLocalDataSourceImpl.kt +++ b/app/src/main/java/org/sopt/and/data/local/datasourceimpl/TokenLocalDataSourceImpl.kt @@ -1,6 +1,7 @@ -package org.sopt.and.data.local +package org.sopt.and.data.local.datasourceimpl import android.content.SharedPreferences +import org.sopt.and.data.local.datasource.TokenLocalDataSource import javax.inject.Inject class TokenLocalDataSourceImpl @Inject constructor( diff --git a/app/src/main/java/org/sopt/and/data/remote/model/request/UserInfoUpdateRequestDto.kt b/app/src/main/java/org/sopt/and/data/remote/model/request/UserInfoUpdateRequestDto.kt new file mode 100644 index 0000000..934535d --- /dev/null +++ b/app/src/main/java/org/sopt/and/data/remote/model/request/UserInfoUpdateRequestDto.kt @@ -0,0 +1,10 @@ +package org.sopt.and.data.remote.model.request + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class UserInfoUpdateRequestDto ( + @SerialName("hobby") val hobby: String?, + @SerialName("password") val password: String? +) \ No newline at end of file diff --git a/app/src/main/java/org/sopt/and/data/remote/model/response/GetMyHobbyResponseDto.kt b/app/src/main/java/org/sopt/and/data/remote/model/response/HobbyResponseDto.kt similarity index 84% rename from app/src/main/java/org/sopt/and/data/remote/model/response/GetMyHobbyResponseDto.kt rename to app/src/main/java/org/sopt/and/data/remote/model/response/HobbyResponseDto.kt index e1f2d5b..bbf0e2b 100644 --- a/app/src/main/java/org/sopt/and/data/remote/model/response/GetMyHobbyResponseDto.kt +++ b/app/src/main/java/org/sopt/and/data/remote/model/response/HobbyResponseDto.kt @@ -4,6 +4,6 @@ import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable -data class GetMyHobbyResponseDto( +data class HobbyResponseDto( @SerialName("hobby") val hobby: String ) \ 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 960af66..0348f0d 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 @@ -1,5 +1,6 @@ package org.sopt.and.data.remote.service +import org.sopt.and.data.remote.model.base.ApiResponse 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 @@ -12,10 +13,10 @@ interface AuthService { @POST("user") fun registerUser( @Body userRegistrationRequestDto: UserRegistrationRequestDto - ): Call + ): ApiResponse @POST("login") fun login( @Body loginRequestDto: LoginRequestDto - ): Call + ): 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 5653f60..0ae9d5e 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 @@ -1,13 +1,29 @@ package org.sopt.and.data.remote.service -import org.sopt.and.data.remote.model.response.GetMyHobbyResponseDto -import retrofit2.Call +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.http.Body import retrofit2.http.GET import retrofit2.http.Header +import retrofit2.http.PUT +import retrofit2.http.Path interface UserService { @GET("user/my-hobby") fun getMyHobby( @Header("token") token: String - ): Call + ): ApiResponse + + @GET("user/{no}/hobby") + fun getOthersHobby( + @Header("token") token: String, + @Path("no") userNo: Int + ): ApiResponse + + @PUT("user") + fun updateUserInfo( + @Header("token") token: String, + @Body userInfoUpdateRequestDto: UserInfoUpdateRequestDto + ): ApiResponse } \ No newline at end of file diff --git a/app/src/main/java/org/sopt/and/data/repositoryimpl/TokenRepositoryImpl.kt b/app/src/main/java/org/sopt/and/data/repositoryimpl/TokenRepositoryImpl.kt index eab9008..fd59e75 100644 --- a/app/src/main/java/org/sopt/and/data/repositoryimpl/TokenRepositoryImpl.kt +++ b/app/src/main/java/org/sopt/and/data/repositoryimpl/TokenRepositoryImpl.kt @@ -1,6 +1,6 @@ package org.sopt.and.data.repositoryimpl -import org.sopt.and.data.local.TokenLocalDataSource +import org.sopt.and.data.local.datasource.TokenLocalDataSource import org.sopt.and.domain.repository.TokenRepository import javax.inject.Inject diff --git a/app/src/main/java/org/sopt/and/di/TokenDataStoreModule.kt b/app/src/main/java/org/sopt/and/di/TokenDataStoreModule.kt index 3eb6c9a..d5310b1 100644 --- a/app/src/main/java/org/sopt/and/di/TokenDataStoreModule.kt +++ b/app/src/main/java/org/sopt/and/di/TokenDataStoreModule.kt @@ -5,8 +5,8 @@ import dagger.Module import dagger.Provides import dagger.hilt.InstallIn import dagger.hilt.components.SingletonComponent -import org.sopt.and.data.local.TokenLocalDataSource -import org.sopt.and.data.local.TokenLocalDataSourceImpl +import org.sopt.and.data.local.datasource.TokenLocalDataSource +import org.sopt.and.data.local.datasourceimpl.TokenLocalDataSourceImpl import javax.inject.Singleton @Module diff --git a/app/src/main/java/org/sopt/and/presentation/ui/main/screen/MainViewModel.kt b/app/src/main/java/org/sopt/and/presentation/ui/main/screen/MainViewModel.kt index 214b2f5..60d24e2 100644 --- a/app/src/main/java/org/sopt/and/presentation/ui/main/screen/MainViewModel.kt +++ b/app/src/main/java/org/sopt/and/presentation/ui/main/screen/MainViewModel.kt @@ -6,8 +6,8 @@ import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.launch -import org.sopt.and.data.local.TokenLocalDataSource -import org.sopt.and.data.remote.model.response.GetMyHobbyResponseDto +import org.sopt.and.data.local.datasource.TokenLocalDataSource +import org.sopt.and.data.remote.model.response.HobbyResponseDto import org.sopt.and.di.ServicePool import retrofit2.Call import retrofit2.Callback @@ -26,10 +26,10 @@ class MainViewModel @Inject constructor( fun getUserHobby() { viewModelScope.launch { userService.getMyHobby(token = tokenLocalDataSource.token).enqueue(object : - Callback { + Callback { override fun onResponse( - call: Call, - response: Response + call: Call, + response: Response ) { if (response.isSuccessful) { _userHobbyState.value = @@ -40,7 +40,7 @@ class MainViewModel @Inject constructor( } override fun onFailure( - call: Call, + call: Call, t: Throwable ) { _userHobbyState.value = UserHobbyState.Failure(t.message.toString())