@@ -262,19 +262,10 @@ class PostDataSourceImpl @Inject constructor(
262
262
override suspend fun convertPostType (document : QueryDocumentSnapshot ): Post ? {
263
263
return if (document[RUNNING_HISTORY_ID ] != null ) {
264
264
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)
270
266
271
267
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)
278
269
279
270
runningHistory?.let {
280
271
RunningPost (
@@ -290,18 +281,10 @@ class PostDataSourceImpl @Inject constructor(
290
281
}
291
282
} else {
292
283
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)
298
285
299
286
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)
305
288
306
289
groupInfoResponse?.let {
307
290
val author = authorResponse.toUser()
@@ -415,6 +398,33 @@ class PostDataSourceImpl @Inject constructor(
415
398
}
416
399
}
417
400
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
+
418
428
companion object {
419
429
private const val DATA_COUNT_PER_PAGE = 10L
420
430
}
0 commit comments