IceCubesApp/Packages/Network/Sources/Network/Endpoint/Polls.swift
Thomas Ricouard 7f6419ebae Swiftformat
2023-01-17 11:36:01 +01:00

30 lines
583 B
Swift

import Foundation
public enum Polls: Endpoint {
case poll(id: String)
case vote(id: String, votes: [Int])
public func path() -> String {
switch self {
case let .poll(id):
return "polls/\(id)/"
case let .vote(id, _):
return "polls/\(id)/votes"
}
}
public func queryItems() -> [URLQueryItem]? {
switch self {
case let .vote(_, votes):
var params: [URLQueryItem] = []
for vote in votes {
params.append(.init(name: "choices[]", value: "\(vote)"))
}
return params
default:
return nil
}
}
}