Skip to content

Commit

Permalink
Add query parameter to search preset by suite
Browse files Browse the repository at this point in the history
Signed-off-by: Devansh Singh <[email protected]>
  • Loading branch information
Devansh3712 committed Aug 21, 2024
1 parent 2b70962 commit 72c88d9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/teuthology_api/routes/presets.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from typing import Optional

from fastapi import status, APIRouter, Depends, HTTPException, Request
from sqlmodel import Session
Expand All @@ -25,8 +26,13 @@ def read_preset(username: str, name: str, db: Session = Depends(get_db)):


@router.get("/list", status_code=status.HTTP_200_OK)
def read_all_presets(username: str, db: Session = Depends(get_db)):
db_presets = PresetsService(db).get_by_username(username)
def read_all_presets(
username: str, suite: Optional[str] = None, db: Session = Depends(get_db)
):
if suite:
db_presets = PresetsService(db).get_by_username_and_suite(username, suite)
else:
db_presets = PresetsService(db).get_by_username(username)
if not db_presets:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
Expand Down
7 changes: 7 additions & 0 deletions src/teuthology_api/services/presets.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ def get_by_username(self, username: str):
db_presets = self.db.exec(statement).all()
return db_presets

def get_by_username_and_suite(self, username: str, suite: str):
statement = select(Presets).where(
Presets.username == username, Presets.suite == suite
)
db_presets = self.db.exec(statement).all()
return db_presets

def get_by_username_and_name(
self, username: str, preset_name: str
) -> Union[Presets, None]:
Expand Down

0 comments on commit 72c88d9

Please sign in to comment.