feat: add share calendar API
This commit is contained in:
@@ -10,6 +10,7 @@ from sqlalchemy.exc import SQLAlchemyError
|
||||
from core.db.base_repository import BaseRepository
|
||||
from core.logging import get_logger
|
||||
from models.schedule_items import ScheduleItem
|
||||
from models.schedule_subscriptions import ScheduleSubscription
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
@@ -18,6 +19,7 @@ logger = get_logger("v1.schedule_items.repository")
|
||||
|
||||
|
||||
class ScheduleItemRepository(Protocol):
|
||||
async def get_by_id(self, entity_id: UUID) -> ScheduleItem | None: ...
|
||||
async def get_by_item_id(
|
||||
self, item_id: UUID, owner_id: UUID
|
||||
) -> ScheduleItem | None: ...
|
||||
@@ -31,6 +33,7 @@ class ScheduleItemRepository(Protocol):
|
||||
async def list_by_date_range(
|
||||
self, owner_id: UUID, start_at: datetime, end_at: datetime
|
||||
) -> list[ScheduleItem]: ...
|
||||
async def create_subscription(self, data: dict) -> ScheduleSubscription: ...
|
||||
|
||||
|
||||
class SQLAlchemyScheduleItemRepository(BaseRepository[ScheduleItem]):
|
||||
@@ -127,3 +130,12 @@ class SQLAlchemyScheduleItemRepository(BaseRepository[ScheduleItem]):
|
||||
except SQLAlchemyError:
|
||||
logger.exception("Schedule item list failed", owner_id=str(owner_id))
|
||||
raise
|
||||
|
||||
async def create_subscription(self, data: dict) -> ScheduleSubscription:
|
||||
sub = ScheduleSubscription(**data)
|
||||
self._session.add(sub)
|
||||
await self._session.flush()
|
||||
return sub
|
||||
|
||||
async def get_by_id(self, entity_id: UUID) -> ScheduleItem | None:
|
||||
return await super().get_by_id(entity_id)
|
||||
|
||||
Reference in New Issue
Block a user