Skip to content
Snippets Groups Projects
Commit 26810a8f authored by Herman Andersen Dyrkorn's avatar Herman Andersen Dyrkorn
Browse files

changes in location endpoint, takes longitude and latitude

parent 27e946b0
No related branches found
No related tags found
1 merge request!23Resolve "debug and cleanup code"
......@@ -6,7 +6,8 @@ from api.models.dbmodels import Location
import re
import os
COORDINATES_REGEX = "^[-+]?([1-8]?\d(\.\d+)?|90(\.0+)?),\s*[-+]?(180(\.0+)?|((1[0-7]\d)|([1-9]?\d))(\.\d+)?)$"
LATITUDE_REGEX = "^(\\+|-)?(?:90(?:(?:\\.0{1,6})?)|(?:[0-9]|[1-8][0-9])(?:(?:\\.[0-9]{1,6})?))$"
LONGITUDE_REGEX = "^(\\+|-)?(?:180(?:(?:\\.0{1,6})?)|(?:[0-9]|[1-9][0-9]|1[0-7][0-9])(?:(?:\\.[0-9]{1,6})?))$"
# findSalamanderInfo endpoint
......@@ -15,11 +16,11 @@ class LocationEndpoint(Resource):
@jwt_required
def post():
data = request.form
if "coordinates" in data and "name" in data and "radius" in data:
if "name" in data and "radius" in data and "latitude" in data and "longitude" in data:
location = db.session.query(Location).filter_by(name=data['name'].lower()).first()
if location is None and re.search(COORDINATES_REGEX, data['coordinates']):
new_location = Location(name=data['name'].lower(), coordinates=data['coordinates'],
radius=data['radius'])
if location is None and re.search(LATITUDE_REGEX, data['latitude']) and re.search(LONGITUDE_REGEX, data['longitude']):
new_location = Location(name=data['name'].lower(), longitude=data['longitude'],
latitude=data['latitude'], radius=data['radius'])
db.session.add(new_location)
db.session.commit()
create_directory_folders(data['name'].lower())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment