parent
d003098146
commit
b21703f6d9
|
@ -24,6 +24,20 @@ public struct Poll: Codable, Sendable {
|
|||
expired || (expiresAt != nil && expiresAt! < Date())
|
||||
}
|
||||
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
self.id = try container.decode(String.self, forKey: .id)
|
||||
self.expiresAt = try container.decodeIfPresent(Date.self, forKey: .expiresAt)
|
||||
self.expired = try container.decode(Bool.self, forKey: .expired)
|
||||
self.multiple = try container.decode(Bool.self, forKey: .multiple)
|
||||
self.votesCount = try container.decode(Int.self, forKey: .votesCount)
|
||||
self.votersCount = try container.decodeIfPresent(Int.self, forKey: .votersCount)
|
||||
self.voted = try container.decodeIfPresent(Bool.self, forKey: .voted)
|
||||
self.ownVotes = try container.decodeIfPresent([Int].self, forKey: .ownVotes)
|
||||
self.options = try container.decode([Poll.Option].self, forKey: .options)
|
||||
self.emojis = try container.decodeIfPresent([Emoji].self, forKey: .emojis) ?? []
|
||||
}
|
||||
|
||||
public static func vote(_ pollID: String, choices: [Int]) -> Request<Poll> {
|
||||
return Request<Poll>(method: .post, path: "/api/v1/polls/\(pollID)/votes", body: FormDataBody("choices" => choices, nil))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue