IceCubesApp/Packages/Models/Sources/Models/Poll.swift
Jérôme Danthinne 9b3b3692ee
Support for follow requests (#376) close #321
* Support for follow requests (#321)

* Run SwiftFormat

Co-authored-by: Thomas Ricouard <ricouard77@gmail.com>
2023-01-25 13:02:28 +01:00

44 lines
1,000 B
Swift

import Foundation
public struct Poll: Codable, Equatable, Hashable {
public static func == (lhs: Poll, rhs: Poll) -> Bool {
lhs.id == rhs.id
}
public func hash(into hasher: inout Hasher) {
hasher.combine(id)
}
public struct Option: Identifiable, Codable {
enum CodingKeys: String, CodingKey {
case title, votesCount
}
public var id = UUID().uuidString
public let title: String
public let votesCount: Int
}
public let id: String
public let expiresAt: NullableString
public let expired: Bool
public let multiple: Bool
public let votesCount: Int
public let voted: Bool?
public let ownVotes: [Int]?
public let options: [Option]
}
public struct NullableString: Codable, Equatable, Hashable {
public let value: String?
public init(from decoder: Decoder) throws {
do {
let container = try decoder.singleValueContainer()
self.value = try container.decode(String.self)
} catch {
self.value = nil
}
}
}