-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change to single shared query, single param dependency for post & get…
… and add documentation for helper endpoints
- Loading branch information
Showing
5 changed files
with
68 additions
and
408 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,4 +65,3 @@ EXPOSE 8080 | |
|
||
# Run the application. | ||
CMD ["uvicorn", "sia.main:app", "--host", "0.0.0.0", "--port", "8080"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,6 +125,7 @@ select = ["ALL"] | |
builtins-ignorelist = [ | ||
"all", | ||
"any", | ||
"format", | ||
"help", | ||
"id", | ||
"list", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,34 @@ | ||
"""Provides functions to get instances of params.""" | ||
|
||
from collections import defaultdict | ||
from typing import Annotated | ||
|
||
from fastapi import Depends | ||
from fastapi import Depends, Request | ||
from lsst.dax.obscore.siav2 import SIAv2Parameters | ||
|
||
from ..models.sia_query_params import SIAFormParams, SIAQueryParams | ||
from ..constants import SINGLE_PARAMS | ||
from ..models.sia_query_params import SIAQueryParams | ||
|
||
|
||
def get_query_params( | ||
async def get_sia_params_dependency( | ||
*, | ||
params: Annotated[SIAQueryParams, Depends(SIAQueryParams)], | ||
request: Request, | ||
) -> SIAv2Parameters: | ||
"""Get the SIAv2Parameters from the query parameters. | ||
Parameters | ||
---------- | ||
params | ||
The query parameters. | ||
Returns | ||
------- | ||
SIAv2Parameters | ||
The SIAv2Parameters instance. | ||
""" | ||
return params.to_butler_parameters() | ||
|
||
"""Parse GET and POST parameters into SIAv2Parameters for SIA query.""" | ||
# For POST requests, use form data | ||
if request.method == "POST": | ||
post_params_ddict: dict[str, list[str]] = defaultdict(list) | ||
|
||
for key, value in (await request.form()).multi_items(): | ||
if not isinstance(value, str): | ||
raise TypeError("File upload not supported") | ||
post_params_ddict[key].append(value) | ||
|
||
post_params = { | ||
key: (values[0] if key in SINGLE_PARAMS else values) | ||
for key, values in post_params_ddict.items() | ||
} | ||
params = SIAQueryParams.from_dict(post_params) | ||
|
||
def get_form_params( | ||
params: Annotated[SIAFormParams, Depends(SIAFormParams)], | ||
) -> SIAv2Parameters: | ||
"""Get the SIAv2Parameters from the form parameters. | ||
Parameters | ||
---------- | ||
params | ||
The form parameters. | ||
Returns | ||
------- | ||
SIAv2Parameters | ||
The SIAv2Parameters instance. | ||
""" | ||
return params.to_butler_parameters() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.