TermRemoteCtl/apps/mobile_app/lib/features/sessions/session_repository.dart

39 lines
1.2 KiB
Dart

import 'package:term_remote_ctl/core/network/agent_api_client.dart';
import 'package:term_remote_ctl/features/sessions/session.dart';
import 'package:term_remote_ctl/features/terminal/terminal_snapshot_storage.dart';
class SessionRepository {
SessionRepository(this._client, {TerminalSnapshotStorage? snapshotStorage})
: _snapshotStorage = snapshotStorage;
final AgentApiClient _client;
final TerminalSnapshotStorage? _snapshotStorage;
Future<List<Session>> listSessions() async {
final sessions = await _client.listSessions();
final mapped = sessions.map(Session.fromJson).toList(growable: false);
await _snapshotStorage?.pruneToSessionIds(
mapped.map((session) => session.sessionId).toSet(),
);
return mapped;
}
Future<Session> createSession({
String? name,
String? projectId,
String? workingDirectory,
}) async {
final session = await _client.createSession(
name: name,
projectId: projectId,
workingDirectory: workingDirectory,
);
return Session.fromJson(session);
}
Future<void> deleteSession(String sessionId) async {
await _client.deleteSession(sessionId);
await _snapshotStorage?.delete(sessionId);
}
}