From 16af3be47e46be8e619dff27948a4b64483cbeb8 Mon Sep 17 00:00:00 2001 From: Maximilian Bundscherer Date: Thu, 4 Aug 2022 14:34:24 +0200 Subject: [PATCH] Implement Delete Messages from Server --- docs/server-protocol.md | 3 +++ independer-server/app/app.py | 12 ++++++++++++ independer-server/app/init_db.py | 6 +++--- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/docs/server-protocol.md b/docs/server-protocol.md index 0c700f3..56edd8c 100644 --- a/docs/server-protocol.md +++ b/docs/server-protocol.md @@ -9,3 +9,6 @@ JSON-API Independer Server. Please also visit [escape rules](escape-rules.md). - `receiver`: Receiver of the message - `author`: Author of the message - `msg`: Content of the message + +- `/v1/clearmsg/` (GET): Clear all messages + - Response `OK` diff --git a/independer-server/app/app.py b/independer-server/app/app.py index ca34129..f02c073 100644 --- a/independer-server/app/app.py +++ b/independer-server/app/app.py @@ -35,6 +35,18 @@ def routeGetMessages(receiverId): return retDict +@app.route('/v1/clearmsg/') +def routeClearMessages(receiverId): + conn = get_db_connection() + cur = conn.cursor() + cur.execute( + "UPDATE messages SET active = false WHERE receiver = '" + receiverId + "';") + conn.commit() + cur.close() + conn.close() + + return "OK" + @app.route('/v1/msg', methods=['POST']) def routeWriteMessage(): diff --git a/independer-server/app/init_db.py b/independer-server/app/init_db.py index 9b1c3fe..b700775 100644 --- a/independer-server/app/init_db.py +++ b/independer-server/app/init_db.py @@ -19,9 +19,9 @@ cur.execute('CREATE TABLE IF NOT EXISTS messages (id serial PRIMARY KEY,' 'receiver varchar (5) NOT NULL,' 'author varchar (5) NOT NULL,' - 'msg text,' - 'active boolean,' - 'date_added date DEFAULT CURRENT_TIMESTAMP);' + 'msg text NOT NULL,' + 'active boolean NOT NULL,' + 'date_added date DEFAULT CURRENT_TIMESTAMP NOT NULL);' ) # Insert data into the table