Skip to content

Commit

Permalink
Merge pull request #116 from maxbundscherer/develop
Browse files Browse the repository at this point in the history
Implement Delete Messages from Server
  • Loading branch information
maxbundscherer authored Aug 4, 2022
2 parents 1900f5a + 16af3be commit 8fdde76
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
3 changes: 3 additions & 0 deletions docs/server-protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

- `<server-url>/v1/clearmsg/<receiverId>` (GET): Clear all messages
- Response `OK`
12 changes: 12 additions & 0 deletions independer-server/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ def routeGetMessages(receiverId):

return retDict

@app.route('/v1/clearmsg/<receiverId>')
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():
Expand Down
6 changes: 3 additions & 3 deletions independer-server/app/init_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8fdde76

Please sign in to comment.