Skip to content

Commit

Permalink
FIx: Data를 Entity로 변환하는 과정을 메서드로 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
GeonH0 committed Jun 4, 2024
1 parent 9c2e460 commit de9d3e5
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions HomeCafeRecipes/HomeCafeRecipes/Data/FirebaseRemoteDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
Expand All @@ -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)
}
}

}

Expand Down

0 comments on commit de9d3e5

Please sign in to comment.