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
+45
View File
@@ -0,0 +1,45 @@
import 'package:ac_web/Api/JsonReader.dart';
/// Dart counterpart of the backend `ReportDto` returned by `GET /reports`.
class ReportDto {
const ReportDto({
required this.id,
required this.author,
required this.timestamp,
required this.type,
required this.text,
});
final String id;
final String author;
final DateTime timestamp;
/// Free form report type. The backend sends this as a plain string, so it is
/// intentionally not modelled as an enum here.
final String type;
final String text;
factory ReportDto.fromJson(Map<String, dynamic> json) {
return ReportDto(
id: JsonReader.requireString(json, 'Id'),
author: JsonReader.requireString(json, 'Author'),
timestamp: JsonReader.requireDateTime(json, 'Timestamp'),
type: JsonReader.optionalString(json, 'Type') ?? '',
text: JsonReader.optionalString(json, 'Text') ?? '',
);
}
Map<String, dynamic> toJson() {
return <String, dynamic>{
'Id': id,
'Author': author,
'Timestamp': timestamp.toIso8601String(),
'Type': type,
'Text': text,
};
}
@override
String toString() => 'ReportDto(id: $id, author: $author, type: $type)';
}