diff --git a/app/src/main/java/org/sopt/and/data/UserRepository.kt b/app/src/main/java/org/sopt/and/data/UserRepository.kt index 97f9f36..dad6db1 100644 --- a/app/src/main/java/org/sopt/and/data/UserRepository.kt +++ b/app/src/main/java/org/sopt/and/data/UserRepository.kt @@ -1,22 +1,45 @@ package org.sopt.and.data import android.content.Context +import org.sopt.and.network.UserService +import org.sopt.and.network.request.RequestLoginDto +import org.sopt.and.network.request.RequestSignUpDto +import org.sopt.and.network.response.ResponseDto +import org.sopt.and.network.response.ResponseHobbyDto +import retrofit2.Response -class UserRepository(context: Context) { +class UserRepository( + private val userService: UserService, + context: Context) { private val dataSource = DataSource(context.getSharedPreferences("UserPrefs", Context.MODE_PRIVATE)) - fun saveUserInfo(email: String, password: String) { - dataSource.saveUserInfo(email, password) + suspend fun postSignUp(username: String, password: String, hobby: String): Response { + val request = RequestSignUpDto(username, password, hobby) + return userService.postSignUp(request) } - fun getEmail(): String? { - return dataSource.getEmail() + suspend fun postLogin(username: String, password: String): Response { + val request = RequestLoginDto(username, password) + return userService.postLogin(request) } - fun getPassword(): String? { - return dataSource.getPassword() + suspend fun getHobby(token: String): Response { + return userService.getHobby(token) } + fun saveUserInfo(username: String, password: String, hobby: String) { + dataSource.saveUserInfo(username, password, hobby) + } + + fun saveUserToken(token: String) { + dataSource.saveUserToken(token) + } + + fun getUsername(): String? = dataSource.getUsername() + fun getPassword(): String? = dataSource.getPassword() + fun getHobby(): String? = dataSource.getHobby() + fun getToken(): String? = dataSource.getToken() + fun isLoggedIn(): Boolean { return dataSource.isLoggedIn() } @@ -24,4 +47,5 @@ class UserRepository(context: Context) { fun logout() { dataSource.clearUserCredentials() } + }