Skip to content

Commit

Permalink
added delte document endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
cophilot committed Jan 15, 2024
1 parent 3763665 commit 74a5653
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@

postgres/__pycache__
flask_app/__pycache__
1_:memory:
12 changes: 12 additions & 0 deletions wannadb_web/postgres/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,18 @@ def updateDocumentContent(doc_id: int, new_content):
print("updateDocumentContent failed because:\n", e)
return False

def deleteDocumentContent(doc_id: int):
try:
delete_query = sql.SQL("""DELETE
FROM documents
WHERE id = (%s)
""")
execute_transaction(delete_query, (doc_id,), commit=True, fetch=False)
return True
except Exception as e:
print("updateDocumentContent failed because:\n", e)
return False


def getDocuments(document_ids: list[int], user_id: int):
select_query = sql.SQL(f"""SELECT name,content,content_byte
Expand Down
18 changes: 17 additions & 1 deletion wannadb_web/routing/files.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from flask import Blueprint, request, make_response

from wannadb_web.postgres.queries import getDocument, getDocumentsForOrganization, updateDocumentContent
from wannadb_web.postgres.queries import deleteDocumentContent, getDocument, getDocumentsForOrganization, updateDocumentContent
from wannadb_web.util import tokenDecode
from wannadb_web.postgres.transactions import addDocument

Expand Down Expand Up @@ -72,6 +72,22 @@ def update_file_content():

return make_response({"status": status}, 200)

@main_routes.route('/file/delete', methods=['POST'])
def delete_file():
authorization = request.headers.get("authorization")

token = tokenDecode(authorization)
if token is None:
return make_response({'error': 'no authorization'}, 401)


data = request.get_json()
docId = data.get('documentId')

status = deleteDocumentContent(docId)

return make_response({"status": status}, 200)

@main_routes.route('/get/file/<_id>', methods=['GET'])
def get_file(_id):

Expand Down

0 comments on commit 74a5653

Please sign in to comment.