IceCubesApp/Packages/Network/Sources/Network/Endpoint/Polls.swift

30 lines
583 B
Swift
Raw Normal View History

2022-12-28 09:08:41 +00:00
import Foundation
public enum Polls: Endpoint {
case poll(id: String)
case vote(id: String, votes: [Int])
2023-01-17 10:36:01 +00:00
2022-12-28 09:08:41 +00:00
public func path() -> String {
switch self {
2023-01-17 10:36:01 +00:00
case let .poll(id):
2022-12-28 09:08:41 +00:00
return "polls/\(id)/"
2023-01-17 10:36:01 +00:00
case let .vote(id, _):
2022-12-28 09:08:41 +00:00
return "polls/\(id)/votes"
}
}
2023-01-17 10:36:01 +00:00
2022-12-28 09:08:41 +00:00
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
2023-01-17 10:36:01 +00:00
2022-12-28 09:08:41 +00:00
default:
return nil
}
}
}