Add beamtime relationships and enhance sample handling
This commit adds relationships to link Pucks and Samples to Beamtime in the models, enabling better data association. Includes changes to assign beamtime IDs during data generation and updates in API response models for improved data loading. Removed redundant code in testfunctions.ipynb to clean up the notebook.
This commit is contained in:
@ -1,9 +1,14 @@
|
||||
from fastapi import APIRouter, HTTPException, status, Depends
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlalchemy.orm import Session, joinedload
|
||||
from sqlalchemy import or_
|
||||
|
||||
from app.models import Beamtime as BeamtimeModel
|
||||
from app.schemas import Beamtime as BeamtimeSchema, BeamtimeCreate, loginData
|
||||
from app.schemas import (
|
||||
Beamtime as BeamtimeSchema,
|
||||
BeamtimeCreate,
|
||||
loginData,
|
||||
BeamtimeResponse,
|
||||
)
|
||||
from app.dependencies import get_db
|
||||
from app.routers.auth import get_current_user
|
||||
|
||||
@ -60,7 +65,7 @@ async def create_beamtime(
|
||||
|
||||
@beamtime_router.get(
|
||||
"/my-beamtimes",
|
||||
response_model=list[BeamtimeSchema],
|
||||
response_model=list[BeamtimeResponse],
|
||||
)
|
||||
async def get_my_beamtimes(
|
||||
db: Session = Depends(get_db),
|
||||
@ -68,5 +73,10 @@ async def get_my_beamtimes(
|
||||
):
|
||||
user_pgroups = current_user.pgroups
|
||||
filters = [BeamtimeModel.pgroups.like(f"%{pgroup}%") for pgroup in user_pgroups]
|
||||
beamtimes = db.query(BeamtimeModel).filter(or_(*filters)).all()
|
||||
beamtimes = (
|
||||
db.query(BeamtimeModel)
|
||||
.options(joinedload(BeamtimeModel.local_contact))
|
||||
.filter(or_(*filters))
|
||||
.all()
|
||||
)
|
||||
return beamtimes
|
||||
|
Reference in New Issue
Block a user