Alter 2 files

Update `db.py`
Update `endpoints.py`
This commit is contained in:
akp 2022-10-30 07:33:44 +00:00
parent df2fd91e0b
commit 56c2a8246d
No known key found for this signature in database
GPG key ID: AA5726202C8879B7
2 changed files with 15 additions and 17 deletions

View file

@ -122,13 +122,8 @@ class DB:
return entry
def addEntry(self, Entry):
title = Entry.name
latitude = Entry.location_lat
longitude = Entry.location_long
votes = Entry.votes
image_url = Entry.image_url
insertArray = [title, latitude, longitude, votes, image_url]
def addEntry(self, entry):
insertArray = [entry.name, entry.location_lat, entry.location_long, entry.votes, entry.image_url]
cursor = self.conn.cursor()
cursor.execute(

View file

@ -31,7 +31,6 @@ class Endpoints:
def get_entry(self, entry_id: str):
entry = self.get_entry(entry_id)
return flask.jsonify(entry.as_dict())
def update_entry(self):
@ -40,19 +39,23 @@ class Endpoints:
def create_entry(self):
body = flask.request.get_json()
if body is None:
return "no JSON body", 400
return flask.abort(400, "no JSON body")
coordinates = body.get("location", None)
if coordinates is None:
return "missing location", 400
return flask.abort(400, "missing location")
new_entry = db.Entry(
uuid.uuid4(),
body.get("name"),
coordinates.get("lat"),
coordinates.get("long"),
0,
body.get("imageURL"))
try:
new_entry = db.Entry(
uuid.uuid4(),
body.get("name"),
int(coordinates.get("lat")),
int(coordinates.get("long")),
0,
body.get("imageURL"),
)
except ValueError:
return flask.abort(400, "invalid coordinate format")
validation_result, error_text = new_entry.validate()