Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature/#7 week04] #8

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from
38 changes: 31 additions & 7 deletions app/src/main/java/org/sopt/and/data/UserRepository.kt
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)
}
Comment on lines +16 to 19
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이렇게 간단하게 api 요청 코드를 작성할 수 있군요! 배워갑니당


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()
}

}