| 
					
				 | 
			
			
				@@ -9,15 +9,28 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import Foundation 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import CoreLocation 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+struct Person: Codable { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    var name: String 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    var age: Int 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 //class SendPOSTData { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     func placeOrder(didUpdateLocations locations: [CLLocation]) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         print("placeOrder") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         locations.forEach { (location) in 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            var kalle = "Hejhejhej" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            guard let encoded = try? JSONEncoder().encode(kalle) else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                print("Failed to encode order") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+             
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            let person = Person(name: "Josh", age: 30) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            let jsonEncoder = JSONEncoder() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            jsonEncoder.outputFormatting = .prettyPrinted 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+             
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            var uploadData:Data? 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            do { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                uploadData = try jsonEncoder.encode(person) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                let endcodeStringPerson = String(data: uploadData! , encoding: .utf8)! 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                print(endcodeStringPerson) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } catch { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                print(error.localizedDescription) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				              
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             let url = URL(string: "http://chef.maya.se/gpsapi/cupcakes")! 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -25,12 +38,24 @@ import CoreLocation 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             request.setValue("application/json", forHTTPHeaderField: "Content-Type") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             request.httpMethod = "POST" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				              
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            /*do { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                let (data, _) = try await URLSession.shared.upload(for: request, from: encoded) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                // handle the result 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } catch { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                print("Checkout failed.") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            }*/ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            let task = URLSession.shared.uploadTask(with: request, from: uploadData) { data, response, error in 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if let error = error { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    print ("error: \(error)") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                guard let response = response as? HTTPURLResponse, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    (200...299).contains(response.statusCode) else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    print ("server error") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if let mimeType = response.mimeType, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    mimeType == "application/json", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    let data = data, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    let dataString = String(data: data, encoding: .utf8) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    print ("got data: \(dataString)") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            task.resume() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 |