Initial commit: unionflow-mobile-apps
Application Flutter complète (sans build artifacts). Signed-off-by: lions dev Team
This commit is contained in:
60
lib/features/logs/data/models/system_alert_model.dart
Normal file
60
lib/features/logs/data/models/system_alert_model.dart
Normal file
@@ -0,0 +1,60 @@
|
||||
/// Modèle d'alerte système
|
||||
/// Correspond à SystemAlertResponse du backend
|
||||
library system_alert_model;
|
||||
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'system_alert_model.g.dart';
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class SystemAlertModel extends Equatable {
|
||||
final String? id;
|
||||
final String? level; // CRITICAL, ERROR, WARNING, INFO
|
||||
final String? title;
|
||||
final String? message;
|
||||
final DateTime? timestamp;
|
||||
final bool? acknowledged;
|
||||
final String? acknowledgedBy;
|
||||
final DateTime? acknowledgedAt;
|
||||
final String? source;
|
||||
final String? alertType;
|
||||
final double? currentValue;
|
||||
final double? thresholdValue;
|
||||
|
||||
const SystemAlertModel({
|
||||
this.id,
|
||||
this.level,
|
||||
this.title,
|
||||
this.message,
|
||||
this.timestamp,
|
||||
this.acknowledged,
|
||||
this.acknowledgedBy,
|
||||
this.acknowledgedAt,
|
||||
this.source,
|
||||
this.alertType,
|
||||
this.currentValue,
|
||||
this.thresholdValue,
|
||||
});
|
||||
|
||||
factory SystemAlertModel.fromJson(Map<String, dynamic> json) =>
|
||||
_$SystemAlertModelFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$SystemAlertModelToJson(this);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
id,
|
||||
level,
|
||||
title,
|
||||
message,
|
||||
timestamp,
|
||||
acknowledged,
|
||||
acknowledgedBy,
|
||||
acknowledgedAt,
|
||||
source,
|
||||
alertType,
|
||||
currentValue,
|
||||
thresholdValue,
|
||||
];
|
||||
}
|
||||
43
lib/features/logs/data/models/system_alert_model.g.dart
Normal file
43
lib/features/logs/data/models/system_alert_model.g.dart
Normal file
@@ -0,0 +1,43 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'system_alert_model.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
SystemAlertModel _$SystemAlertModelFromJson(Map<String, dynamic> json) =>
|
||||
SystemAlertModel(
|
||||
id: json['id'] as String?,
|
||||
level: json['level'] as String?,
|
||||
title: json['title'] as String?,
|
||||
message: json['message'] as String?,
|
||||
timestamp: json['timestamp'] == null
|
||||
? null
|
||||
: DateTime.parse(json['timestamp'] as String),
|
||||
acknowledged: json['acknowledged'] as bool?,
|
||||
acknowledgedBy: json['acknowledgedBy'] as String?,
|
||||
acknowledgedAt: json['acknowledgedAt'] == null
|
||||
? null
|
||||
: DateTime.parse(json['acknowledgedAt'] as String),
|
||||
source: json['source'] as String?,
|
||||
alertType: json['alertType'] as String?,
|
||||
currentValue: (json['currentValue'] as num?)?.toDouble(),
|
||||
thresholdValue: (json['thresholdValue'] as num?)?.toDouble(),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$SystemAlertModelToJson(SystemAlertModel instance) =>
|
||||
<String, dynamic>{
|
||||
'id': instance.id,
|
||||
'level': instance.level,
|
||||
'title': instance.title,
|
||||
'message': instance.message,
|
||||
'timestamp': instance.timestamp?.toIso8601String(),
|
||||
'acknowledged': instance.acknowledged,
|
||||
'acknowledgedBy': instance.acknowledgedBy,
|
||||
'acknowledgedAt': instance.acknowledgedAt?.toIso8601String(),
|
||||
'source': instance.source,
|
||||
'alertType': instance.alertType,
|
||||
'currentValue': instance.currentValue,
|
||||
'thresholdValue': instance.thresholdValue,
|
||||
};
|
||||
54
lib/features/logs/data/models/system_log_model.dart
Normal file
54
lib/features/logs/data/models/system_log_model.dart
Normal file
@@ -0,0 +1,54 @@
|
||||
/// Modèle d'entrée de log système
|
||||
/// Correspond à SystemLogResponse du backend
|
||||
library system_log_model;
|
||||
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'system_log_model.g.dart';
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class SystemLogModel extends Equatable {
|
||||
final String? id;
|
||||
final String? level; // CRITICAL, ERROR, WARN, INFO, DEBUG, TRACE
|
||||
final String? source; // API, Auth, Database, Cache, Security, Performance, System
|
||||
final String? message;
|
||||
final String? details;
|
||||
final DateTime? timestamp;
|
||||
final String? username;
|
||||
final String? ipAddress;
|
||||
final String? requestId;
|
||||
final String? stackTrace;
|
||||
|
||||
const SystemLogModel({
|
||||
this.id,
|
||||
this.level,
|
||||
this.source,
|
||||
this.message,
|
||||
this.details,
|
||||
this.timestamp,
|
||||
this.username,
|
||||
this.ipAddress,
|
||||
this.requestId,
|
||||
this.stackTrace,
|
||||
});
|
||||
|
||||
factory SystemLogModel.fromJson(Map<String, dynamic> json) =>
|
||||
_$SystemLogModelFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$SystemLogModelToJson(this);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
id,
|
||||
level,
|
||||
source,
|
||||
message,
|
||||
details,
|
||||
timestamp,
|
||||
username,
|
||||
ipAddress,
|
||||
requestId,
|
||||
stackTrace,
|
||||
];
|
||||
}
|
||||
37
lib/features/logs/data/models/system_log_model.g.dart
Normal file
37
lib/features/logs/data/models/system_log_model.g.dart
Normal file
@@ -0,0 +1,37 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'system_log_model.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
SystemLogModel _$SystemLogModelFromJson(Map<String, dynamic> json) =>
|
||||
SystemLogModel(
|
||||
id: json['id'] as String?,
|
||||
level: json['level'] as String?,
|
||||
source: json['source'] as String?,
|
||||
message: json['message'] as String?,
|
||||
details: json['details'] as String?,
|
||||
timestamp: json['timestamp'] == null
|
||||
? null
|
||||
: DateTime.parse(json['timestamp'] as String),
|
||||
username: json['username'] as String?,
|
||||
ipAddress: json['ipAddress'] as String?,
|
||||
requestId: json['requestId'] as String?,
|
||||
stackTrace: json['stackTrace'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$SystemLogModelToJson(SystemLogModel instance) =>
|
||||
<String, dynamic>{
|
||||
'id': instance.id,
|
||||
'level': instance.level,
|
||||
'source': instance.source,
|
||||
'message': instance.message,
|
||||
'details': instance.details,
|
||||
'timestamp': instance.timestamp?.toIso8601String(),
|
||||
'username': instance.username,
|
||||
'ipAddress': instance.ipAddress,
|
||||
'requestId': instance.requestId,
|
||||
'stackTrace': instance.stackTrace,
|
||||
};
|
||||
66
lib/features/logs/data/models/system_metrics_model.dart
Normal file
66
lib/features/logs/data/models/system_metrics_model.dart
Normal file
@@ -0,0 +1,66 @@
|
||||
/// Modèle des métriques système
|
||||
/// Correspond à SystemMetricsResponse du backend
|
||||
library system_metrics_model;
|
||||
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'system_metrics_model.g.dart';
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class SystemMetricsModel extends Equatable {
|
||||
final double? cpuUsagePercent;
|
||||
final double? memoryUsagePercent;
|
||||
final double? diskUsagePercent;
|
||||
final double? networkUsageMbps;
|
||||
final int? activeConnections;
|
||||
final double? errorRate;
|
||||
final int? averageResponseTimeMs;
|
||||
final int? uptime;
|
||||
final String? uptimeFormatted;
|
||||
final int? totalLogs24h;
|
||||
final int? totalErrors24h;
|
||||
final int? totalWarnings24h;
|
||||
final int? totalRequests24h;
|
||||
final DateTime? timestamp;
|
||||
|
||||
const SystemMetricsModel({
|
||||
this.cpuUsagePercent,
|
||||
this.memoryUsagePercent,
|
||||
this.diskUsagePercent,
|
||||
this.networkUsageMbps,
|
||||
this.activeConnections,
|
||||
this.errorRate,
|
||||
this.averageResponseTimeMs,
|
||||
this.uptime,
|
||||
this.uptimeFormatted,
|
||||
this.totalLogs24h,
|
||||
this.totalErrors24h,
|
||||
this.totalWarnings24h,
|
||||
this.totalRequests24h,
|
||||
this.timestamp,
|
||||
});
|
||||
|
||||
factory SystemMetricsModel.fromJson(Map<String, dynamic> json) =>
|
||||
_$SystemMetricsModelFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$SystemMetricsModelToJson(this);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
cpuUsagePercent,
|
||||
memoryUsagePercent,
|
||||
diskUsagePercent,
|
||||
networkUsageMbps,
|
||||
activeConnections,
|
||||
errorRate,
|
||||
averageResponseTimeMs,
|
||||
uptime,
|
||||
uptimeFormatted,
|
||||
totalLogs24h,
|
||||
totalErrors24h,
|
||||
totalWarnings24h,
|
||||
totalRequests24h,
|
||||
timestamp,
|
||||
];
|
||||
}
|
||||
45
lib/features/logs/data/models/system_metrics_model.g.dart
Normal file
45
lib/features/logs/data/models/system_metrics_model.g.dart
Normal file
@@ -0,0 +1,45 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'system_metrics_model.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
SystemMetricsModel _$SystemMetricsModelFromJson(Map<String, dynamic> json) =>
|
||||
SystemMetricsModel(
|
||||
cpuUsagePercent: (json['cpuUsagePercent'] as num?)?.toDouble(),
|
||||
memoryUsagePercent: (json['memoryUsagePercent'] as num?)?.toDouble(),
|
||||
diskUsagePercent: (json['diskUsagePercent'] as num?)?.toDouble(),
|
||||
networkUsageMbps: (json['networkUsageMbps'] as num?)?.toDouble(),
|
||||
activeConnections: (json['activeConnections'] as num?)?.toInt(),
|
||||
errorRate: (json['errorRate'] as num?)?.toDouble(),
|
||||
averageResponseTimeMs: (json['averageResponseTimeMs'] as num?)?.toInt(),
|
||||
uptime: (json['uptime'] as num?)?.toInt(),
|
||||
uptimeFormatted: json['uptimeFormatted'] as String?,
|
||||
totalLogs24h: (json['totalLogs24h'] as num?)?.toInt(),
|
||||
totalErrors24h: (json['totalErrors24h'] as num?)?.toInt(),
|
||||
totalWarnings24h: (json['totalWarnings24h'] as num?)?.toInt(),
|
||||
totalRequests24h: (json['totalRequests24h'] as num?)?.toInt(),
|
||||
timestamp: json['timestamp'] == null
|
||||
? null
|
||||
: DateTime.parse(json['timestamp'] as String),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$SystemMetricsModelToJson(SystemMetricsModel instance) =>
|
||||
<String, dynamic>{
|
||||
'cpuUsagePercent': instance.cpuUsagePercent,
|
||||
'memoryUsagePercent': instance.memoryUsagePercent,
|
||||
'diskUsagePercent': instance.diskUsagePercent,
|
||||
'networkUsageMbps': instance.networkUsageMbps,
|
||||
'activeConnections': instance.activeConnections,
|
||||
'errorRate': instance.errorRate,
|
||||
'averageResponseTimeMs': instance.averageResponseTimeMs,
|
||||
'uptime': instance.uptime,
|
||||
'uptimeFormatted': instance.uptimeFormatted,
|
||||
'totalLogs24h': instance.totalLogs24h,
|
||||
'totalErrors24h': instance.totalErrors24h,
|
||||
'totalWarnings24h': instance.totalWarnings24h,
|
||||
'totalRequests24h': instance.totalRequests24h,
|
||||
'timestamp': instance.timestamp?.toIso8601String(),
|
||||
};
|
||||
@@ -0,0 +1,93 @@
|
||||
/// Repository pour la gestion des logs et du monitoring système
|
||||
/// Interface avec l'API backend LogsMonitoringResource
|
||||
library logs_monitoring_repository;
|
||||
|
||||
import 'package:injectable/injectable.dart';
|
||||
import 'package:unionflow_mobile_apps/core/network/api_client.dart';
|
||||
import '../models/system_log_model.dart';
|
||||
import '../models/system_metrics_model.dart';
|
||||
import '../models/system_alert_model.dart';
|
||||
|
||||
abstract class LogsMonitoringRepository {
|
||||
Future<List<SystemLogModel>> searchLogs({
|
||||
String? level,
|
||||
String? source,
|
||||
String? searchQuery,
|
||||
String? timeRange,
|
||||
});
|
||||
Future<SystemMetricsModel> getMetrics();
|
||||
Future<List<SystemAlertModel>> getAlerts();
|
||||
Future<void> acknowledgeAlert(String alertId);
|
||||
}
|
||||
|
||||
@LazySingleton(as: LogsMonitoringRepository)
|
||||
class LogsMonitoringRepositoryImpl implements LogsMonitoringRepository {
|
||||
final ApiClient _apiClient;
|
||||
|
||||
LogsMonitoringRepositoryImpl(this._apiClient);
|
||||
|
||||
List<dynamic> _parseListResponse(dynamic data) {
|
||||
if (data is List) return data;
|
||||
if (data is Map && data.containsKey('content')) {
|
||||
final content = data['content'];
|
||||
return content is List ? content : [];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<SystemLogModel>> searchLogs({
|
||||
String? level,
|
||||
String? source,
|
||||
String? searchQuery,
|
||||
String? timeRange,
|
||||
}) async {
|
||||
final response = await _apiClient.post(
|
||||
'/api/logs/search',
|
||||
data: {
|
||||
'level': level ?? 'TOUS',
|
||||
'source': source ?? 'TOUS',
|
||||
'searchQuery': searchQuery,
|
||||
'timeRange': timeRange ?? 'Dernières 24h',
|
||||
'page': 0,
|
||||
'pageSize': 100,
|
||||
},
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
final data = _parseListResponse(response.data);
|
||||
return data
|
||||
.map((e) => SystemLogModel.fromJson(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
}
|
||||
throw Exception('Erreur ${response.statusCode}');
|
||||
}
|
||||
|
||||
@override
|
||||
Future<SystemMetricsModel> getMetrics() async {
|
||||
final response = await _apiClient.get('/api/monitoring/metrics');
|
||||
if (response.statusCode == 200) {
|
||||
return SystemMetricsModel.fromJson(response.data as Map<String, dynamic>);
|
||||
}
|
||||
throw Exception('Erreur ${response.statusCode}');
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<SystemAlertModel>> getAlerts() async {
|
||||
final response = await _apiClient.get('/api/alerts');
|
||||
if (response.statusCode == 200) {
|
||||
final data = _parseListResponse(response.data);
|
||||
return data
|
||||
.map((e) => SystemAlertModel.fromJson(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
}
|
||||
throw Exception('Erreur ${response.statusCode}');
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> acknowledgeAlert(String alertId) async {
|
||||
final response = await _apiClient.post('/api/alerts/$alertId/acknowledge');
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception('Erreur ${response.statusCode}');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user