Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add /query/list/parents endpoint #40

Merged
merged 2 commits into from
Aug 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion python/valis/routes/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
carton_program_list, carton_program_map,
get_targets_by_sdss_id, get_targets_by_catalog_id,
get_targets_obs, get_paged_target_list_by_mapper)
from sdssdb.peewee.sdss5db import database
from sdssdb.peewee.sdss5db import database, catalogdb

# convert string floats to proper floats
Float = Annotated[Union[float, str], BeforeValidator(lambda x: float(x) if x and isinstance(x, str) else x)]
Expand Down Expand Up @@ -172,6 +172,19 @@ async def program_map(self):

return carton_program_map()

@router.get('/list/parents', summary='Return a list of available parent catalog tables',
response_model=List[str])
async def parent_catalogs(self):
"""Return a list of available parent catalog tables."""

columns = catalogdb.SDSS_ID_To_Catalog._meta.fields.keys()

# In sdss_id_to_catalog table, the parent catalog columns are named
# as 'parent_catalog__parent_catalog_pk_column'.
catalogs = [col.split('__')[0] for col in columns if '__' in col]

return sorted(catalogs)

@router.get('/carton-program', summary='Search for all SDSS targets within a carton or program',
response_model=List[SDSSModel], dependencies=[Depends(get_pw_db)])
async def carton_program(self,
Expand Down
Loading