Skip to content

Commit

Permalink
[feat/#10] api 5개를 위한 service와 model을 정의합니다.
Browse files Browse the repository at this point in the history
  • Loading branch information
SYAAINN committed Dec 2, 2024
1 parent cf30390 commit 935d201
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sopt.and.data.local
package org.sopt.and.data.local.datasource

interface TokenLocalDataSource {
var token: String
Expand Down
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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?
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class GetMyHobbyResponseDto(
data class HobbyResponseDto(
@SerialName("hobby") val hobby: String
)
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -12,10 +13,10 @@ interface AuthService {
@POST("user")
fun registerUser(
@Body userRegistrationRequestDto: UserRegistrationRequestDto
): Call<UserRegistrationResponseDto>
): ApiResponse<UserRegistrationResponseDto>

@POST("login")
fun login(
@Body loginRequestDto: LoginRequestDto
): Call<LoginResponseDto>
): ApiResponse<LoginResponseDto>
}
22 changes: 19 additions & 3 deletions app/src/main/java/org/sopt/and/data/remote/service/UserService.kt
Original file line number Diff line number Diff line change
@@ -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<GetMyHobbyResponseDto>
): ApiResponse<HobbyResponseDto>

@GET("user/{no}/hobby")
fun getOthersHobby(
@Header("token") token: String,
@Path("no") userNo: Int
): ApiResponse<HobbyResponseDto>

@PUT("user")
fun updateUserInfo(
@Header("token") token: String,
@Body userInfoUpdateRequestDto: UserInfoUpdateRequestDto
): ApiResponse<Unit>
}
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/org/sopt/and/di/TokenDataStoreModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,10 +26,10 @@ class MainViewModel @Inject constructor(
fun getUserHobby() {
viewModelScope.launch {
userService.getMyHobby(token = tokenLocalDataSource.token).enqueue(object :
Callback<GetMyHobbyResponseDto> {
Callback<HobbyResponseDto> {
override fun onResponse(
call: Call<GetMyHobbyResponseDto>,
response: Response<GetMyHobbyResponseDto>
call: Call<HobbyResponseDto>,
response: Response<HobbyResponseDto>
) {
if (response.isSuccessful) {
_userHobbyState.value =
Expand All @@ -40,7 +40,7 @@ class MainViewModel @Inject constructor(
}

override fun onFailure(
call: Call<GetMyHobbyResponseDto>,
call: Call<HobbyResponseDto>,
t: Throwable
) {
_userHobbyState.value = UserHobbyState.Failure(t.message.toString())
Expand Down

0 comments on commit 935d201

Please sign in to comment.