Setting up basic API Structure
This commit is contained in:
@@ -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)';
|
||||
}
|
||||
Reference in New Issue
Block a user