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

update requirements #222

Closed
Show file tree
Hide file tree
Changes from 1 commit
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
19 changes: 17 additions & 2 deletions pcstac/pcstac/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
from fastapi.openapi.utils import get_openapi
from fastapi.responses import ORJSONResponse
from stac_fastapi.api.errors import DEFAULT_STATUS_CODES
from stac_fastapi.api.models import create_get_request_model, create_post_request_model
from stac_fastapi.api.models import (
create_get_request_model,
create_post_request_model,
create_request_model,
)
from stac_fastapi.extensions.core import TokenPaginationExtension
from stac_fastapi.api.middleware import ProxyHeaderMiddleware
from stac_fastapi.pgstac.config import Settings
from stac_fastapi.pgstac.db import close_db_connection, connect_to_db
Expand All @@ -33,7 +38,7 @@
get_settings,
)
from pcstac.errors import PC_DEFAULT_STATUS_CODES
from pcstac.search import PCSearch, PCSearchGetRequest, RedisBaseItemCache
from pcstac.search import PCSearch, PCSearchGetRequest, RedisBaseItemCache, PCItemCollectionUri

DEBUG: bool = os.getenv("DEBUG") == "TRUE" or False

Expand All @@ -50,6 +55,15 @@

app_settings = get_settings()

items_get_request_model = PCItemCollectionUri
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can now directly define the GET - /items model. This wasn't used previously

if any(isinstance(ext, TokenPaginationExtension) for ext in EXTENSIONS):
items_get_request_model = create_request_model(
model_name="ItemCollectionUri",
base_model=PCItemCollectionUri,
mixins=[TokenPaginationExtension().GET],
request_type="GET",
)

search_get_request_model = create_get_request_model(
EXTENSIONS, base_model=PCSearchGetRequest
)
Expand Down Expand Up @@ -82,6 +96,7 @@ async def lifespan(app: FastAPI) -> AsyncGenerator:
default_response_class=ORJSONResponse,
lifespan=lifespan,
),
items_get_request_model=items_get_request_model,
search_get_request_model=search_get_request_model,
search_post_request_model=search_post_request_model,
response_class=ORJSONResponse,
Expand Down
9 changes: 5 additions & 4 deletions pcstac/pcstac/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Any, Callable, Coroutine, Dict, Optional

import attr
from fastapi import Query
from pydantic import Field, field_validator
from stac_fastapi.api.models import BaseSearchGetRequest, ItemCollectionUri
from stac_fastapi.types.rfc3339 import str_to_interval, DateTimeType
Expand All @@ -14,7 +15,7 @@
from pccommon.redis import cached_result
from pcstac.contants import CACHE_KEY_BASE_ITEM

DEFAULT_LIMIT = 250
DEFAULT_LIMIT: int = 250

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -69,7 +70,7 @@ async def _fetch() -> Dict[str, Any]:

@attr.s
class PCItemCollectionUri(ItemCollectionUri):
limit: Optional[int] = attr.ib(default=DEFAULT_LIMIT) # type:ignore
limit: Annotated[Optional[int], Query()] = attr.ib(default=DEFAULT_LIMIT)


def patch_and_convert(interval: Optional[str]) -> Optional[DateTimeType]:
Expand All @@ -81,7 +82,7 @@ def patch_and_convert(interval: Optional[str]) -> Optional[DateTimeType]:

@attr.s
class PCSearchGetRequest(BaseSearchGetRequest):
datetime: Optional[DateTimeType] = attr.ib(
datetime: Annotated[Optional[DateTimeType], Query()] = attr.ib(
default=None, converter=patch_and_convert
)
limit: Optional[int] = attr.ib(default=DEFAULT_LIMIT) # type:ignore
limit: Annotated[Optional[int], Query()] = attr.ib(default=DEFAULT_LIMIT)
8 changes: 4 additions & 4 deletions pcstac/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
# Runtime requirements.
inst_reqs = [
"idna>=3.7.0",
"stac-fastapi.api==3.0.0a3",
"stac-fastapi.extensions==3.0.0a3",
"stac-fastapi.pgstac==3.0.0a2",
"stac-fastapi.types==3.0.0a3",
"stac-fastapi.api==3.0.0b2",
"stac-fastapi.extensions==3.0.0b2",
"stac-fastapi.pgstac==3.0.0a4",
"stac-fastapi.types==3.0.0b2",
"orjson==3.10.4",
# Required due to some imports related to pypgstac CLI usage in startup script
"pypgstac[psycopg]>=0.8.5,<0.9",
Expand Down