This repository has been archived by the owner on Apr 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJobHandler.swift
62 lines (48 loc) · 2.41 KB
/
JobHandler.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//
// JobHandler.swift
// mobile
//
// Created by cb on 06.09.23.
//
import Foundation
class JobHandler {
static func fetchOwnJobs(accessToken: String, completion: @escaping (Result<JobsResponse, APIError>) -> Void) {
print("Started fetching own jobs with: \naccess_token: \(accessToken)")
guard let urlComponents = URLComponents(string: Routes.ROOT_URL + Routes.USER_JOBS_PATH) else {
completion(.failure(APIError.invalidURL))
return
}
guard let url = urlComponents.url else {
completion(.failure(APIError.invalidURL))
return
}
print("URL: \(url)")
RequestHandler.performRequest(url: url, httpMethod: HTTPMethod.GET, accessToken: accessToken, responseType:JobsResponse.self, completion: completion)
}
static func fetchUpcomingJobs(accessToken: String, completion: @escaping (Result<JobsResponse, APIError>) -> Void) {
print("Started fetching upcoming jobs with: \naccess_token: \(accessToken)")
guard let urlComponents = URLComponents(string: Routes.ROOT_URL + Routes.USER_UPCOMING_PATH) else {
completion(.failure(APIError.invalidURL))
return
}
guard let url = urlComponents.url else {
completion(.failure(APIError.invalidURL))
return
}
print("URL: \(url)")
RequestHandler.performRequest(url: url, httpMethod: HTTPMethod.GET, accessToken: accessToken, responseType:JobsResponse.self, completion: completion)
}
static func fetchNearbyJobs(accessToken: String, longitude: Double, latitude: Double, completion: @escaping (Result<JobsResponse, APIError>) -> Void) {
print("Started fetching nearby jobs with: \naccess_token: \(accessToken)\nlongitude: \(longitude)\nlatitude: \(latitude)")
guard let urlComponents = URLComponents(string: Routes.ROOT_URL + Routes.JOBS_MAPS_PATH) else {
completion(.failure(APIError.invalidURL))
return
}
guard let url = urlComponents.url else {
completion(.failure(APIError.invalidURL))
return
}
print("URL: \(url)")
RequestHandler.performRequest(url: url, httpMethod: HTTPMethod.GET, accessToken: accessToken, responseType:JobsResponse.self, queryParameters: ["longitude": String(longitude), "latitude": String(latitude)], completion: completion)
}
}