Setting up basic API Structure

This commit is contained in:
2026-08-28 14:54:54 +02:00
parent 968228cbc3
commit b3a13cd5a2
18 changed files with 974 additions and 0 deletions
+58
View File
@@ -0,0 +1,58 @@
import 'package:ac_web/Api/Dtos/AgentTaskDto.dart';
import 'package:ac_web/Api/Dtos/EAgentStatus.dart';
import 'package:ac_web/Api/Dtos/EAgentType.dart';
import 'package:ac_web/Api/JsonReader.dart';
/// Dart counterpart of the backend `AgentData` returned by `GET /agents`.
class AgentDto {
const AgentDto({
required this.name,
required this.type,
required this.lastSeen,
required this.tasks,
required this.status,
});
final String name;
final EAgentType type;
final DateTime lastSeen;
final List<AgentTaskDto> tasks;
final EAgentStatus status;
bool get hasTasks => tasks.isNotEmpty;
factory AgentDto.fromJson(Map<String, dynamic> json) {
return AgentDto(
name: JsonReader.requireString(json, 'Name'),
type: JsonReader.enumValue(
json,
'Type',
EAgentType.values,
(value) => value.name,
EAgentType.unknown,
),
lastSeen: JsonReader.requireDateTime(json, 'LastSeen'),
tasks: JsonReader.list(json, 'Tasks', AgentTaskDto.fromJson),
status: JsonReader.enumValue(
json,
'Status',
EAgentStatus.values,
(value) => value.name,
EAgentStatus.unknown,
),
);
}
Map<String, dynamic> toJson() {
return <String, dynamic>{
'Name': name,
'Type': type.name,
'LastSeen': lastSeen.toIso8601String(),
'Tasks': tasks.map((task) => task.toJson()).toList(growable: false),
'Status': status.name,
};
}
@override
String toString() => 'AgentDto(name: $name, type: ${type.name}, status: ${status.name})';
}