73 lines
2.4 KiB
Dart
73 lines
2.4 KiB
Dart
import 'package:json_annotation/json_annotation.dart';
|
|
part 'classes.g.dart';
|
|
|
|
/*
|
|
Voyage Handbook - The open-source WikiVoyage reader
|
|
Copyright (C) 2023 Matyáš Caras
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License version 3 as published by
|
|
the Free Software Foundation.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
@JsonSerializable()
|
|
class SearchResponse {
|
|
final int id;
|
|
final String key;
|
|
final String title;
|
|
final String excerpt;
|
|
final String? description;
|
|
const SearchResponse(
|
|
this.id, this.key, this.title, this.excerpt, this.description);
|
|
|
|
/// Connect the generated function to the `fromJson`
|
|
/// factory.
|
|
factory SearchResponse.fromJson(Map<String, dynamic> json) =>
|
|
_$SearchResponseFromJson(json);
|
|
|
|
/// Connect the generated function to the `toJson` method.
|
|
Map<String, dynamic> toJson() => _$SearchResponseToJson(this);
|
|
}
|
|
|
|
@JsonSerializable()
|
|
class LicenseAttribution {
|
|
final String url;
|
|
final String title;
|
|
const LicenseAttribution(this.url, this.title);
|
|
factory LicenseAttribution.fromJson(Map<String, dynamic> json) =>
|
|
_$LicenseAttributionFromJson(json);
|
|
|
|
/// Connect the generated function to the `toJson` method.
|
|
Map<String, dynamic> toJson() => _$LicenseAttributionToJson(this);
|
|
}
|
|
|
|
@JsonSerializable()
|
|
class RawPage {
|
|
final int id;
|
|
final String key;
|
|
final String title;
|
|
@JsonKey(fromJson: _editedFromJson, toJson: _editedToJson, name: "latest")
|
|
final String edited;
|
|
final String html;
|
|
final LicenseAttribution license;
|
|
|
|
const RawPage(
|
|
this.id, this.key, this.title, this.edited, this.html, this.license);
|
|
|
|
factory RawPage.fromJson(Map<String, dynamic> json) =>
|
|
_$RawPageFromJson(json);
|
|
|
|
/// Connect the generated function to the `toJson` method.
|
|
Map<String, dynamic> toJson() => _$RawPageToJson(this);
|
|
|
|
static String _editedFromJson(Map<String, dynamic> json) => json["timestamp"];
|
|
static Map<String, dynamic> _editedToJson(String json) => {"timestamp": json};
|
|
}
|