diff --git a/backend/main.py b/backend/main.py index bbf00f0..b025ee4 100644 --- a/backend/main.py +++ b/backend/main.py @@ -48,13 +48,14 @@ def get_files(): res = [] if files is not None: for file in files: - res.append({"name": file[1], "type": file[2], "size": file[3]}) + res.append({"id": file[0], "name": file[1], "type": file[2], "size": file[3]}) else: return {"error": "No files found."} return res except DatabaseError as e: return {"error": str(e)} + @app.post("/files/") async def upload_files(files: List[UploadFile] = File(...)): from database.models.files import File @@ -78,6 +79,18 @@ async def upload_files(files: List[UploadFile] = File(...)): return {"message": "Files uploaded successfully"} +@app.delete("/files/") +def delete_files(files: List[UploadFile] = File(...)): + from database.models.files import File + for file in files: + entry = File(id=file.id) + db = Database.get_session() + db.delete(entry) + db.commit() + print(f"deleted {file.filename} from the db") + return {"message": "Files deleted successfully"} + + @app.post("/chat/") def chat(question: Question): genie = Genie()