Skip to content

Commit c3c238c

Browse files
committed
Implemented adding location, radios and gig_only params in workspaces API
1 parent 0ab1a7e commit c3c238c

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

GoInfoGame/GoInfoGame/Network/APIEndPoint.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import Foundation
99
import osmapi
10+
import CoreLocation
1011

1112
struct APIEndpoint {
1213
let path: String
@@ -29,12 +30,12 @@ struct APIEndpoint {
2930

3031
}
3132

32-
static let fetchWorkspaceList = { (accessToken: String) in
33+
static let fetchWorkspaceList = { (location: CLLocationCoordinate2D, radius: Int, gig_only: Bool, accessToken: String) in
3334

3435
let header = [
3536
"Authorization" : "Bearer \(accessToken)"
3637
]
37-
return APIEndpoint(path: "/workspaces/mine", method: "GET", body: nil, headers: header, formData: nil)}
38+
return APIEndpoint(path: "/workspaces/mine?lat=\(location.latitude.roundedTo7Digits())&lon=\(location.longitude.roundedTo7Digits())&radius=\(radius)&gig_only=\(gig_only)", method: "GET", body: nil, headers: header, formData: nil)}
3839

3940
static let fetchLongQuests = { (workspaceId: String) in APIEndpoint(path: "/workspaces/\(workspaceId)/quests/long", method: "GET", body: nil, headers: ["Content-Type":"application/json"], formData: nil) }
4041

GoInfoGame/GoInfoGame/UI/InitialView/InitialView.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ struct WorkspacesListView: View {
122122
.padding(.top, 20)
123123
Spacer()
124124
Button {
125-
viewModel.fetchWorkspacesList()
125+
if let location = viewModel.currentLocation {
126+
viewModel.fetchWorkspacesList(location: location)
127+
}
126128
} label: {
127129
Group {
128130
VStack {

GoInfoGame/GoInfoGame/UI/InitialView/InitialViewModel.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ class InitialViewModel: ObservableObject {
2121

2222
@Published var showBiometricIDError: Bool = false
2323
@Published var biometricIDErrorMessage: String?
24+
private(set) var currentLocation: CLLocationCoordinate2D?
2425

2526

2627
init() {
2728
locationManagerDelegate.locationUpdateHandler = { [weak self] location in
2829
guard let self = self else { return }
29-
fetchWorkspacesList()
30+
self.currentLocation = location
31+
fetchWorkspacesList(location: location)
3032
locationManagerDelegate.stopUpdatingLocation()
3133
}
3234

@@ -35,10 +37,10 @@ class InitialViewModel: ObservableObject {
3537
}
3638

3739
// fetch workspaces list
38-
func fetchWorkspacesList() {
40+
func fetchWorkspacesList(location: CLLocationCoordinate2D) {
3941
self.isLoading = true
4042
if let accessToken = KeychainManager.load(key: "accessToken") {
41-
ApiManager.shared.performRequest(to: .fetchWorkspaceList(accessToken), setupType: .workspace, modelType: [Workspace].self) { result in
43+
ApiManager.shared.performRequest(to: .fetchWorkspaceList(location, 20000, true, accessToken), setupType: .workspace, modelType: [Workspace].self) { result in
4244

4345
DispatchQueue.main.async { [weak self] in
4446
self?.isLoading = false

0 commit comments

Comments
 (0)