Skip to content

Commit

Permalink
ChangeMachine/NewMachine - Functional handling of special http charac…
Browse files Browse the repository at this point in the history
…ters (#283)

* revert hotfix, finalize frontend fix of ascii characters

* use request construct to avoid errors

* fix: + sign now parsed correctly

* fix: endpoint

---------

Co-authored-by: jannisborn <[email protected]>
  • Loading branch information
NinaWie and jannisborn authored Feb 8, 2024
1 parent ac44b7a commit 7b07dd7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 30 deletions.
4 changes: 2 additions & 2 deletions PennyMe.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.14;
MARKETING_VERSION = 1.15;
PRODUCT_BUNDLE_IDENTIFIER = "PennyMe--com.de.pennyme";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.2;
Expand All @@ -525,7 +525,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.14;
MARKETING_VERSION = 1.15;
PRODUCT_BUNDLE_IDENTIFIER = "PennyMe--com.de.pennyme";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.2;
Expand Down
29 changes: 16 additions & 13 deletions PennyMe/MachineChangedRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -266,19 +266,22 @@ struct MachineChangedForm: View {

let statusNew = statusDict[selectedSegment]!

let addressCleaned = address.replacingOccurrences(of: "?", with: "%26").replacingOccurrences(of: "+", with: "%2b").replacingOccurrences(of: "=", with: "%3d")
let titleCleaned = name.replacingOccurrences(of: "?", with: "%26").replacingOccurrences(of: "+", with: "%2b").replacingOccurrences(of: "=", with: "%3d")
let areaCleaned = area.replacingOccurrences(of: "?", with: "%26").replacingOccurrences(of: "+", with: "%2b").replacingOccurrences(of: "=", with: "%3d")

// prepare URL
let urlString = flaskURL+"/change_machine?id=\(pinDataStored.id)&title=\(titleCleaned)&address=\(addressCleaned)&lat_coord=\(lat_coord)&lon_coord=\(lon_coord)&status=\(statusNew)&multimachine=\(multimachine)&paywall=\(paywall)&area=\(areaCleaned)"

guard let url = URL(string: urlString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? "None"
) else {
finishLoading(message: "Something went wrong. Please try to re-enter the information")
return
}
var request = URLRequest(url: url)
var urlComponents = URLComponents(string: flaskURL)!
urlComponents.path = "/change_machine"
urlComponents.queryItems = [
URLQueryItem(name: "id", value: pinDataStored.id),
URLQueryItem(name: "title", value: name),
URLQueryItem(name: "address", value: address),
URLQueryItem(name: "area", value: area),
URLQueryItem(name: "multimachine", value: multimachine),
URLQueryItem(name:"paywall", value: String(paywall)),
URLQueryItem(name: "lon_coord", value: "\(lon_coord)"),
URLQueryItem(name: "lat_coord", value: "\(lat_coord)"),
URLQueryItem(name: "status", value: statusNew),
]
urlComponents.percentEncodedQuery = urlComponents.percentEncodedQuery?.replacingOccurrences(of: "+", with: "%2B")
var request = URLRequest(url: urlComponents.url!)

request.httpMethod = "POST"

// Create a URLSessionDataTask to send the request
Expand Down
25 changes: 13 additions & 12 deletions PennyMe/NewMachineRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -214,18 +214,19 @@ struct NewMachineFormView: View {
finishLoading(message: "Something went wrong with your image")
return
}
let addressCleaned = address.replacingOccurrences(of: "?", with: "%26").replacingOccurrences(of: "+", with: "%2b").replacingOccurrences(of: "=", with: "%3d")
let titleCleaned = name.replacingOccurrences(of: "?", with: "%26").replacingOccurrences(of: "+", with: "%2b").replacingOccurrences(of: "=", with: "%3d")
let areaCleaned = area.replacingOccurrences(of: "?", with: "%26").replacingOccurrences(of: "+", with: "%2b").replacingOccurrences(of: "=", with: "%3d")

// call flask method called create_machine
let urlString = flaskURL+"/create_machine?title=\(titleCleaned)&address=\(addressCleaned)&lat_coord=\(coords.latitude)&lon_coord=\(coords.longitude)&multimachine=\(multimachine)&paywall=\(paywall)&area=\(areaCleaned)"
guard let url = URL(string: urlString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? "None"
) else {
finishLoading(message: "Something went wrong. Please try to re-enter the information")
return
}
var request = URLRequest(url: url)
var urlComponents = URLComponents(string: flaskURL)!
urlComponents.path = "/create_machine"
urlComponents.queryItems = [
URLQueryItem(name: "title", value: name),
URLQueryItem(name: "address", value: address),
URLQueryItem(name: "area", value: area),
URLQueryItem(name: "multimachine", value: multimachine),
URLQueryItem(name:"paywall", value: String(paywall)),
URLQueryItem(name: "lon_coord", value: "\(coords.longitude)"),
URLQueryItem(name: "lat_coord", value: "\(coords.latitude)"),
]
urlComponents.percentEncodedQuery = urlComponents.percentEncodedQuery?.replacingOccurrences(of: "+", with: "%2B")
var request = URLRequest(url: urlComponents.url!)
request.httpMethod = "POST"

// Add the image data to the request body
Expand Down
4 changes: 1 addition & 3 deletions backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,7 @@ def change_machine():
"""
machine_id = int(request.args.get("id"))
title = str(request.args.get("title")).strip()
# address = str(request.args.get("address")).strip()
# hot fix: for now, just use the part between the address and the lat_coord argument
address = str(request.query_string).split("address=")[1].split("&lat_coord=")[0]
address = str(request.args.get("address")).strip()
area = str(request.args.get("area")).strip()
status = str(request.args.get("status")).strip()
latitude = float(request.args.get("lat_coord"))
Expand Down

0 comments on commit 7b07dd7

Please sign in to comment.