generated from AND-SOPT-ANDROID/and-sopt-android-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
31 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,51 @@ | ||
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<ResponseDto> { | ||
val request = RequestSignUpDto(username, password, hobby) | ||
return userService.postSignUp(request) | ||
} | ||
|
||
fun getEmail(): String? { | ||
return dataSource.getEmail() | ||
suspend fun postLogin(username: String, password: String): Response<ResponseDto> { | ||
val request = RequestLoginDto(username, password) | ||
return userService.postLogin(request) | ||
} | ||
|
||
fun getPassword(): String? { | ||
return dataSource.getPassword() | ||
suspend fun getHobby(token: String): Response<ResponseHobbyDto> { | ||
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() | ||
} | ||
|
||
fun logout() { | ||
dataSource.clearUserCredentials() | ||
} | ||
|
||
} |