Add upcoming_entries_for_container to CalendarService
New paginated query for upcoming confirmed entries across all calendars belonging to a container (page). Used by the events page summary view. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -239,6 +239,35 @@ class SqlCalendarService:
|
||||
merged = sorted(entries_by_id.values(), key=lambda e: e.start_at or period_start)
|
||||
return [_entry_to_dto(e) for e in merged]
|
||||
|
||||
async def upcoming_entries_for_container(
|
||||
self, session: AsyncSession, container_type: str, container_id: int,
|
||||
*, page: int = 1, per_page: int = 20,
|
||||
) -> tuple[list[CalendarEntryDTO], bool]:
|
||||
"""Upcoming confirmed entries across all calendars for a container."""
|
||||
cal_ids = select(Calendar.id).where(
|
||||
Calendar.container_type == container_type,
|
||||
Calendar.container_id == container_id,
|
||||
Calendar.deleted_at.is_(None),
|
||||
).scalar_subquery()
|
||||
|
||||
offset = (page - 1) * per_page
|
||||
result = await session.execute(
|
||||
select(CalendarEntry)
|
||||
.where(
|
||||
CalendarEntry.calendar_id.in_(cal_ids),
|
||||
CalendarEntry.state == "confirmed",
|
||||
CalendarEntry.deleted_at.is_(None),
|
||||
CalendarEntry.start_at >= func.now(),
|
||||
)
|
||||
.order_by(CalendarEntry.start_at.asc())
|
||||
.limit(per_page)
|
||||
.offset(offset)
|
||||
.options(selectinload(CalendarEntry.calendar))
|
||||
)
|
||||
entries = result.scalars().all()
|
||||
has_more = len(entries) == per_page
|
||||
return [_entry_to_dto(e) for e in entries], has_more
|
||||
|
||||
async def associated_entries(
|
||||
self, session: AsyncSession, content_type: str, content_id: int, page: int,
|
||||
) -> tuple[list[CalendarEntryDTO], bool]:
|
||||
|
||||
Reference in New Issue
Block a user