From de9d3e5bc64bd90afcdeb4c096b73a70473c944d Mon Sep 17 00:00:00 2001 From: GeonH0 Date: Tue, 4 Jun 2024 19:54:32 +0900 Subject: [PATCH] =?UTF-8?q?FIx:=20Data=EB=A5=BC=20Entity=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=ED=99=98=ED=95=98=EB=8A=94=20=EA=B3=BC=EC=A0=95?= =?UTF-8?q?=EC=9D=84=20=EB=A9=94=EC=84=9C=EB=93=9C=EB=A1=9C=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Data/FirebaseRemoteDataSource.swift | 37 ++++++++----------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/HomeCafeRecipes/HomeCafeRecipes/Data/FirebaseRemoteDataSource.swift b/HomeCafeRecipes/HomeCafeRecipes/Data/FirebaseRemoteDataSource.swift index e7ddf94..7acfd08 100644 --- a/HomeCafeRecipes/HomeCafeRecipes/Data/FirebaseRemoteDataSource.swift +++ b/HomeCafeRecipes/HomeCafeRecipes/Data/FirebaseRemoteDataSource.swift @@ -20,17 +20,7 @@ class FirebaseRemoteDataSource { completion(.success([])) return } - let feedItems = documents.compactMap { doc -> FeedItem? in - let data = doc.data() - guard - let id = data["id"] as? String, - let title = data["title"] as? String, - let imageURLs = data["imageURLs"] as? [String] else { - return nil - } - return FeedItem(id: id, title: title, imageURLs: imageURLs) - - } + let feedItems = self.convertToFeedItems(documents) completion(.success(feedItems)) } } @@ -48,19 +38,24 @@ class FirebaseRemoteDataSource { completion(.success([])) return } - let feedItems = documents.compactMap { doc -> FeedItem? in - let data = doc.data() - guard - let id = data["id"] as? String, - let title = data["title"] as? String, - let imageURLs = data["imageURLs"] as? [String] else { - return nil - } - return FeedItem(id: id, title: title, imageURLs: imageURLs) - } + + let feedItems = self.convertToFeedItems(documents) completion(.success(feedItems)) } } + + private func convertToFeedItems(_ documents: [QueryDocumentSnapshot]) -> [FeedItem] { + return documents.compactMap { doc -> FeedItem? in + let data = doc.data() + guard + let id = data["id"] as? String, + let title = data["title"] as? String, + let imageURLs = data["imageURLs"] as? [String] else { + return nil + } + return FeedItem(id: id, title: title, imageURLs: imageURLs) + } + } }