initial commit
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
import '../../core/models/models.dart';
|
||||
import '../../core/network/api_client_provider.dart';
|
||||
import '../../core/network/node_master_api_client.dart';
|
||||
|
||||
part 'services_repository.g.dart';
|
||||
|
||||
/// Wraps the `/services/*` endpoints — the compose-based services on this
|
||||
/// host and their start/stop/backup actions.
|
||||
class ServicesRepository {
|
||||
const ServicesRepository(this._client);
|
||||
|
||||
final NodeMasterApiClient _client;
|
||||
|
||||
Future<List<Service>> getAll() => _client.getAllServices();
|
||||
Future<Service> get(String id) => _client.getService(id);
|
||||
Future<Service> add(Service service) => _client.addService(service);
|
||||
Future<Service> update(String id, Service service) => _client.updateService(id, service);
|
||||
Future<void> delete(String id) => _client.deleteService(id);
|
||||
Future<void> start(String id) => _client.startService(id);
|
||||
Future<void> stop(String id) => _client.stopService(id);
|
||||
Future<void> backupNow(String id) => _client.backupService(id);
|
||||
|
||||
Future<List<BackupTarget>> getBackupTargets(String id) => _client.getServiceBackupTargets(id);
|
||||
Future<BackupTarget> addBackupTarget(String id, BackupTarget target) =>
|
||||
_client.addServiceBackupTarget(id, target);
|
||||
Future<BackupTarget> updateBackupTarget(String id, String targetId, BackupTarget target) =>
|
||||
_client.updateServiceBackupTarget(id, targetId, target);
|
||||
Future<void> deleteBackupTarget(String id, String targetId) =>
|
||||
_client.deleteServiceBackupTarget(id, targetId);
|
||||
Future<void> runBackupTarget(String id, String targetId) =>
|
||||
_client.runServiceBackupTarget(id, targetId);
|
||||
Future<RunState> getBackupTargetProgress(String id, String targetId) =>
|
||||
_client.getServiceBackupTargetProgress(id, targetId);
|
||||
Future<List<RunState>> getBackupProgress(String id) => _client.getServiceBackupProgress(id);
|
||||
}
|
||||
|
||||
/// Null when no connection is active, mirroring [apiClientProvider].
|
||||
@riverpod
|
||||
ServicesRepository? servicesRepository(Ref ref) {
|
||||
final client = ref.watch(apiClientProvider);
|
||||
if (client == null) return null;
|
||||
return ServicesRepository(client);
|
||||
}
|
||||
|
||||
/// The full services list for the active connection. Manual-refresh only
|
||||
/// (not polled) — this is a detail-heavy table screen where a mid-edit
|
||||
/// slide-over silently refreshing underneath the user would be worse than
|
||||
/// slightly stale data; Dashboard's polled summary is where "did something
|
||||
/// change" gets noticed at a glance.
|
||||
@riverpod
|
||||
Future<List<Service>> servicesList(Ref ref) async {
|
||||
final repo = ref.watch(servicesRepositoryProvider);
|
||||
if (repo == null) return [];
|
||||
return repo.getAll();
|
||||
}
|
||||
Reference in New Issue
Block a user