Improve timestamp handling and event navigation
This commit is contained in:
@@ -6,6 +6,7 @@ from ..cursors import decode, decode_datetime, encode
|
||||
from ..db import get_session
|
||||
from ..models import Incident as IncidentModel
|
||||
from ..schemas import Incident, IncidentsPage
|
||||
from ..timeutil import to_utc
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@@ -18,8 +19,8 @@ def _to_schema(i: IncidentModel) -> Incident:
|
||||
severity=i.severity,
|
||||
agent_id=i.agent_id,
|
||||
check_id=i.check_id,
|
||||
opened_at=i.opened_at,
|
||||
resolved_at=i.resolved_at,
|
||||
opened_at=to_utc(i.opened_at),
|
||||
resolved_at=to_utc(i.resolved_at) if i.resolved_at else None,
|
||||
summary=i.summary,
|
||||
)
|
||||
|
||||
@@ -49,5 +50,5 @@ async def list_incidents(
|
||||
next_cursor = None
|
||||
if len(rows) > limit:
|
||||
rows = rows[:limit]
|
||||
next_cursor = encode(rows[-1].opened_at.isoformat(), rows[-1].id)
|
||||
next_cursor = encode(to_utc(rows[-1].opened_at).isoformat(), rows[-1].id)
|
||||
return IncidentsPage(items=[_to_schema(r) for r in rows], next_cursor=next_cursor)
|
||||
|
||||
Reference in New Issue
Block a user