Files
voidea/app/api/v1/sync.py
T

34 lines
985 B
Python

"""Sync API routes for VoIdea."""
from typing import Annotated
from fastapi import APIRouter, Depends
from sqlalchemy.ext.asyncio import AsyncSession
from app.core.dependencies import get_current_user, get_db
from app.models.user import User
from app.schemas.sync import SyncPullRequest, SyncPushRequest, SyncResponse
from app.services.sync_service import SyncService
router = APIRouter()
@router.post("/pull", response_model=SyncResponse)
async def pull(
body: SyncPullRequest,
user: Annotated[User, Depends(get_current_user)],
db: AsyncSession = Depends(get_db),
):
service = SyncService(db)
return await service.pull(user, last_sync=body.last_sync)
@router.post("/push", response_model=SyncResponse)
async def push(
body: SyncPushRequest,
user: Annotated[User, Depends(get_current_user)],
db: AsyncSession = Depends(get_db),
):
service = SyncService(db)
return await service.push(user, device_id=body.device_id, changes=body.changes)