Skip to content

Commit

Permalink
[CHORE] #105 : 불필요한 스코프 소거
Browse files Browse the repository at this point in the history
  • Loading branch information
tgyuuAn committed Jan 17, 2024
1 parent a5e9a19 commit eef2117
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,15 @@ import javax.inject.Inject
class AuthDataSourceImpl @Inject constructor(
private val firebaseAuth: FirebaseAuth,
) : AuthDataSource {
override suspend fun signOut(): Result<Unit> {
return runCatching {
firebaseAuth.signOut()
}
override suspend fun signOut(): Result<Unit> = runCatching {
firebaseAuth.signOut()
}

override suspend fun deleteUser(): Result<Unit> {
return runCatching {
val user = checkNotNull(firebaseAuth.currentUser)
override suspend fun deleteUser(): Result<Unit> = runCatching {
val user = checkNotNull(firebaseAuth.currentUser)

user.delete()
.await()
}
user.delete()
.await()
}

@OptIn(ExperimentalCoroutinesApi::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,18 @@ class SignInDataSourceImpl @Inject constructor(
private val firebaseAuth: FirebaseAuth,
@ActivityContext private val context: Context,
) : SignInDataSource {
override suspend fun signIn(email: String): Result<String> =
runCatching {
val provider = OAuthProvider.newBuilder("github.com")
provider.addCustomParameter("login", email)
override suspend fun signIn(email: String): Result<String> = runCatching {
val provider = OAuthProvider.newBuilder("github.com")
provider.addCustomParameter("login", email)

val activityContext = context as Activity
val activityContext = context as Activity

val result = firebaseAuth.startActivityForSignInWithProvider(
activityContext,
provider.build(),
).await()
val result = firebaseAuth.startActivityForSignInWithProvider(
activityContext,
provider.build(),
).await()

val user = checkNotNull(result.user)
user.uid
}
val user = checkNotNull(result.user)
user.uid
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,14 @@ class EventDataSourceImpl @Inject constructor(
result
}

override suspend fun getEvent(eventId: String): Result<EventResponse> =
runCatching {
val document = firebaseFirestore.collection(EVENT_COLLECTION)
.document(eventId)
.get()
.await()
override suspend fun getEvent(eventId: String): Result<EventResponse> = runCatching {
val document = firebaseFirestore.collection(EVENT_COLLECTION)
.document(eventId)
.get()
.await()

checkNotNull(document.toObject<EventResponse>())
}
checkNotNull(document.toObject<EventResponse>())
}

override suspend fun deleteEvent(eventId: String): Result<Unit> = runCatching {
firebaseFirestore.collection(EVENT_COLLECTION)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,26 @@ class SurveyDataSourceImpl @Inject constructor(
result
}

override suspend fun getSurveyListBySurveyFormId(surveyFormId: String)
: Result<List<SurveyResponse>> =
runCatching {
val result: MutableList<SurveyResponse> = mutableListOf()

val task = firebaseFirestore.collection(SURVEY_COLLECTION)
.whereEqualTo("surveyFormId", surveyFormId)
.get()
.await()
override suspend fun getSurveyListBySurveyFormId(
surveyFormId: String,
): Result<List<SurveyResponse>> = runCatching {
val result: MutableList<SurveyResponse> = mutableListOf()

for (document in task.documents) {
val surveyResponse = document.toObject(SurveyResponse::class.java)
checkNotNull(surveyResponse)
val task = firebaseFirestore.collection(SURVEY_COLLECTION)
.whereEqualTo("surveyFormId", surveyFormId)
.get()
.await()

result.add(surveyResponse)
}
for (document in task.documents) {
val surveyResponse = document.toObject(SurveyResponse::class.java)
checkNotNull(surveyResponse)

result
result.add(surveyResponse)
}

result
}

override suspend fun getUserRespondedSurveyList(userId: String): Result<List<SurveyResponse>> =
runCatching {
val result: MutableList<SurveyResponse> = mutableListOf()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,24 @@ class SurveyFormDataSourceImpl @Inject constructor(

override suspend fun getSurveyFormListByEventId(
eventId: String,
): Result<List<SurveyFormResponse>> =
runCatching {
val result: MutableList<SurveyFormResponse> = mutableListOf()

val task = firebaseFirestore.collection(SURVEY_FORM_COLLECTION)
.whereEqualTo("eventId", eventId)
.get()
.await()
): Result<List<SurveyFormResponse>> = runCatching {
val result: MutableList<SurveyFormResponse> = mutableListOf()

for (document in task.documents) {
val surveyFormResponse = document.toObject(SurveyFormResponse::class.java)
checkNotNull(surveyFormResponse)
val task = firebaseFirestore.collection(SURVEY_FORM_COLLECTION)
.whereEqualTo("eventId", eventId)
.get()
.await()

result.add(surveyFormResponse)
}
for (document in task.documents) {
val surveyFormResponse = document.toObject(SurveyFormResponse::class.java)
checkNotNull(surveyFormResponse)

result
result.add(surveyFormResponse)
}

result
}

override suspend fun deleteSurveyForm(surveyFormId: String): Result<Unit> = runCatching {
firebaseFirestore.collection(SURVEY_FORM_COLLECTION)
.document(surveyFormId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,33 @@ class UserDataSourceImpl @Inject constructor(
) : UserDataSource {
override suspend fun postUserProfile(
userProfileRequest: UserProfileRequest,
): Result<Unit> {
return runCatching {
val userId = userProfileRequest.userId
val setOption = SetOptions.merge()
): Result<Unit> = runCatching {
val userId = userProfileRequest.userId
val setOption = SetOptions.merge()

firebaseFirestore.collection(USER_COLLECTION)
.document(userId)
.set(
userProfileRequest,
setOption,
)
.await()
}
firebaseFirestore.collection(USER_COLLECTION)
.document(userId)
.set(
userProfileRequest,
setOption,
)
.await()
}

override suspend fun getUserId(): Result<String> {
return runCatching {
checkNotNull(firebaseAuth.uid)
}
override suspend fun getUserId(): Result<String> = runCatching {
checkNotNull(firebaseAuth.uid)
}

override suspend fun getUserProfile(
userId: String,
): Result<UserProfileResponse> {
return runCatching {
val result = firebaseFirestore.collection(USER_COLLECTION)
.document(userId)
.get()
.await()
): Result<UserProfileResponse> = runCatching {
val result = firebaseFirestore.collection(USER_COLLECTION)
.document(userId)
.get()
.await()

val userProfile = result.toObject(UserProfileResponse::class.java)
checkNotNull(userProfile)
}
val userProfile = result.toObject(UserProfileResponse::class.java)
checkNotNull(userProfile)
}

override suspend fun deleteUserProfile(userId: String): Result<Unit> = runCatching {
Expand Down

0 comments on commit eef2117

Please sign in to comment.