Skip to content

Commit

Permalink
feat(grumpyp#45): added API to delete files
Browse files Browse the repository at this point in the history
  • Loading branch information
tarun-raghunandan-miq committed Jun 11, 2023
1 parent 7099cd4 commit e09004b
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down

0 comments on commit e09004b

Please sign in to comment.