Monorepo: consolidate 7 repos into one
Combines shared, blog, market, cart, events, federation, and account into a single repository. Eliminates submodule sync, sibling model copying at build time, and per-app CI orchestration. Changes: - Remove per-app .git, .gitmodules, .gitea, submodule shared/ dirs - Remove stale sibling model copies from each app - Update all 6 Dockerfiles for monorepo build context (root = .) - Add build directives to docker-compose.yml - Add single .gitea/workflows/ci.yml with change detection - Add .dockerignore for monorepo build context - Create __init__.py for federation and account (cross-app imports)
This commit is contained in:
60
blog/bp/post/services/entry_associations.py
Normal file
60
blog/bp/post/services/entry_associations.py
Normal file
@@ -0,0 +1,60 @@
|
||||
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,
|
||||
}
|
||||
Reference in New Issue
Block a user