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 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 toJson() { return { 'Id': id, 'Author': author, 'Timestamp': timestamp.toIso8601String(), 'Type': type, 'Text': text, }; } @override String toString() => 'ReportDto(id: $id, author: $author, type: $type)'; }