Skip to content

Commit

Permalink
fix last func
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrOertlin committed Mar 18, 2024
1 parent 8a80e11 commit 227fd80
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
6 changes: 3 additions & 3 deletions genotype_api/api/endpoints/plates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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}",
Expand Down
16 changes: 4 additions & 12 deletions genotype_api/database/crud/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 227fd80

Please sign in to comment.