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

31 lines
808 B
Swift
Raw Normal View History

2022-12-27 06:51:44 +00:00
import Foundation
public enum Search: Endpoint {
case search(query: String, type: String?, offset: Int?, following: Bool?)
2023-01-17 10:36:01 +00:00
2022-12-27 06:51:44 +00:00
public func path() -> String {
switch self {
case .search:
return "search"
}
}
2023-01-17 10:36:01 +00:00
2022-12-27 06:51:44 +00:00
public func queryItems() -> [URLQueryItem]? {
switch self {
case let .search(query, type, offset, following):
2022-12-27 06:51:44 +00:00
var params: [URLQueryItem] = [.init(name: "q", value: query)]
if let type {
params.append(.init(name: "type", value: type))
}
if let offset {
params.append(.init(name: "offset", value: String(offset)))
}
if let following {
2023-01-17 10:36:01 +00:00
params.append(.init(name: "following", value: following ? "true" : "false"))
}
params.append(.init(name: "resolve", value: "true"))
2022-12-27 06:51:44 +00:00
return params
}
}
}