Skip to content

Commit

Permalink
Added target_by_sdss_id_list endpoint (#13)
Browse files Browse the repository at this point in the history
* added target_by_sdss_id_list endpoint

* Consolidate get_targets_by_sdss_id functions.
  • Loading branch information
mtaghiza authored Mar 12, 2024
1 parent 41ae433 commit dcf8ab6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
19 changes: 10 additions & 9 deletions python/valis/db/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,29 +149,30 @@ def cone_search(ra: Union[str, float], dec: Union[str, float],
dec_col='dec_sdss_id'))


def get_targets_by_sdss_id(sdss_id: int) -> peewee.ModelSelect:
""" Perform a search for SDSS targets on vizdb.SDSSidStacked based on the sdss_id.
def get_targets_by_sdss_id(sdss_id: Union[int, list[int]] = []) -> peewee.ModelSelect:
""" Perform a search for SDSS targets on vizdb.SDSSidStacked based on sdss_id values.
Perform a search for SDSS targets using the peewee ORM in the
vizdb.SDSSidStacked table. We return the peewee ModelSelect
directly here so it can be easily combined with other queries,
if needed.
vizdb.SDSSidStacked table, based on single or multiple sdss_ids values.
We return the peewee ModelSelect directly here so it can be easily combined
with other queries, if needed.
In the route endpoint itself, remember to return wrap this in a list.
Parameters
----------
sdss_id : int
the sdss_id
sdss_id : Union[int, list[int]]
the sdss_id or list of sdss_id values
Returns
-------
peewee.ModelSelect
the ORM query
"""
if type(sdss_id) == int:
sdss_id = [sdss_id]

return vizdb.SDSSidStacked.select().where(vizdb.SDSSidStacked.sdss_id == sdss_id)

return vizdb.SDSSidStacked.select().where(vizdb.SDSSidStacked.sdss_id.in_(sdss_id))

def get_targets_by_catalog_id(catalog_id: int) -> peewee.ModelSelect:
""" Perform a search for SDSS targets on vizdb.SDSSidStacked based on the catalog_id.
Expand Down
11 changes: 11 additions & 0 deletions python/valis/routes/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ class MainSearchResponse(BaseModel):
data: List[MainResponse] = Field(..., description='the list of query results')


class SDSSIdsModel(BaseModel):
"""Request body for the endpoint returning targets from an sdss_id list"""
sdss_id_list: List[int] = Field(description='List of sdss_id values', example=[67660076, 67151446])


router = APIRouter()


Expand Down Expand Up @@ -123,6 +128,12 @@ async def sdss_id_search(self, sdss_id: Annotated[int, Query(description='Value

return targets or {}

@router.post('/sdssid', summary='Perform a search for SDSS targets based on a list of sdss_id values',
response_model=List[SDSSidStackedBase], dependencies=[Depends(get_pw_db)])
async def sdss_ids_search(self, body: SDSSIdsModel):
""" Perform a search for SDSS targets based on a list of input sdss_id values."""
return list(get_targets_by_sdss_id(body.sdss_id_list))

@router.get('/catalogid', summary='Perform a search for SDSS targets based on the catalog_id',
response_model=List[SDSSidStackedBase], dependencies=[Depends(get_pw_db)])
async def catalog_id_search(self, catalog_id: Annotated[int, Query(description='Value of catalog_id', example=7613823349)]):
Expand Down

0 comments on commit dcf8ab6

Please sign in to comment.