Displaying Processing Results in the frontend
This commit is contained in:
@ -17,6 +17,7 @@ from app.schemas import (
|
||||
ImageInfo,
|
||||
ResultResponse,
|
||||
ResultCreate,
|
||||
Results as ProcessingResults,
|
||||
)
|
||||
from app.models import (
|
||||
Puck as PuckModel,
|
||||
@ -374,17 +375,29 @@ def create_result(payload: ResultCreate, db: Session = Depends(get_db)):
|
||||
)
|
||||
|
||||
|
||||
# @router.get("/results", response_model=list[ResultResponse])
|
||||
# def get_results(sample_id: int, result_id: int, db: Session = Depends(get_db)):
|
||||
# query = db.query(Results)
|
||||
#
|
||||
# if sample_id:
|
||||
# query = query.filter(Results.sample_id == sample_id)
|
||||
# if result_id:
|
||||
# query = query.filter(Results.result_id == result_id)
|
||||
#
|
||||
# results = query.all()
|
||||
# if not results:
|
||||
# raise HTTPException(status_code=404, detail="No results found")
|
||||
#
|
||||
# return results
|
||||
@router.get(
|
||||
"/processing-results/{sample_id}/{run_id}", response_model=List[ResultResponse]
|
||||
)
|
||||
async def get_results_for_run_and_sample(
|
||||
sample_id: int, run_id: int, db: Session = Depends(get_db)
|
||||
):
|
||||
results = (
|
||||
db.query(ResultsModel)
|
||||
.filter(ResultsModel.sample_id == sample_id, ResultsModel.run_id == run_id)
|
||||
.all()
|
||||
)
|
||||
|
||||
if not results:
|
||||
raise HTTPException(status_code=404, detail="Results not found.")
|
||||
|
||||
formatted_results = [
|
||||
ResultResponse(
|
||||
id=result.id,
|
||||
sample_id=result.sample_id,
|
||||
run_id=result.run_id,
|
||||
result=ProcessingResults(**result.result),
|
||||
)
|
||||
for result in results
|
||||
]
|
||||
|
||||
return formatted_results
|
||||
|
Reference in New Issue
Block a user