From caefa364a89243e8eb3240c2b957182e1c603027 Mon Sep 17 00:00:00 2001 From: Satindar Dhillon Date: Thu, 31 Mar 2022 22:02:35 -0700 Subject: [PATCH] add lables to feedItem type --- .../OmnivoreKit/Sources/Models/FeedItem.swift | 9 ++- .../Sources/Models/FeedItemLabel.swift | 23 ++++++ .../Services/DataService/GQLSchema.swift | 78 +++++++++++++++++-- .../Queries/LibraryItemsQuery.swift | 13 +++- 4 files changed, 114 insertions(+), 9 deletions(-) create mode 100644 apple/OmnivoreKit/Sources/Models/FeedItemLabel.swift diff --git a/apple/OmnivoreKit/Sources/Models/FeedItem.swift b/apple/OmnivoreKit/Sources/Models/FeedItem.swift index 30960fbb7..af6a53139 100644 --- a/apple/OmnivoreKit/Sources/Models/FeedItem.swift +++ b/apple/OmnivoreKit/Sources/Models/FeedItem.swift @@ -28,6 +28,7 @@ public struct FeedItem: Identifiable, Hashable, Decodable { public let slug: String public let isArchived: Bool public let contentReader: String? + public let labels: [FeedItemLabel] public init( id: String, @@ -46,7 +47,8 @@ public struct FeedItem: Identifiable, Hashable, Decodable { publishDate: Date?, slug: String, isArchived: Bool, - contentReader: String? + contentReader: String?, + labels: [FeedItemLabel] ) { self.id = id self.title = title @@ -65,10 +67,12 @@ public struct FeedItem: Identifiable, Hashable, Decodable { self.slug = slug self.isArchived = isArchived self.contentReader = contentReader + self.labels = labels } + // swiftlint:disable:next line_length enum CodingKeys: String, CodingKey { - case id, title, createdAt, savedAt, image, isArchived, readingProgressPercent, readingProgressAnchorIndex, slug, contentReader, url + case id, title, createdAt, savedAt, image, isArchived, readingProgressPercent, readingProgressAnchorIndex, slug, contentReader, url, labels } public init(from decoder: Decoder) throws { @@ -85,6 +89,7 @@ public struct FeedItem: Identifiable, Hashable, Decodable { contentReader = try container.decode(String.self, forKey: .contentReader) pageURLString = try container.decode(String.self, forKey: .url) isArchived = try container.decode(Bool.self, forKey: .isArchived) + labels = try container.decode([FeedItemLabel].self, forKey: .labels) self.onDeviceImageURLString = nil self.documentDirectoryPath = nil diff --git a/apple/OmnivoreKit/Sources/Models/FeedItemLabel.swift b/apple/OmnivoreKit/Sources/Models/FeedItemLabel.swift new file mode 100644 index 000000000..14a157a02 --- /dev/null +++ b/apple/OmnivoreKit/Sources/Models/FeedItemLabel.swift @@ -0,0 +1,23 @@ +import Foundation + +public struct FeedItemLabel: Decodable, Hashable { + public let id: String + public let name: String + public let color: String + public let createdAt: Date? + public let description: String? + + public init( + id: String, + name: String, + color: String, + createdAt: Date?, + description: String? + ) { + self.id = id + self.name = name + self.color = color + self.createdAt = createdAt + self.description = description + } +} diff --git a/apple/OmnivoreKit/Sources/Services/DataService/GQLSchema.swift b/apple/OmnivoreKit/Sources/Services/DataService/GQLSchema.swift index 89528dbc1..6f50d6b8b 100644 --- a/apple/OmnivoreKit/Sources/Services/DataService/GQLSchema.swift +++ b/apple/OmnivoreKit/Sources/Services/DataService/GQLSchema.swift @@ -2970,8 +2970,11 @@ extension Objects { let savedByViewer: [String: Bool] let shareInfo: [String: Objects.LinkShareInfo] let sharedComment: [String: String] + let siteIcon: [String: String] + let siteName: [String: String] let slug: [String: String] let title: [String: String] + let uploadFileId: [String: String] let url: [String: String] enum TypeName: String, Codable { @@ -3088,6 +3091,14 @@ extension Objects.Article: Decodable { if let value = try container.decode(String?.self, forKey: codingKey) { map.set(key: field, hash: alias, value: value as Any) } + case "siteIcon": + if let value = try container.decode(String?.self, forKey: codingKey) { + map.set(key: field, hash: alias, value: value as Any) + } + case "siteName": + if let value = try container.decode(String?.self, forKey: codingKey) { + map.set(key: field, hash: alias, value: value as Any) + } case "slug": if let value = try container.decode(String?.self, forKey: codingKey) { map.set(key: field, hash: alias, value: value as Any) @@ -3096,6 +3107,10 @@ extension Objects.Article: Decodable { if let value = try container.decode(String?.self, forKey: codingKey) { map.set(key: field, hash: alias, value: value as Any) } + case "uploadFileId": + if let value = try container.decode(String?.self, forKey: codingKey) { + map.set(key: field, hash: alias, value: value as Any) + } case "url": if let value = try container.decode(String?.self, forKey: codingKey) { map.set(key: field, hash: alias, value: value as Any) @@ -3134,8 +3149,11 @@ extension Objects.Article: Decodable { savedByViewer = map["savedByViewer"] shareInfo = map["shareInfo"] sharedComment = map["sharedComment"] + siteIcon = map["siteIcon"] + siteName = map["siteName"] slug = map["slug"] title = map["title"] + uploadFileId = map["uploadFileId"] url = map["url"] } } @@ -3587,6 +3605,51 @@ extension Fields where TypeLock == Objects.Article { return selection.mock() } } + + func uploadFileId() throws -> String? { + let field = GraphQLField.leaf( + name: "uploadFileId", + arguments: [] + ) + select(field) + + switch response { + case let .decoding(data): + return data.uploadFileId[field.alias!] + case .mocking: + return nil + } + } + + func siteName() throws -> String? { + let field = GraphQLField.leaf( + name: "siteName", + arguments: [] + ) + select(field) + + switch response { + case let .decoding(data): + return data.siteName[field.alias!] + case .mocking: + return nil + } + } + + func siteIcon() throws -> String? { + let field = GraphQLField.leaf( + name: "siteIcon", + arguments: [] + ) + select(field) + + switch response { + case let .decoding(data): + return data.siteIcon[field.alias!] + case .mocking: + return nil + } + } } extension Selection where TypeLock == Never, Type == Never { @@ -10784,7 +10847,7 @@ extension Fields where TypeLock == Objects.Label { } } - func createdAt() throws -> DateTime { + func createdAt() throws -> DateTime? { let field = GraphQLField.leaf( name: "createdAt", arguments: [] @@ -10793,12 +10856,9 @@ extension Fields where TypeLock == Objects.Label { switch response { case let .decoding(data): - if let data = data.createdAt[field.alias!] { - return data - } - throw HttpError.badpayload + return data.createdAt[field.alias!] case .mocking: - return DateTime.mockValue + return nil } } } @@ -16779,6 +16839,10 @@ extension Enums { /// SortBy enum SortBy: String, CaseIterable, Codable { case updatedTime = "UPDATED_TIME" + + case score = "SCORE" + + case savedAt = "SAVED_AT" } } @@ -16956,6 +17020,8 @@ extension Enums { case payloadTooLarge = "PAYLOAD_TOO_LARGE" case uploadFileMissing = "UPLOAD_FILE_MISSING" + + case elasticError = "ELASTIC_ERROR" } } diff --git a/apple/OmnivoreKit/Sources/Services/DataService/Queries/LibraryItemsQuery.swift b/apple/OmnivoreKit/Sources/Services/DataService/Queries/LibraryItemsQuery.swift index 7419e2649..174df3d26 100644 --- a/apple/OmnivoreKit/Sources/Services/DataService/Queries/LibraryItemsQuery.swift +++ b/apple/OmnivoreKit/Sources/Services/DataService/Queries/LibraryItemsQuery.swift @@ -143,7 +143,18 @@ let homeFeedItemSelection = Selection.Article { publishDate: try $0.publishedAt()?.value, slug: try $0.slug(), isArchived: try $0.isArchived(), - contentReader: try $0.contentReader().rawValue + contentReader: try $0.contentReader().rawValue, + labels: try $0.labels(selection: feedItemLabelSelection.list.nullable) ?? [] + ) +} + +private let feedItemLabelSelection = Selection.Label { + FeedItemLabel( + id: try $0.id(), + name: try $0.name(), + color: try $0.color(), + createdAt: try $0.createdAt()?.value, + description: try $0.description() ) }