Skip to content

Commit

Permalink
Merge pull request #2 from lsst-dm/u/jeremym/dev
Browse files Browse the repository at this point in the history
Implement endpoint function
  • Loading branch information
JeremyMcCormick committed May 29, 2024
2 parents b3c2cef + a069038 commit 7c276f1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
4 changes: 1 addition & 3 deletions src/mpclookup/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ class Config(BaseSettings):

name: str = Field("mpc-lookup", title="Name of application")

path_prefix: str = Field(
"/mpc-lookup", title="URL prefix for application"
)
path_prefix: str = Field("/mpc-lookup", title="URL prefix for application")

profile: Profile = Field(
Profile.development, title="Application logging profile"
Expand Down
31 changes: 30 additions & 1 deletion src/mpclookup/handlers/external.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

from typing import Annotated

from fastapi import APIRouter, Depends
from fastapi import APIRouter, Depends, Query
from fastapi.responses import RedirectResponse
from safir.dependencies.logger import logger_dependency
from safir.metadata import get_metadata
from structlog.stdlib import BoundLogger
Expand Down Expand Up @@ -50,3 +51,31 @@ async def get_index(
application_name=config.name,
)
return Index(metadata=metadata)


_DESIGNATION_PREPEND = "2011 "


@external_router.get("/search", response_class=RedirectResponse)
async def search(
designation: Annotated[str, Query()],
logger: Annotated[BoundLogger, Depends(logger_dependency)],
) -> str:
"""
Request a redirect to the MPCORB record for a given designation.
Notes
-----
Example request:
/mpc-lookup/search?designation=2011+1001+T-2
"""
logger.info("Request for designation URL", designation=designation)
fd = designation.replace(_DESIGNATION_PREPEND, "")
redirect_url = (
"https://www.minorplanetcenter.net/db_search/"
f"show_object?object_id={fd}"
)
logger.info("Redirecting to designation URL", redirect_url=redirect_url)
return redirect_url

0 comments on commit 7c276f1

Please sign in to comment.