- Upgrade flutter_riverpod to 3.1.0, riverpod_annotation to 4.0.0 - Upgrade freezed to 3.2.3, freezed_annotation to 3.1.0 - Migrate freezed classes to use sealed keyword (freezed 3.x) - Update provider naming (*NotifierProvider → *Provider) - Add legacy.dart import for StateNotifierProvider compatibility - Fix valueOrNull → value for AsyncValue - Remove unused imports and fields - Add sync from Authentik button to users/groups pages - Suppress invalid_annotation_target warning in analysis_options 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
72 lines
2.0 KiB
Dart
72 lines
2.0 KiB
Dart
import 'package:dio/dio.dart';
|
|
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
|
import 'package:tatlock_ui/core/api/api_client.dart';
|
|
import 'package:tatlock_ui/features/control_room/containers/data/models/container_model.dart';
|
|
|
|
part 'containers_datasource.g.dart';
|
|
|
|
/// Remote data source for container operations.
|
|
class ContainersDatasource {
|
|
ContainersDatasource(this._dio);
|
|
|
|
final Dio _dio;
|
|
|
|
/// Gets all containers from the API.
|
|
Future<List<ContainerModel>> getContainers({bool all = true}) async {
|
|
final response = await _dio.get<List<dynamic>>(
|
|
'/infrastructure/containers',
|
|
queryParameters: {'all': all},
|
|
);
|
|
|
|
return response.data!
|
|
.map((json) => ContainerModel.fromJson(json as Map<String, dynamic>))
|
|
.toList();
|
|
}
|
|
|
|
/// Gets a single container by ID.
|
|
Future<ContainerModel> getContainer(String id) async {
|
|
final response = await _dio.get<Map<String, dynamic>>(
|
|
'/infrastructure/containers/$id',
|
|
);
|
|
|
|
return ContainerModel.fromJson(response.data!);
|
|
}
|
|
|
|
/// Performs an action on a container.
|
|
Future<void> containerAction(String id, String action) async {
|
|
await _dio.post<void>('/infrastructure/containers/$id/$action');
|
|
}
|
|
|
|
/// Gets container logs.
|
|
Future<String> getContainerLogs(
|
|
String id, {
|
|
int? tail,
|
|
bool timestamps = false,
|
|
}) async {
|
|
final response = await _dio.get<String>(
|
|
'/infrastructure/containers/$id/logs',
|
|
queryParameters: {
|
|
if (tail != null) 'tail': tail,
|
|
'timestamps': timestamps,
|
|
},
|
|
);
|
|
|
|
return response.data ?? '';
|
|
}
|
|
|
|
/// Removes a container.
|
|
Future<void> removeContainer(String id, {bool force = false}) async {
|
|
await _dio.delete<void>(
|
|
'/infrastructure/containers/$id',
|
|
queryParameters: {'force': force},
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Provides the containers datasource.
|
|
@riverpod
|
|
ContainersDatasource containersDatasource(Ref ref) {
|
|
final dio = ref.watch(coreApiClientProvider);
|
|
return ContainersDatasource(dio);
|
|
}
|