Add last_updated_at to list_advisories

This commit is contained in:
Mustafa Gezen 2023-03-23 17:01:52 +01:00
parent 1d90b6db2e
commit 650a80989e
Signed by untrusted user who does not match committer: mustafa
GPG Key ID: DCDF010D946438C1

View File

@ -6,9 +6,8 @@ from fastapi_pagination import Params
from fastapi_pagination.links import Page from fastapi_pagination.links import Page
from fastapi_pagination.ext.tortoise import paginate from fastapi_pagination.ext.tortoise import paginate
from apollo.db import Advisory from apollo.db import Advisory, RedHatIndexState
from apollo.db.serialize import Advisory_Pydantic from apollo.db.serialize import Advisory_Pydantic
from apollo.db.advisory import fetch_advisories
router = APIRouter(tags=["advisories"]) router = APIRouter(tags=["advisories"])
@ -16,6 +15,8 @@ T = TypeVar("T")
class Pagination(Page[T], Generic[T]): class Pagination(Page[T], Generic[T]):
last_updated_at: Optional[str]
class Config: class Config:
allow_population_by_field_name = True allow_population_by_field_name = True
fields = {"items": {"alias": "advisories"}} fields = {"items": {"alias": "advisories"}}
@ -46,6 +47,12 @@ async def list_advisories(
).order_by("-published_at"), ).order_by("-published_at"),
) )
state = await RedHatIndexState.first()
advisories.last_updated_at = state.last_indexed_at.isoformat("T").replace(
"+00:00",
"",
) + "Z"
return advisories return advisories