From 227fd808810d1c54e9d900246ade8f66a8b31dc5 Mon Sep 17 00:00:00 2001 From: Christian Oertlin Date: Mon, 18 Mar 2024 11:18:03 +0100 Subject: [PATCH] fix last func --- genotype_api/api/endpoints/plates.py | 6 +++--- genotype_api/database/crud/delete.py | 16 ++++------------ 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/genotype_api/api/endpoints/plates.py b/genotype_api/api/endpoints/plates.py index 95b4072..0d731ba 100644 --- a/genotype_api/api/endpoints/plates.py +++ b/genotype_api/api/endpoints/plates.py @@ -12,6 +12,7 @@ from sqlmodel.sql.expression import Select, SelectOfScalar from genotype_api.database.crud.create import create_analyses_sample_objects, create_plate +from genotype_api.database.crud.delete import delete_analysis from genotype_api.database.crud.read import ( check_analyses_objects, get_analyses_from_plate, @@ -172,9 +173,8 @@ def delete_plate( analyses: list[Analysis] = get_analyses_from_plate(session=session, plate_id=plate_id) analyse_ids = [analyse.id for analyse in analyses] for analysis in analyses: - session.delete(analysis) - session.delete(plate) - session.commit() + delete_analysis(session=session, analysis=analysis) + delete_plate(session=session, plate=plate) return JSONResponse( f"Deleted plate: {plate_id} and analyses: {analyse_ids}", diff --git a/genotype_api/database/crud/delete.py b/genotype_api/database/crud/delete.py index aaf8af7..d603a6f 100644 --- a/genotype_api/database/crud/delete.py +++ b/genotype_api/database/crud/delete.py @@ -11,19 +11,11 @@ LOG = logging.getLogger(__name__) -def delete_analysis(session: Session, analysis_id: int) -> Analysis: - db_analysis = session.get(Analysis, analysis_id) - session.delete(db_analysis) +def delete_analysis(session: Session, analysis: Analysis) -> None: + session.delete(analysis) session.commit() - return db_analysis -def delete_plate(session: Session, plate_id: int) -> Plate | None: - db_plate: Plate = session.get(Plate, plate_id) - if not db_plate: - LOG.info(f"Could not find plate {plate_id}") - return None - session.delete(db_plate) +def delete_plate(session: Session, plate: Plate) -> None: + session.delete(plate) session.commit() - LOG.info("Plate deleted") - return db_plate