|
45 | 45 | ) |
46 | 46 |
|
47 | 47 |
|
48 | | -# TODO: Rewrite this function. |
49 | | -@router.get( |
50 | | - "/experiments/", |
51 | | - status_code=200, |
52 | | - response_model=list[experiment.Experiment], |
53 | | - response_model_exclude_none=True, |
54 | | -) |
55 | | -def list_experiments( |
56 | | - *, |
57 | | - editable: Optional[bool] = None, |
58 | | - q: Optional[str] = None, |
59 | | - db: Session = Depends(deps.get_db), |
60 | | - user_data: Optional[UserData] = Depends(get_current_user), |
61 | | -) -> list[Experiment]: |
62 | | - """ |
63 | | - List experiments. |
64 | | - """ |
65 | | - query = db.query(Experiment) |
66 | | - if q is not None: |
67 | | - save_to_logging_context({"query_string": q}) |
68 | | - |
69 | | - if user_data is None or user_data.user is None: |
70 | | - logger.debug(msg="User is anonymous; Cannot list their experiments.", extra=logging_context()) |
71 | | - return [] |
72 | | - |
73 | | - if len(q) > 0: |
74 | | - logger.debug(msg="Listing experiments for the current user.", extra=logging_context()) |
75 | | - query = query.filter( |
76 | | - Experiment.created_by_id == user_data.user.id |
77 | | - ) # .filter(Experiment.published_date is None) |
78 | | - # else: |
79 | | - # query = query.filter(Experiment.created_by_id == user.id).filter(Experiment.published_date is None) |
80 | | - try: |
81 | | - q_parsed = json.loads(q) |
82 | | - l_filter = q_parsed.get('l', {}).get('meta_analysis', None) |
83 | | - |
84 | | - if l_filter == 'false': |
85 | | - logger.debug("Excluding meta-analysis experiments.") |
86 | | - query = query.filter( |
87 | | - or_( |
88 | | - # Keep experiments without any score sets |
89 | | - not_(Experiment.score_sets.any()), |
90 | | - # Keep experiments where score sets exist but have no meta_analyzes_score_sets |
91 | | - Experiment.score_sets.any(not_(ScoreSet.meta_analyzes_score_sets.any())) |
92 | | - ) |
93 | | - ) |
94 | | - |
95 | | - except json.JSONDecodeError: |
96 | | - raise HTTPException(status_code=400, detail="Invalid query format") |
97 | | - else: |
98 | | - logger.debug(msg="No query string was provided; Listing all experiments.", extra=logging_context()) |
99 | | - |
100 | | - items = query.order_by(Experiment.urn).all() |
101 | | - return items |
102 | | - |
103 | | - |
104 | 48 | @router.post( |
105 | 49 | "/experiments/search", |
106 | 50 | status_code=200, |
|
0 commit comments