Skip to content

Instantly share code, notes, and snippets.

@YannisDC
Last active November 7, 2020 18:38
Show Gist options
  • Save YannisDC/2ff574a127ab1401b01e10eb69d53f08 to your computer and use it in GitHub Desktop.
Save YannisDC/2ff574a127ab1401b01e10eb69d53f08 to your computer and use it in GitHub Desktop.
grpc workaround
import Foundation
struct StringValue: Codable {
var stringValue: String?
}
struct IntValue: Codable {
var integerValue: String?
}
struct Values: Codable {
var values: [StringValue]?
}
struct ArrayValue: Codable {
var arrayValue: Values?
}
struct grpcObject: Codable {
var name: String
var fields: Fields
var createTime: String
var updateTime: String
struct Fields: Codable {
var longDescription: StringValue?
var artist: StringValue?
var year: IntValue?
var id: StringValue?
var owner: StringValue?
var images: ArrayValue?
var shortDescription: StringValue?
var title: StringValue?
var image: StringValue?
var dimensions: DimensionsMapValue?
var construction: ConstructionMapValue?
}
struct DimensionsMapValue: Codable {
var mapValue: DimensionFields?
}
struct DimensionFields: Codable {
var fields: DimensionFieldsValues?
struct DimensionFieldsValues: Codable {
var depth: IntValue
var width: IntValue
var length: IntValue
}
}
struct ConstructionMapValue: Codable {
var mapValue: ConstructionFields?
}
struct ConstructionFields: Codable {
var fields: ConstructionFieldsValues?
struct ConstructionFieldsValues: Codable {
var materials: ArrayValue?
var type: StringValue
}
}
var object: Object {
Object(id: id,
owner: owner,
coverImage: image,
title: title,
artist: artist,
year: year,
images: images,
shortDescription: shortDescription,
longDescription: longDescription,
construction: nil,
dimensions: nil)
}
var id: String {
fields.id?.stringValue ?? ""
}
var owner: String {
fields.owner?.stringValue ?? ""
}
var image: String {
fields.image?.stringValue ?? ""
}
var title: String {
fields.title?.stringValue ?? ""
}
var artist: String {
fields.artist?.stringValue ?? ""
}
var year: Int? {
Int(fields.year?.integerValue ?? "")
}
var images: [String] {
fields.images?.arrayValue?.values?.compactMap { $0.stringValue } ?? [String]()
}
var shortDescription: String {
fields.shortDescription?.stringValue ?? ""
}
var longDescription: String {
fields.longDescription?.stringValue ?? ""
}
}
struct grpcCollection: Codable {
var name: String
var fields: Fields
var createTime: String
var updateTime: String
struct Fields: Codable {
var longDescription: StringValue?
var shortDescription: StringValue?
var id: StringValue
var name: StringValue
var image: StringValue
var owner: StringValue
var objectIds: ArrayValue?
}
var collection: Collection {
Collection(id: id,
owner: owner,
coverImage: image,
name: objectName,
shortDescription: shortDescription,
longDescription: longDescription,
objectIds: objectIds)
}
var id: String {
fields.id.stringValue ?? ""
}
var owner: String {
fields.owner.stringValue ?? ""
}
var image: String {
fields.image.stringValue ?? ""
}
var objectName: String {
fields.name.stringValue ?? ""
}
var shortDescription: String {
fields.shortDescription?.stringValue ?? ""
}
var longDescription: String {
fields.longDescription?.stringValue ?? ""
}
var objectIds: [String] {
fields.objectIds?.arrayValue?.values?.compactMap { $0.stringValue } ?? [String]()
}
}
struct grpcObjectResult: Codable {
var document: grpcObject
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment