aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/server/routes/sync.ts
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2025-12-07 19:20:04 +0900
committernsfisis <nsfisis@gmail.com>2025-12-07 19:20:04 +0900
commit9632d70ea0d326ac0df4e9bffb7fb669013f0755 (patch)
tree74b29b896b57c16c3bb64e8ade75566f6a8f0e1c /src/server/routes/sync.ts
parentfe101104cdd50256d4ef5c61e1bf099ed2da68e3 (diff)
downloadkioku-9632d70ea0d326ac0df4e9bffb7fb669013f0755.tar.gz
kioku-9632d70ea0d326ac0df4e9bffb7fb669013f0755.tar.zst
kioku-9632d70ea0d326ac0df4e9bffb7fb669013f0755.zip
feat(server): add GET /api/sync/pull endpoint
Implement sync pull endpoint to fetch entities updated since a given syncVersion. Returns decks, cards, and review logs with their current sync versions for incremental client synchronization. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Diffstat (limited to 'src/server/routes/sync.ts')
-rw-r--r--src/server/routes/sync.ts13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/server/routes/sync.ts b/src/server/routes/sync.ts
index 01f9bd0..d61e8d3 100644
--- a/src/server/routes/sync.ts
+++ b/src/server/routes/sync.ts
@@ -3,6 +3,7 @@ import { Hono } from "hono";
import { z } from "zod";
import { authMiddleware, getAuthUser } from "../middleware/index.js";
import {
+ type SyncPullQuery,
type SyncPushData,
type SyncRepository,
syncRepository,
@@ -58,6 +59,10 @@ const syncPushSchema = z.object({
reviewLogs: z.array(syncReviewLogSchema).default([]),
});
+const syncPullQuerySchema = z.object({
+ lastSyncVersion: z.coerce.number().int().min(0).default(0),
+});
+
export function createSyncRouter(deps: SyncDependencies) {
const { syncRepo } = deps;
@@ -70,6 +75,14 @@ export function createSyncRouter(deps: SyncDependencies) {
const result = await syncRepo.pushChanges(user.id, data);
return c.json(result, 200);
+ })
+ .get("/pull", zValidator("query", syncPullQuerySchema), async (c) => {
+ const user = getAuthUser(c);
+ const query = c.req.valid("query") as SyncPullQuery;
+
+ const result = await syncRepo.pullChanges(user.id, query);
+
+ return c.json(result, 200);
});
}