@@ -683,6 +683,7 @@ def update_batch(
683683 "updated_at" : query_result [0 ][0 ].updated_at ,
684684 }
685685
686+
686687@router .patch ("/{inst_id}/delete-batch/{batch_id}" , response_model = BatchInfo )
687688def delete_batch (
688689 inst_id : str ,
@@ -697,26 +698,25 @@ def delete_batch(
697698 local_session .set (sql_session )
698699 sess = local_session .get ()
699700
700- batch = (
701- sess .execute (
702- select (BatchTable ).where (
703- BatchTable .id == str_to_uuid (batch_id ),
704- BatchTable .inst_id == str_to_uuid (inst_id ),
705- )
701+ batch = sess .execute (
702+ select (BatchTable ).where (
703+ BatchTable .id == str_to_uuid (batch_id ),
704+ BatchTable .inst_id == str_to_uuid (inst_id ),
706705 )
707- .scalar_one_or_none ()
708- )
706+ ).scalar_one_or_none ()
709707 if batch is None :
710- raise HTTPException (status_code = status .HTTP_404_NOT_FOUND , detail = "Batch not found." )
708+ raise HTTPException (
709+ status_code = status .HTTP_404_NOT_FOUND , detail = "Batch not found."
710+ )
711711
712712 # 2) Gather filenames to delete
713713 batch_files : list [str ] = (
714714 sess .execute (
715715 select (FileTable .name ).where (
716- FileTable .id == str_to_uuid (batch_id ),
717- FileTable .inst_id == str_to_uuid (inst_id ),
718- )
716+ FileTable .id == str_to_uuid (batch_id ),
717+ FileTable .inst_id == str_to_uuid (inst_id ),
719718 )
719+ )
720720 .scalars ()
721721 .all ()
722722 )
@@ -736,16 +736,15 @@ def delete_batch(
736736 }
737737
738738 gcs_result = storage_control .delete_batch_files (
739- bucket_name = get_external_bucket_name (inst_id ),
740- batch_files = batch_files
739+ bucket_name = get_external_bucket_name (inst_id ), batch_files = batch_files
741740 )
742741
743742 if gcs_result .get ("errors" ):
744743 raise HTTPException (
745744 status_code = status .HTTP_500_INTERNAL_SERVER_ERROR ,
746745 detail = f"Unable to delete files { gcs_result ['errors' ]} ." ,
747746 )
748-
747+
749748 # 4) Delete DB rows only for blobs that were actually deleted
750749 deleted_names = {d ["file" ] for d in gcs_result .get ("deleted" , [])}
751750 not_found_names = set (gcs_result .get ("not_found" , []))
@@ -781,17 +780,18 @@ def delete_batch(
781780 raise HTTPException (
782781 status_code = 500 , detail = f"DB batch delete failed after file cleanup: { e } "
783782 )
784-
783+
785784 return {
786785 "inst_id" : inst_id ,
787786 "batch_id" : batch_id ,
788- "deleted" : gcs_result .get ("deleted" , []), # [{file, path, deleted_at}, ...]
787+ "deleted" : gcs_result .get ("deleted" , []), # [{file, path, deleted_at}, ...]
789788 "not_found" : sorted (not_found_names ),
790789 "errors" : gcs_result .get ("errors" , []),
791790 "db_deleted_rows" : db_deleted_rows ,
792791 "batch_deleted" : True ,
793792 }
794793
794+
795795@router .get ("/{inst_id}/file-id/{file_id}" , response_model = DataInfo )
796796def read_file_id_info (
797797 inst_id : str ,
0 commit comments