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/JsonReader.dart';
/// Dart counterpart of the backend `AgentTaskDto`.
///
/// The exact shape of the backend dto is not final yet, therefore everything
/// except the name is treated as optional. Unknown properties are simply
/// ignored, so this dto keeps working while the api grows.
class AgentTaskDto {
const AgentTaskDto({
required this.name,
this.id,
this.description,
this.status,
this.progress,
this.createdAt,
this.finishedAt,
});
final String name;
final String? id;
final String? description;
final String? status;
/// Completion between 0 and 100 if the api reports it.
final int? progress;
final DateTime? createdAt;
final DateTime? finishedAt;
bool get isFinished => finishedAt != null;
factory AgentTaskDto.fromJson(Map<String, dynamic> json) {
return AgentTaskDto(
name: JsonReader.optionalString(json, 'Name') ?? '',
id: JsonReader.optionalString(json, 'Id'),
description: JsonReader.optionalString(json, 'Description'),
status: JsonReader.optionalString(json, 'Status'),
progress: JsonReader.optionalInt(json, 'Progress'),
createdAt: JsonReader.optionalDateTime(json, 'CreatedAt'),
finishedAt: JsonReader.optionalDateTime(json, 'FinishedAt'),
);
}
Map<String, dynamic> toJson() {
return <String, dynamic>{
'Name': name,
if (id != null) 'Id': id,
if (description != null) 'Description': description,
if (status != null) 'Status': status,
if (progress != null) 'Progress': progress,
if (createdAt != null) 'CreatedAt': createdAt!.toIso8601String(),
if (finishedAt != null) 'FinishedAt': finishedAt!.toIso8601String(),
};
}
@override
String toString() => 'AgentTaskDto(name: $name, status: $status)';
}