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/#38] 클린 적용 #39

Open
wants to merge 26 commits into
base: develop-compose
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions app/src/main/java/com/sopt/now/compose/data/User.kt

This file was deleted.

48 changes: 0 additions & 48 deletions app/src/main/java/com/sopt/now/compose/data/UserLocalDataSource.kt

This file was deleted.

This file was deleted.

21 changes: 0 additions & 21 deletions app/src/main/java/com/sopt/now/compose/data/UserRepository.kt

This file was deleted.

54 changes: 0 additions & 54 deletions app/src/main/java/com/sopt/now/compose/data/UserRepositoryImpl.kt

This file was deleted.

11 changes: 11 additions & 0 deletions app/src/main/java/com/sopt/now/compose/data/local/UserDataStore.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.sopt.now.compose.data.local

interface UserDataStore {
var userId: String
var id: String
var password: String
var nickname: String
var phoneNumber: String
var isLoggedIn: Boolean
fun clearInfo()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.sopt.now.compose.data.local

import android.content.SharedPreferences
import androidx.core.content.edit
import javax.inject.Inject

class UserDataStoreImpl @Inject constructor(
private val dataStore: SharedPreferences,
) : UserDataStore {
override var userId: String
get() = dataStore.getString(USER_ID, "").orEmpty()
set(value) = dataStore.edit { putString(USER_ID, value) }

override var id: String
get() = dataStore.getString(ID, "").orEmpty()
set(value) = dataStore.edit { putString(ID, value) }

override var password: String
get() = dataStore.getString(PASSWORD, "").orEmpty()
set(value) = dataStore.edit { putString(PASSWORD, value) }

override var nickname: String
get() = dataStore.getString(NICKNAME, "").orEmpty()
set(value) = dataStore.edit { putString(NICKNAME, value) }

override var phoneNumber: String
get() = dataStore.getString(PHONE_NUMBER, "").orEmpty()
set(value) = dataStore.edit { putString(PHONE_NUMBER, value) }

override var isLoggedIn: Boolean
get() = dataStore.getBoolean(IS_LOGGED_IN, false)
set(value) = dataStore.edit { putBoolean(IS_LOGGED_IN, value) }


override fun clearInfo() {
dataStore.edit().clear().commit()
}

companion object {
private const val USER_ID = "userId"
private const val ID = "id"
private const val PASSWORD = "password"
private const val NICKNAME = "nickname"
private const val PHONE_NUMBER = "phoneNumber"
private const val IS_LOGGED_IN = "isLoggedIn"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.sopt.now.compose.data.remote.datasource

import com.sopt.now.compose.data.remote.response.BaseResponseWithoutDataDto
import com.sopt.now.compose.domain.entity.request.RequestChangePasswordEntity
import com.sopt.now.compose.domain.entity.request.RequestSignInEntity
import com.sopt.now.compose.domain.entity.request.RequestUserEntity
import retrofit2.Response

interface AuthDataSource {
suspend fun postSignUp(user: RequestUserEntity): Response<BaseResponseWithoutDataDto>

suspend fun postSignIn(user: RequestSignInEntity): Response<BaseResponseWithoutDataDto>

suspend fun postChangePassword(user: RequestChangePasswordEntity): Response<BaseResponseWithoutDataDto>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.sopt.now.compose.data.remote.datasource

import com.sopt.now.compose.data.remote.response.BaseResponseDto
import com.sopt.now.compose.data.remote.response.ResponseUserDto

interface MypageDataSource {
suspend fun getUserInfo(): BaseResponseDto<ResponseUserDto>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.sopt.now.compose.data.remote.datasourceImpl

import com.sopt.now.compose.data.remote.datasource.AuthDataSource
import com.sopt.now.compose.data.remote.response.BaseResponseWithoutDataDto
import com.sopt.now.compose.data.remote.service.AuthService
import com.sopt.now.compose.domain.entity.request.RequestChangePasswordEntity
import com.sopt.now.compose.domain.entity.request.RequestSignInEntity
import com.sopt.now.compose.domain.entity.request.RequestUserEntity
import retrofit2.Response
import javax.inject.Inject

class AuthDataSourceImpl @Inject constructor(
private val authService: AuthService
) : AuthDataSource {
override suspend fun postSignUp(user: RequestUserEntity): Response<BaseResponseWithoutDataDto> =
authService.postSignUp(user)

override suspend fun postSignIn(user: RequestSignInEntity): Response<BaseResponseWithoutDataDto> =
authService.postSignIn(user)

override suspend fun postChangePassword(user: RequestChangePasswordEntity): Response<BaseResponseWithoutDataDto> =
authService.postChangePassword(user)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.sopt.now.compose.data.remote.datasourceImpl

import com.sopt.now.compose.data.remote.datasource.MypageDataSource
import com.sopt.now.compose.data.remote.response.BaseResponseDto
import com.sopt.now.compose.data.remote.response.ResponseUserDto
import com.sopt.now.compose.data.remote.service.MypageService
import javax.inject.Inject

class MypageDataSourceImpl @Inject constructor(
private val maypageService: MypageService,
) : MypageDataSource {
override suspend fun getUserInfo(): BaseResponseDto<ResponseUserDto> = maypageService.getUserInfo()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.sopt.now.compose.data.remote.repositoryImpl

import com.sopt.now.compose.data.local.UserDataStore
import com.sopt.now.compose.data.remote.datasource.AuthDataSource
import com.sopt.now.compose.data.remote.response.BaseResponseWithoutDataDto
import com.sopt.now.compose.domain.entity.request.RequestChangePasswordEntity
import com.sopt.now.compose.domain.entity.request.RequestSignInEntity
import com.sopt.now.compose.domain.entity.request.RequestUserEntity
import com.sopt.now.compose.domain.repository.AuthRepository
import retrofit2.Response
import javax.inject.Inject

class AuthRepositoryImpl @Inject constructor(
private val authDataSource: AuthDataSource,
private val userDataStore: UserDataStore
) : AuthRepository {
override suspend fun signup(user: RequestUserEntity): Result<Response<BaseResponseWithoutDataDto>> =
runCatching {
authDataSource.postSignUp(user)
}

override suspend fun login(user: RequestSignInEntity): Result<Response<BaseResponseWithoutDataDto>> =
runCatching {
authDataSource.postSignIn(user)
}

override suspend fun changePassword(user: RequestChangePasswordEntity): Result<Response<BaseResponseWithoutDataDto>> =
runCatching {
authDataSource.postChangePassword(user)
}

override fun getId() = userDataStore.id
override fun getPassword() = userDataStore.password
override fun getNickname() = userDataStore.nickname
override fun getPhoneNumber() = userDataStore.phoneNumber
override fun setId(id: String) {
userDataStore.id = id
}

override fun setPassword(password: String) {
userDataStore.password = password
}

override fun setNickname(nickname: String) {
userDataStore.nickname = nickname
}

override fun setPhoneNumber(phoneNumber: String) {
userDataStore.phoneNumber = phoneNumber
}

override fun setUserId(userId: String) {
userDataStore.userId = userId
}

override fun setUserLoggedIn(loggedIn: Boolean) {
userDataStore.isLoggedIn = loggedIn
}

override fun clearInfo() {
userDataStore.clearInfo()
}

companion object {
const val HEADER = "location"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.sopt.now.compose.data.remote.repositoryImpl

import com.sopt.now.compose.data.remote.datasource.MypageDataSource
import com.sopt.now.compose.data.remote.response.toResponseUserInfo
import com.sopt.now.compose.domain.entity.response.ResponseUserInfo
import com.sopt.now.compose.domain.repository.MypageRepository
import javax.inject.Inject

class MypageRepositoryImpl @Inject constructor(
private val mypageDataSource: MypageDataSource
) : MypageRepository {
override suspend fun getUserInfo(): Result<ResponseUserInfo> =
runCatching {
mypageDataSource.getUserInfo().data.toResponseUserInfo()
}
}
Loading