|
4 | 4 |
|
5 | 5 | from enum import Enum
|
6 | 6 | from typing import List, Union, Dict, Annotated, Optional
|
7 |
| -from fastapi import APIRouter, Depends, Query, HTTPException |
| 7 | +from fastapi import APIRouter, Depends, Query, HTTPException, Body |
8 | 8 | from fastapi_restful.cbv import cbv
|
9 | 9 | from pydantic import BaseModel, Field, BeforeValidator
|
10 | 10 |
|
|
16 | 16 | carton_program_list, carton_program_map,
|
17 | 17 | get_targets_by_sdss_id, get_targets_by_catalog_id,
|
18 | 18 | get_targets_obs, get_paged_target_list_by_mapper,
|
19 |
| - get_target_by_altid) |
| 19 | + get_target_by_altid, get_targets_by_altid) |
20 | 20 | from valis.routes.auth import set_auth
|
21 | 21 | from sdssdb.peewee.sdss5db import database, catalogdb
|
22 | 22 |
|
@@ -60,6 +60,23 @@ class SDSSIdsModel(BaseModel):
|
60 | 60 | """Request body for the endpoint returning targets from an sdss_id list"""
|
61 | 61 | sdss_id_list: List[int] = Field(description='List of sdss_id values', example=[67660076, 67151446])
|
62 | 62 |
|
| 63 | +class AltEnum(str, Enum): |
| 64 | + """ Enum for the alternative id types """ |
| 65 | + apogeeid = 'apogeeid' |
| 66 | + catalogid = 'catalogid' |
| 67 | + gaiaid = 'gaiaid' |
| 68 | + sdssid = 'sdssid' |
| 69 | + twomassid = 'twomassid' |
| 70 | + specobjid = 'specobjid' |
| 71 | + platefibermjd = 'platefibermjd' |
| 72 | + photoobjid = 'photoobjid' |
| 73 | + fieldmjdcatalogid = 'fieldmjdcatalogid' |
| 74 | + |
| 75 | +class AltIdsModel(BaseModel): |
| 76 | + """Request body for the endpoint returning targets from an altid list""" |
| 77 | + altid_list: List[str|int] = Field(description='List of altid values', example=['2M10193634+1952122', '2M14030226+5112480']) |
| 78 | + idtype: Optional[AltEnum] = Field(None, description='For ambiguous integer ids, the type of id, e.g. "catalogid"', example=['apogeeid']) |
| 79 | + |
63 | 80 |
|
64 | 81 | router = APIRouter()
|
65 | 82 |
|
@@ -164,11 +181,19 @@ async def sdss_id_search(self, sdss_id: Annotated[int, Query(description='Value
|
164 | 181 | return targets or {}
|
165 | 182 |
|
166 | 183 | @router.post('/sdssid', summary='Perform a search for SDSS targets based on a list of sdss_id values',
|
167 |
| - response_model=List[SDSSidStackedBase], |
| 184 | + response_model=List[SDSSModel], |
168 | 185 | dependencies=[Depends(get_pw_db), Depends(set_auth)])
|
169 | 186 | async def sdss_ids_search(self, body: SDSSIdsModel):
|
170 | 187 | """ Perform a search for SDSS targets based on a list of input sdss_id values."""
|
171 |
| - return list(get_targets_by_sdss_id(body.sdss_id_list)) |
| 188 | + return list(append_pipes(get_targets_by_sdss_id(body.sdss_id_list), release=self.release).dicts()) |
| 189 | + #return list(get_targets_by_sdss_id(body.sdss_id_list)) |
| 190 | + |
| 191 | + @router.post('/altids', summary='Performa search for SDSS targets based on a list of alternative ids', |
| 192 | + response_model=List[SDSSModel], |
| 193 | + dependencies=[Depends(get_pw_db), Depends(set_auth)]) |
| 194 | + async def altids_search(self, body: AltIdsModel): |
| 195 | + """ Perform a search for SDSS targets based on a list of input altid values.""" |
| 196 | + return list(append_pipes(get_targets_by_altid(body.altid_list, idtype=body.idtype), release=self.release).dicts()) |
172 | 197 |
|
173 | 198 | @router.get('/catalogid', summary='Perform a search for SDSS targets based on the catalog_id',
|
174 | 199 | response_model=List[SDSSidStackedBase],
|
|
0 commit comments