Files
GameTime/server/lib/api/router.dart
Blomios 60912ebde4 feat(server): API de synchronisation incrémentale LWW (ticket #50)
Ajoute l'endpoint api/sync_api.dart, les use cases de synchronisation
(application/sync_use_cases.dart) et l'adapter Postgres
(infrastructure/postgres/synced_resource_repository.dart) implémentant
un upsert LWW atomique via CTE (INSERT ... ON CONFLICT ... WHERE
client_updated_at < EXCLUDED.client_updated_at, avec fallback UNION
ALL pour le cas ignoré). dart pub get OK, dart analyze clean, dart
test 15/15 vert. SQL d'upsert relu manuellement et jugé correct ; pas
de test de bout en bout contre un vrai PostgreSQL faute d'accès
Docker dans ce sandbox.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-19 10:23:36 +02:00

54 lines
1.3 KiB
Dart

import 'dart:convert';
import 'package:shelf/shelf.dart';
import 'package:shelf_router/shelf_router.dart';
import 'auth_api.dart';
import 'sync_api.dart';
Handler buildApiHandler({AuthApi? authApi, SyncApi? syncApi}) {
final router = Router()
..get('/health', (Request request) {
return Response.ok(
jsonEncode({'status': 'ok'}),
headers: {'content-type': 'application/json'},
);
});
if (authApi != null) {
router
..post('/auth/register', authApi.register)
..post('/auth/login', authApi.loginUser)
..post(
'/auth/logout',
authenticationMiddleware(authApi.authenticateRequest.execute)(
authApi.logoutUser,
),
);
}
if (syncApi != null) {
router
..post(
'/sync/push',
authenticationMiddleware(syncApi.authenticateRequest.execute)(
syncApi.push,
),
)
..get(
'/sync/pull',
authenticationMiddleware(syncApi.authenticateRequest.execute)(
syncApi.pull,
),
)
..post(
'/sync/exchange',
authenticationMiddleware(syncApi.authenticateRequest.execute)(
syncApi.exchange,
),
);
}
return const Pipeline().addMiddleware(logRequests()).addHandler(router.call);
}