Skip to content

Commit 7e7c002

Browse files
committed
♻️ 반복되는 코드 함수로 분리
1 parent 5f3fb03 commit 7e7c002

File tree

1 file changed

+31
-21
lines changed

1 file changed

+31
-21
lines changed

data/src/main/java/com/whyranoid/data/post/PostDataSourceImpl.kt

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -262,19 +262,10 @@ class PostDataSourceImpl @Inject constructor(
262262
override suspend fun convertPostType(document: QueryDocumentSnapshot): Post? {
263263
return if (document[RUNNING_HISTORY_ID] != null) {
264264
document.toObject(RunningPostResponse::class.java).let { postResponse ->
265-
val authorResponse = db.collection(CollectionId.USERS_COLLECTION)
266-
.document(postResponse.authorId)
267-
.get()
268-
.await()
269-
.toObject(UserResponse::class.java)
265+
val authorResponse = getUserResponse(postResponse.authorId)
270266

271267
authorResponse?.let {
272-
val runningHistory =
273-
db.collection(CollectionId.RUNNING_HISTORY_COLLECTION)
274-
.document(postResponse.runningHistoryId)
275-
.get()
276-
.await()
277-
.toObject(RunningHistory::class.java)
268+
val runningHistory = getRunningHistory(postResponse.runningHistoryId)
278269

279270
runningHistory?.let {
280271
RunningPost(
@@ -290,18 +281,10 @@ class PostDataSourceImpl @Inject constructor(
290281
}
291282
} else {
292283
document.toObject(RecruitPostResponse::class.java).let { postResponse ->
293-
val authorResponse = db.collection(CollectionId.USERS_COLLECTION)
294-
.document(postResponse.authorId)
295-
.get()
296-
.await()
297-
.toObject(UserResponse::class.java)
284+
val authorResponse = getUserResponse(postResponse.authorId)
298285

299286
authorResponse?.let {
300-
val groupInfoResponse = db.collection(CollectionId.GROUPS_COLLECTION)
301-
.document(postResponse.groupId)
302-
.get()
303-
.await()
304-
.toObject(GroupInfoResponse::class.java)
287+
val groupInfoResponse = getGroupInfoResponse(postResponse.groupId)
305288

306289
groupInfoResponse?.let {
307290
val author = authorResponse.toUser()
@@ -415,6 +398,33 @@ class PostDataSourceImpl @Inject constructor(
415398
}
416399
}
417400

401+
// TODO : 예외 처리
402+
private suspend fun getUserResponse(userId: String): UserResponse? {
403+
return db.collection(CollectionId.USERS_COLLECTION)
404+
.document(userId)
405+
.get()
406+
.await()
407+
.toObject(UserResponse::class.java)
408+
}
409+
410+
// TODO : 예외 처리
411+
private suspend fun getRunningHistory(runningHistoryId: String): RunningHistory? {
412+
return db.collection(CollectionId.RUNNING_HISTORY_COLLECTION)
413+
.document(runningHistoryId)
414+
.get()
415+
.await()
416+
.toObject(RunningHistory::class.java)
417+
}
418+
419+
// TODO : 예외 처리
420+
private suspend fun getGroupInfoResponse(groupId: String): GroupInfoResponse? {
421+
return db.collection(CollectionId.GROUPS_COLLECTION)
422+
.document(groupId)
423+
.get()
424+
.await()
425+
.toObject(GroupInfoResponse::class.java)
426+
}
427+
418428
companion object {
419429
private const val DATA_COUNT_PER_PAGE = 10L
420430
}

0 commit comments

Comments
 (0)