Skip to content

Commit 6f40841

Browse files
authored
Merge pull request #155 from TaskarCenterAtUW/feature-kartaview-image-path
Kartaview image path
2 parents 033b0f2 + 4a429fc commit 6f40841

File tree

4 files changed

+46
-25
lines changed

4 files changed

+46
-25
lines changed

GoInfoGame/GoInfoGame/Kartaview/Model/UploadPhotoModel.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ struct PhotoOsv: Codable {
2727
struct Photo: Codable {
2828
let id, sequenceID, dateAdded, sequenceIndex: String
2929
let photoName, lat, lng: String
30+
let path: String
3031

3132
enum CodingKeys: String, CodingKey {
3233
case id
3334
case sequenceID = "sequenceId"
34-
case dateAdded, sequenceIndex, photoName, lat, lng
35+
case dateAdded, sequenceIndex, photoName, lat, lng, path
3536
}
3637
}
3738

GoInfoGame/GoInfoGame/Kartaview/ViewModel/KartaviewViewModel.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class KartaviewViewModel: ObservableObject {
1919
}
2020

2121
// Step 1: Create Sequence
22-
func createSequence(completion: @escaping (Bool) -> ()) {
22+
func createSequence(completion: @escaping (String, Bool) -> ()) {
2323
let kartaViewAccessToken = "96aca5c4b80709fc6d9aced613b51905c0fbc37870640d7bdabede269165bde7"
2424
let formData: [[String: Any]] =
2525
[["key": "access_token", "value": kartaViewAccessToken, "type": "text"]]
@@ -42,7 +42,7 @@ class KartaviewViewModel: ObservableObject {
4242
}
4343
}
4444

45-
func uploadPhoto(sequenceId: String, completion: @escaping (Bool) -> ()) {
45+
func uploadPhoto(sequenceId: String, completion: @escaping (String, Bool) -> ()) {
4646
guard let imageData = imageToData(image: capturedImage) else {
4747
print("NO image found")
4848
return
@@ -87,15 +87,16 @@ class KartaviewViewModel: ObservableObject {
8787
let status = success.status.httpCode
8888
if status == 200 {
8989
print("PHOTO UPLOADED ----->>>> PROCEEDING TO FINISH UPLOAD")
90-
self.finishUploading(sequenceId: sequenceId, completion: completion)
90+
let imagePath = "https://api.openstreetcam.org/" + "\(success.osv.photo.path)/" + "th/\(success.osv.photo.photoName)"
91+
self.finishUploading(path: imagePath,sequenceId: sequenceId, completion: completion)
9192
}
9293
case .failure(let failure):
9394
print("FAILED")
9495
}
9596
}
9697
}
9798

98-
func finishUploading(sequenceId: String, completion: @escaping (Bool) -> ()) {
99+
func finishUploading(path: String, sequenceId: String, completion: @escaping (String, Bool) -> ()) {
99100
let kartaViewAccessToken = "96aca5c4b80709fc6d9aced613b51905c0fbc37870640d7bdabede269165bde7"
100101

101102
let formData: [[String: Any]] = [
@@ -117,11 +118,11 @@ class KartaviewViewModel: ObservableObject {
117118
let status = success.status.httpCode
118119
if status == 200 {
119120
print("PHOTO UPLOADED SUCCESSFULLY")
120-
completion(true)
121+
completion(path, true)
121122
}
122123
case .failure(let failure):
123124
print("FINISHING FAILED")
124-
completion(false)
125+
completion("An error occured", false)
125126
}
126127
}
127128
}

GoInfoGame/GoInfoGame/Network/APIEnvironment.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ enum APIEnvironment: String, CaseIterable {
2020
case .staging:
2121
return "https://api.workspaces-stage.sidewalks.washington.edu/api/v1"
2222
case .production:
23-
return "https://workspaces.sidewalks.washington.edu/api/v1"
23+
return "https://api.workspaces.sidewalks.washington.edu/api/v1"
2424
}
2525
}
2626

GoInfoGame/GoInfoGame/quests/LongQuests/View/LongForm.swift

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,22 @@ struct LongForm: View, QuestForm {
2424

2525
@Environment(\.presentationMode) var presentationMode
2626

27-
@State private var shouldShowAlert = false
27+
@State private var showSubmitAlert = false
2828

29-
@State private var alertMessage = ""
29+
@State private var showKartaviewAlert = false
30+
31+
@State private var submitAlert = ""
32+
33+
@State private var kartaViewAlert = ""
3034

3135
@State private var isCameraPresented = false
3236
@State private var capturedImage: UIImage?
3337

3438
@State private var isLoading = false
39+
40+
@State private var showImagePath = false
41+
42+
@State private var imagePath = ""
3543

3644
var body: some View {
3745
ZStack {
@@ -44,12 +52,6 @@ struct LongForm: View, QuestForm {
4452
Text("ID: \(questID ?? "0")")
4553
.font(.custom("Lato-Regular", size: 13))
4654
.padding([.leading], 20)
47-
Spacer()
48-
Button(action: {
49-
isCameraPresented = true
50-
}, label: {
51-
Image(systemName: "camera")
52-
})
5355
}
5456
.padding(EdgeInsets(top: 20, leading: 20, bottom: 10, trailing: 20))
5557
LongFormDismissButtonView {
@@ -72,15 +74,29 @@ struct LongForm: View, QuestForm {
7274
.answersToBeSubmitted[quest.questTag])
7375
}
7476
}
77+
Button {
78+
isCameraPresented = true
79+
} label: {
80+
Text("Upload a picture")
81+
}
82+
83+
84+
if showImagePath {
85+
HStack {
86+
Text("Image path: ")
87+
Link("click here", destination: URL(string: imagePath)!)
88+
}
89+
}
90+
7591
VStack {
7692
Button(action: {
7793
if !viewModel.answersToBeSubmitted.isEmpty {
7894
if let action = action {
7995
action(viewModel.answersToBeSubmitted)
8096
}
8197
} else {
82-
self.shouldShowAlert = true
83-
self.alertMessage = "Please answer atleast one quest to submit"
98+
self.showSubmitAlert = true
99+
self.submitAlert = "Please answer atleast one quest to submit"
84100
}
85101

86102
}) {
@@ -109,11 +125,11 @@ struct LongForm: View, QuestForm {
109125
.sheet(isPresented: $isCameraPresented) {
110126
CameraView(capturedImage: $capturedImage, isPresented: $isCameraPresented)
111127
}
112-
.alert(self.alertMessage, isPresented: $shouldShowAlert) {
113-
Button("OK", role: .cancel) { }
114128
}
129+
.alert(self.submitAlert, isPresented: $showSubmitAlert) {
130+
Button("OK", role: .cancel) { }
115131
}
116-
if shouldShowAlert {
132+
if showKartaviewAlert {
117133
VStack {
118134
Image(systemName: "checkmark.circle.fill")
119135
.resizable()
@@ -133,7 +149,7 @@ struct LongForm: View, QuestForm {
133149
.accessibilityLabel("Image uploaded to Kartaview")
134150
.onAppear {
135151
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
136-
shouldShowAlert = false // Dismiss notification box after 1 second
152+
showKartaviewAlert = false // Dismiss notification box after 1 second
137153
}
138154
}
139155
}
@@ -153,10 +169,13 @@ struct LongForm: View, QuestForm {
153169
func uploadImageToKartaView() {
154170
isLoading = true
155171
let kvViewModel = KartaviewViewModel(capturedImage: capturedImage!)
156-
kvViewModel.createSequence(completion: { result in
172+
kvViewModel.createSequence(completion: { (path,result) in
157173
isLoading = false
158-
alertMessage = result ? "Upload Successful" : "Upload Failed"
159-
shouldShowAlert = true
174+
kartaViewAlert = result ? "Upload Successful" : "Upload Failed"
175+
showKartaviewAlert = true
176+
showImagePath = true
177+
imagePath = path
178+
print("KARTAVIEW IMAGE PATH --->>>\(path)")
160179
})
161180
}
162181

0 commit comments

Comments
 (0)