Skip to content
Snippets Groups Projects
Commit 1df78fe6 authored by bruno.lenzi's avatar bruno.lenzi
Browse files

delete documents when deleting a collection

parent 6a410811
No related branches found
No related tags found
No related merge requests found
......@@ -11,6 +11,7 @@ from sqlmodel import select
from app import crud
from app.api.deps import CurrentUser, SessionDep
from app.api.routes.documents import delete_document
from app.models import (
Collection,
CollectionCreate,
......@@ -106,9 +107,16 @@ def update_collection(
@router.delete("/{id}")
def delete_collection(session: SessionDep, current_user: CurrentUser, id: uuid.UUID) -> Message:
"""
Delete an collection.
Delete a collection.
"""
with user_permissions(current_user):
# TODO: probably better to delete the s3 path directly and send a msg to delete all the vectors
# TODO: handle possible problems with s3
collection = cast(Collection, crud.read_generic_item(session=session, model=Collection, item_id=id))
if not collection or not collection.can_edit:
raise HTTPException(status_code=403, detail="The user doesn't have enough privileges")
for document in collection.documents:
delete_document(session=session, current_user=current_user, id=document.id)
return crud.delete_generic_item(session=session, model=Collection, item_id=id)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment