51 lines
1.3 KiB
Swift
51 lines
1.3 KiB
Swift
import Foundation
|
|
|
|
import Moya
|
|
|
|
enum PushNotificationApi {
|
|
case getPushNotificationCategories
|
|
case getPushNotificationList(page: Int, size: Int, category: String?)
|
|
}
|
|
|
|
extension PushNotificationApi: TargetType {
|
|
var baseURL: URL {
|
|
URL(string: BASE_URL)!
|
|
}
|
|
|
|
var path: String {
|
|
switch self {
|
|
case .getPushNotificationCategories:
|
|
return "/push/notification/categories"
|
|
case .getPushNotificationList:
|
|
return "/push/notification/list"
|
|
}
|
|
}
|
|
|
|
var method: Moya.Method {
|
|
.get
|
|
}
|
|
|
|
var task: Task {
|
|
switch self {
|
|
case .getPushNotificationCategories:
|
|
return .requestPlain
|
|
|
|
case .getPushNotificationList(let page, let size, let category):
|
|
var parameters: [String: Any] = [
|
|
"page": max(0, page - 1),
|
|
"size": size
|
|
]
|
|
|
|
if let category = category?.trimmingCharacters(in: .whitespacesAndNewlines), !category.isEmpty {
|
|
parameters["category"] = category
|
|
}
|
|
|
|
return .requestParameters(parameters: parameters, encoding: URLEncoding.queryString)
|
|
}
|
|
}
|
|
|
|
var headers: [String: String]? {
|
|
["Authorization": "Bearer \(UserDefaults.string(forKey: UserDefaultsKey.token))"]
|
|
}
|
|
}
|