Add delete endpoint
Signed-off-by: AKP <tom@tdpain.net>
This commit is contained in:
parent
c941d00555
commit
66c62bd71d
3 changed files with 11 additions and 5 deletions
|
@ -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()
|
||||
|
|
|
@ -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
|
|
@ -1,4 +1,5 @@
|
|||
ENTRIES = "/entries"
|
||||
GET_ENTRY = "/entry/<entry_id>"
|
||||
UPDATE_ENTRY = "/entry/<entry_id>"
|
||||
DELETE_ENTRY = "/entry/<entry_id>"
|
||||
CREATE_ENTRY = "/entry"
|
||||
|
|
Reference in a new issue