Merge branch 'backend'

This commit is contained in:
akp 2022-10-30 08:25:29 +00:00
commit ebd6cfb0c4
No known key found for this signature in database
GPG key ID: AA5726202C8879B7
3 changed files with 11 additions and 5 deletions

View file

@ -145,19 +145,17 @@ class DB:
self.conn.commit()
cursor.close()
def deleteEntry(self, ID):
def deleteEntry(self, entry_id):
cursor = self.conn.cursor()
cursor.execute("DELETE FROM entries WHERE ID = ?", ID)
cursor.execute("DELETE FROM entries WHERE ID = ?", [entry_id])
self.conn.commit()
cursor.close()
def updateEntry(self, entry):
updateArray = [entry.name, entry.location_lat, entry.location_long, entry.votes, entry.image_url]
cursor = self.conn.cursor()
cursor.execute(
"UPDATE entries SET title = ?, latitude = ?, longitude = ?, votes = ?, image_url = ?;",
updateArray,
[entry.name, entry.location_lat, entry.location_long, entry.votes, entry.image_url],
)
self.conn.commit()
cursor.close()

View file

@ -17,6 +17,9 @@ class Endpoints:
app.add_url_rule(
paths.UPDATE_ENTRY, view_func=self.update_entry, methods=["PUT"]
)
app.add_url_rule(
paths.DELETE_ENTRY, view_func=self.delete_entry, methods=["DELETE"]
)
app.add_url_rule(
paths.CREATE_ENTRY, view_func=self.create_entry, methods=["POST"]
)
@ -86,3 +89,7 @@ class Endpoints:
self.db.addEntry(new_entry)
return flask.jsonify({"id": new_entry.id})
def delete_entry(self, entry_id: str):
self.db.deleteEntry(entry_id)
return "", 204

View file

@ -1,4 +1,5 @@
ENTRIES = "/entries"
GET_ENTRY = "/entry/<entry_id>"
UPDATE_ENTRY = "/entry/<entry_id>"
DELETE_ENTRY = "/entry/<entry_id>"
CREATE_ENTRY = "/entry"