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>
This commit is contained in:
@ -2,6 +2,7 @@ import 'dart:io';
|
||||
|
||||
import 'package:gametime_server/api/auth_api.dart';
|
||||
import 'package:gametime_server/api/router.dart';
|
||||
import 'package:gametime_server/api/sync_api.dart';
|
||||
import 'package:gametime_server/application/application.dart';
|
||||
import 'package:gametime_server/infrastructure/postgres/postgres.dart';
|
||||
import 'package:gametime_server/infrastructure/security/security.dart';
|
||||
@ -15,6 +16,7 @@ Future<void> main(List<String> arguments) async {
|
||||
|
||||
final users = PostgresUserRepository(connection);
|
||||
final sessions = PostgresAuthSessionRepository(connection);
|
||||
final resources = PostgresSyncedResourceRepository(connection);
|
||||
final passwordHasher = Pbkdf2PasswordHasher();
|
||||
final tokens = SecureOpaqueTokenService();
|
||||
const clock = SystemClock();
|
||||
@ -43,9 +45,21 @@ Future<void> main(List<String> arguments) async {
|
||||
logout: LogoutUseCase(sessions: sessions, tokens: tokens, clock: clock),
|
||||
authenticateRequest: authenticateRequest,
|
||||
);
|
||||
final pushSync = PushSyncUseCase(
|
||||
resources: resources,
|
||||
clock: clock,
|
||||
ids: ids,
|
||||
);
|
||||
final pullSync = PullSyncUseCase(resources: resources, clock: clock);
|
||||
final syncApi = SyncApi(
|
||||
pushSync: pushSync,
|
||||
pullSync: pullSync,
|
||||
exchangeSync: ExchangeSyncUseCase(push: pushSync, pull: pullSync),
|
||||
authenticateRequest: authenticateRequest,
|
||||
);
|
||||
|
||||
final server = await shelf_io.serve(
|
||||
buildApiHandler(authApi: authApi),
|
||||
buildApiHandler(authApi: authApi, syncApi: syncApi),
|
||||
InternetAddress.anyIPv4,
|
||||
port,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user