Skip to content

Commit

Permalink
#7 Feature: UserRepository
Browse files Browse the repository at this point in the history
  • Loading branch information
0se0 committed Nov 14, 2024
1 parent c9c6566 commit d2cc362
Showing 1 changed file with 31 additions and 7 deletions.
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)
}

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

}

0 comments on commit d2cc362

Please sign in to comment.