All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 50s
Replace direct Calendar, MarketPlace, and Post model queries with typed service calls (services.blog, services.calendar, services.market, services.cart). Blog registers all 4 services via domain_services_fn with has() guards for composable deployment. Key changes: - app.py: use domain_services_fn instead of inline service registration - admin routes: MarketPlace queries → services.market.marketplaces_for_container() - entry_associations: CalendarEntryPost → services.calendar.entry_ids_for_content() - markets service: Post query → services.blog.get_post_by_id/slug() - posts_data, post routes: use calendar/market/cart services - menu_items: glue imports → shared imports Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
61 lines
1.5 KiB
Python
61 lines
1.5 KiB
Python
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,
|
|
}
|