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

feat: 데이타스토어 정비 및 기능 추가 #337

Merged
merged 10 commits into from
Sep 23, 2024
Merged

Conversation

junseo511
Copy link
Member

📌𝘐𝘴𝘴𝘶𝘦𝘴

📎𝘞𝘰𝘳𝘬 𝘋𝘦𝘴𝘤𝘳𝘪𝘱𝘵𝘪𝘰𝘯

  • 기존 데이터스토어를 이전했습니다
  • 데이터스토어 확장함수를 추가했습니다
  • 토큰을 저장할 수 있는 데이터스토어 함수를 추가했습니다

💬𝘛𝘰 𝘙𝘦𝘷𝘪𝘦𝘸𝘦𝘳𝘴

레퍼런스는 드로이드나이츠하고 나우인안드로이드, 오프로드에서 제가 직접 수정한 코드입니다

@junseo511 junseo511 added 🍯 [FEAT] 새로운 기능을 개발합니다. 🔮 법사 준서 아카데미의 천재 마법사 labels Sep 19, 2024
@junseo511 junseo511 requested a review from a team September 19, 2024 14:59
@junseo511 junseo511 self-assigned this Sep 19, 2024
import javax.inject.Named

class UserPreferencesDataSource @Inject constructor(
@Named("userPreferencesDataStore") private val dataStore: DataStore<Preferences>,
Copy link
Member

Choose a reason for hiding this comment

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

a: 우리 dataStore가 여러개인가요??

Copy link
Member Author

Choose a reason for hiding this comment

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

원래 두개를 만들었는데 하나를 지웠습니다!!

Copy link
Member

Choose a reason for hiding this comment

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

그럼 Named 어노테이션은 필요 없을 것 같아요!

@Named("userPreferencesDataStore") private val dataStore: DataStore<Preferences>,
) {

object PreferencesKey {
Copy link
Member

Choose a reason for hiding this comment

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

c: 여기 위치한 이유가 무엇인가요?

Copy link
Member Author

Choose a reason for hiding this comment

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

드나에서 이렇게 쓰더라구요 데이터소스가 직접 키값을 가지고 있는 것도 괜찮다고 생각했습니다!

Copy link
Member

Choose a reason for hiding this comment

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

그럼 동반 객체로 가져가도 좋을 것 같아요~

}

suspend fun fetchAccessToken(): String {
return dataStore.data.first()[PreferencesKey.ACCESS_TOKEN_KEY] ?: ""
Copy link
Member

Choose a reason for hiding this comment

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

c: orEmpty() 어떠심?

Copy link
Member Author

Choose a reason for hiding this comment

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

코틀린스럽고 좋은듯요

@Singleton
@Provides
fun provideUserPreferencesDataStore(@ApplicationContext context: Context): DataStore<Preferences> {
private fun Context.createDataStore(preferencesName: String): DataStore<Preferences> {
Copy link
Member

Choose a reason for hiding this comment

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

c: DataStoreModule에 위치하는건 별로인 것 같아요

)
}

@Singleton
@Provides
@Named("userPreferencesDataStore")
Copy link
Member

Choose a reason for hiding this comment

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

c: Named가 필요한 이유가 무엇인가용

Copy link
Member Author

Choose a reason for hiding this comment

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

데이터스토어 종류가 추가되면 충돌이 발생하더라구요? 그래서 추가했던 것 같습니다 🤔

혹시 하나의 데이터스토어를 모두가 공유해야하나요...?

Copy link
Member

Choose a reason for hiding this comment

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

하나의 데이터스토어밖에 사용하고 있지 않으니 불필요한 어노테이션 같아요

import javax.inject.Inject
import javax.inject.Named

class UserPreferencesDataSource @Inject constructor(
Copy link
Member

Choose a reason for hiding this comment

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

c: 왜 dataSource인가요?

Copy link
Member Author

Choose a reason for hiding this comment

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

이 부분 역시 드나에서 이렇게 사용하더군요! 데이터스토어가 아닌 다른 로컬 저장소로 교체되더라도 네이밍이 바뀌지 않아도 될 것 같아서 괜찮다고 생각해서 채택했습니다 :)

Copy link
Member

Choose a reason for hiding this comment

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

드나나 구글 공식 레포가 정답인것은 아닙니다! 그리고 적어주신 이유는 레포지토리 이름으로도 가능한 내용입니다
특히 클래스명은 팀 컨벤션이니까 적용전에 상의해보는 것도 좋겠습니다 :)

Copy link
Contributor

@m6z1 m6z1 left a comment

Choose a reason for hiding this comment

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

코드 확인했습니다. 그런데 resovled 하려는 이슈와 피알 내용이 다른 것 같아서 다시 수정하셔야 할 것 같아요!

@librarywon
Copy link
Contributor

이슈와 피알 내용이 다른 것은 제가 토큰 관리 쪽을 요청드려서 그런거 같습니다!

@junseo511 junseo511 requested a review from s9hn September 21, 2024 15:21
import javax.inject.Inject

class UserRepository @Inject constructor(
private val userApi: UserApi,
private val dataStore: DataStore<Preferences>,
Copy link
Member

Choose a reason for hiding this comment

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

r: 않이. 이전에도 비슷한 리뷰 남긴것 같은데.... 공식문서에서도 구현체를 밝히는 네이밍은 권장하지 않아요 :(

…o feat/321

# Conflicts:
#	app/src/main/java/com/teamwss/websoso/common/util/ExtentionFuction.kt
Copy link
Contributor

@librarywon librarywon left a comment

Choose a reason for hiding this comment

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

고생하셨습니다

@junseo511 junseo511 merged commit 903ed12 into develop Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍯 [FEAT] 새로운 기능을 개발합니다. 🔮 법사 준서 아카데미의 천재 마법사
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: 데이타스토어 정비 및 기능 추가
4 participants