from __future__ import annotations from sqlalchemy.ext.asyncio import AsyncSession from shared.services.registry import services async def toggle_entry_association( session: AsyncSession, post_id: int, entry_id: int ) -> tuple[bool, str | None]: """ Toggle association between a post and calendar entry. Returns (is_now_associated, error_message). """ post = await services.blog.get_post_by_id(session, post_id) if not post: return False, "Post not found" is_associated = await services.calendar.toggle_entry_post( session, entry_id, "post", post_id, ) return is_associated, None async def get_post_entry_ids( session: AsyncSession, post_id: int ) -> set[int]: """ Get all entry IDs associated with this post. Returns a set of entry IDs. """ return await services.calendar.entry_ids_for_content(session, "post", post_id) async def get_associated_entries( session: AsyncSession, post_id: int, page: int = 1, per_page: int = 10 ) -> dict: """ Get paginated associated entries for this post. Returns dict with entries (CalendarEntryDTOs), total_count, and has_more. """ entries, has_more = await services.calendar.associated_entries( session, "post", post_id, page, ) total_count = len(entries) + (page - 1) * per_page if has_more: total_count += 1 # at least one more return { "entries": entries, "total_count": total_count, "has_more": has_more, "page": page, }