Calling API in LatestReportColumn.dart
and improving UI
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
import 'package:ac_web/Api/Dtos/EReportType.dart';
|
||||
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.title,
|
||||
required this.author,
|
||||
required this.timestamp,
|
||||
required this.type,
|
||||
@@ -11,21 +13,27 @@ class ReportDto {
|
||||
});
|
||||
|
||||
final String id;
|
||||
final String title;
|
||||
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 EReportType type;
|
||||
|
||||
final String text;
|
||||
|
||||
factory ReportDto.fromJson(Map<String, dynamic> json) {
|
||||
return ReportDto(
|
||||
id: JsonReader.requireString(json, 'Id'),
|
||||
title: JsonReader.optionalString(json, 'Title') ?? '',
|
||||
author: JsonReader.requireString(json, 'Author'),
|
||||
timestamp: JsonReader.requireDateTime(json, 'Timestamp'),
|
||||
type: JsonReader.optionalString(json, 'Type') ?? '',
|
||||
type: JsonReader.enumValue(
|
||||
json,
|
||||
'Type',
|
||||
EReportType.values,
|
||||
(value) => value.wireName,
|
||||
EReportType.unknown,
|
||||
),
|
||||
text: JsonReader.optionalString(json, 'Text') ?? '',
|
||||
);
|
||||
}
|
||||
@@ -33,13 +41,15 @@ class ReportDto {
|
||||
Map<String, dynamic> toJson() {
|
||||
return <String, dynamic>{
|
||||
'Id': id,
|
||||
'Title': title,
|
||||
'Author': author,
|
||||
'Timestamp': timestamp.toIso8601String(),
|
||||
'Type': type,
|
||||
'Type': type.wireName,
|
||||
'Text': text,
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() => 'ReportDto(id: $id, author: $author, type: $type)';
|
||||
String toString() =>
|
||||
'ReportDto(id: $id, title: $title, author: $author, type: ${type.wireName})';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user