2017-06-17 01:26:19 +00:00
|
|
|
// GENERATED CODE - DO NOT MODIFY BY HAND
|
|
|
|
|
|
|
|
part of angel_serialize.test.models.book;
|
|
|
|
|
|
|
|
// **************************************************************************
|
2018-06-29 04:11:57 +00:00
|
|
|
// JsonModelGenerator
|
2017-06-17 01:26:19 +00:00
|
|
|
// **************************************************************************
|
|
|
|
|
2018-07-11 15:45:45 +00:00
|
|
|
@generatedSerializable
|
2019-01-07 00:56:05 +00:00
|
|
|
@pragma('hello')
|
|
|
|
@SerializableField(alias: 'omg')
|
2018-02-27 19:57:05 +00:00
|
|
|
class Book extends _Book {
|
|
|
|
Book(
|
|
|
|
{this.id,
|
2019-04-08 04:41:58 +00:00
|
|
|
this.author,
|
|
|
|
this.title,
|
|
|
|
this.description,
|
|
|
|
this.pageCount,
|
|
|
|
List<double> notModels,
|
2018-03-09 12:43:17 +00:00
|
|
|
this.camelCaseString,
|
2018-02-27 19:57:05 +00:00
|
|
|
this.createdAt,
|
2018-05-15 19:01:13 +00:00
|
|
|
this.updatedAt})
|
|
|
|
: this.notModels = new List.unmodifiable(notModels ?? []);
|
2018-02-27 19:57:05 +00:00
|
|
|
|
2018-02-28 00:36:53 +00:00
|
|
|
@override
|
2018-02-27 19:47:42 +00:00
|
|
|
final String id;
|
2017-06-17 01:26:19 +00:00
|
|
|
|
2018-02-28 00:36:53 +00:00
|
|
|
@override
|
2018-02-27 19:47:42 +00:00
|
|
|
final String author;
|
2017-06-17 01:26:19 +00:00
|
|
|
|
2018-02-28 00:36:53 +00:00
|
|
|
@override
|
2018-02-27 19:47:42 +00:00
|
|
|
final String title;
|
2017-06-17 01:26:19 +00:00
|
|
|
|
2018-02-28 00:36:53 +00:00
|
|
|
@override
|
2018-02-27 19:47:42 +00:00
|
|
|
final String description;
|
2017-06-17 01:26:19 +00:00
|
|
|
|
2019-04-08 15:00:04 +00:00
|
|
|
/// The number of pages the book has.
|
2018-02-28 00:36:53 +00:00
|
|
|
@override
|
2018-02-27 19:47:42 +00:00
|
|
|
final int pageCount;
|
2017-06-17 01:26:19 +00:00
|
|
|
|
2018-03-05 06:18:46 +00:00
|
|
|
@override
|
|
|
|
final List<double> notModels;
|
|
|
|
|
2018-03-09 12:43:17 +00:00
|
|
|
@override
|
|
|
|
final String camelCaseString;
|
|
|
|
|
2018-02-28 00:36:53 +00:00
|
|
|
@override
|
2018-02-27 19:47:42 +00:00
|
|
|
final DateTime createdAt;
|
2017-06-17 01:26:19 +00:00
|
|
|
|
2018-02-28 00:36:53 +00:00
|
|
|
@override
|
2018-02-27 19:47:42 +00:00
|
|
|
final DateTime updatedAt;
|
2018-02-28 00:36:53 +00:00
|
|
|
|
|
|
|
Book copyWith(
|
|
|
|
{String id,
|
|
|
|
String author,
|
|
|
|
String title,
|
|
|
|
String description,
|
|
|
|
int pageCount,
|
2018-03-05 06:18:46 +00:00
|
|
|
List<double> notModels,
|
2018-03-09 12:43:17 +00:00
|
|
|
String camelCaseString,
|
2018-02-28 00:36:53 +00:00
|
|
|
DateTime createdAt,
|
|
|
|
DateTime updatedAt}) {
|
|
|
|
return new Book(
|
|
|
|
id: id ?? this.id,
|
|
|
|
author: author ?? this.author,
|
|
|
|
title: title ?? this.title,
|
|
|
|
description: description ?? this.description,
|
|
|
|
pageCount: pageCount ?? this.pageCount,
|
2018-03-05 06:18:46 +00:00
|
|
|
notModels: notModels ?? this.notModels,
|
2018-03-09 12:43:17 +00:00
|
|
|
camelCaseString: camelCaseString ?? this.camelCaseString,
|
2018-02-28 00:36:53 +00:00
|
|
|
createdAt: createdAt ?? this.createdAt,
|
|
|
|
updatedAt: updatedAt ?? this.updatedAt);
|
|
|
|
}
|
2018-02-28 01:49:14 +00:00
|
|
|
|
2018-05-13 18:02:47 +00:00
|
|
|
bool operator ==(other) {
|
|
|
|
return other is _Book &&
|
|
|
|
other.id == id &&
|
|
|
|
other.author == author &&
|
|
|
|
other.title == title &&
|
|
|
|
other.description == description &&
|
|
|
|
other.pageCount == pageCount &&
|
|
|
|
const ListEquality<double>(const DefaultEquality<double>())
|
|
|
|
.equals(other.notModels, notModels) &&
|
|
|
|
other.camelCaseString == camelCaseString &&
|
|
|
|
other.createdAt == createdAt &&
|
|
|
|
other.updatedAt == updatedAt;
|
|
|
|
}
|
|
|
|
|
2018-11-03 07:36:59 +00:00
|
|
|
@override
|
|
|
|
int get hashCode {
|
|
|
|
return hashObjects([
|
|
|
|
id,
|
|
|
|
author,
|
|
|
|
title,
|
|
|
|
description,
|
|
|
|
pageCount,
|
|
|
|
notModels,
|
|
|
|
camelCaseString,
|
|
|
|
createdAt,
|
|
|
|
updatedAt
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2019-04-08 15:00:04 +00:00
|
|
|
@override
|
|
|
|
String toString() {
|
|
|
|
return "Book(id=$id, author=$author, title=$title, description=$description, pageCount=$pageCount, notModels=$notModels, camelCaseString=$camelCaseString, createdAt=$createdAt, updatedAt=$updatedAt)";
|
|
|
|
}
|
|
|
|
|
2018-02-28 01:49:14 +00:00
|
|
|
Map<String, dynamic> toJson() {
|
|
|
|
return BookSerializer.toMap(this);
|
|
|
|
}
|
2017-06-17 01:26:19 +00:00
|
|
|
}
|
2018-12-08 20:53:49 +00:00
|
|
|
|
2019-04-08 04:41:58 +00:00
|
|
|
@generatedSerializable
|
|
|
|
class Author extends _Author {
|
|
|
|
Author(
|
|
|
|
{this.id,
|
|
|
|
@required this.name,
|
|
|
|
@required this.age,
|
|
|
|
List<_Book> books,
|
|
|
|
this.newestBook,
|
|
|
|
this.secret,
|
|
|
|
this.obscured,
|
|
|
|
this.createdAt,
|
|
|
|
this.updatedAt})
|
|
|
|
: this.books = new List.unmodifiable(books ?? []);
|
2018-12-08 20:53:49 +00:00
|
|
|
|
2019-04-08 04:41:58 +00:00
|
|
|
@override
|
|
|
|
final String id;
|
2019-04-04 21:40:36 +00:00
|
|
|
|
2019-04-08 04:41:58 +00:00
|
|
|
@override
|
|
|
|
final String name;
|
2019-04-04 21:40:36 +00:00
|
|
|
|
2019-04-08 04:41:58 +00:00
|
|
|
@override
|
|
|
|
final int age;
|
2019-04-04 21:40:36 +00:00
|
|
|
|
2019-04-08 04:41:58 +00:00
|
|
|
@override
|
|
|
|
final List<_Book> books;
|
2019-04-04 21:40:36 +00:00
|
|
|
|
2019-04-08 15:00:04 +00:00
|
|
|
/// The newest book.
|
2019-04-08 04:41:58 +00:00
|
|
|
@override
|
|
|
|
final _Book newestBook;
|
|
|
|
|
|
|
|
@override
|
|
|
|
final String secret;
|
|
|
|
|
|
|
|
@override
|
|
|
|
final String obscured;
|
|
|
|
|
|
|
|
@override
|
|
|
|
final DateTime createdAt;
|
|
|
|
|
|
|
|
@override
|
|
|
|
final DateTime updatedAt;
|
|
|
|
|
|
|
|
Author copyWith(
|
|
|
|
{String id,
|
|
|
|
String name,
|
|
|
|
int age,
|
|
|
|
List<_Book> books,
|
|
|
|
_Book newestBook,
|
|
|
|
String secret,
|
|
|
|
String obscured,
|
|
|
|
DateTime createdAt,
|
|
|
|
DateTime updatedAt}) {
|
|
|
|
return new Author(
|
|
|
|
id: id ?? this.id,
|
|
|
|
name: name ?? this.name,
|
|
|
|
age: age ?? this.age,
|
|
|
|
books: books ?? this.books,
|
|
|
|
newestBook: newestBook ?? this.newestBook,
|
|
|
|
secret: secret ?? this.secret,
|
|
|
|
obscured: obscured ?? this.obscured,
|
|
|
|
createdAt: createdAt ?? this.createdAt,
|
|
|
|
updatedAt: updatedAt ?? this.updatedAt);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator ==(other) {
|
|
|
|
return other is _Author &&
|
|
|
|
other.id == id &&
|
|
|
|
other.name == name &&
|
|
|
|
other.age == age &&
|
|
|
|
const ListEquality<_Book>(const DefaultEquality<_Book>())
|
|
|
|
.equals(other.books, books) &&
|
|
|
|
other.newestBook == newestBook &&
|
|
|
|
other.secret == secret &&
|
|
|
|
other.obscured == obscured &&
|
|
|
|
other.createdAt == createdAt &&
|
|
|
|
other.updatedAt == updatedAt;
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
int get hashCode {
|
|
|
|
return hashObjects([
|
|
|
|
id,
|
|
|
|
name,
|
|
|
|
age,
|
|
|
|
books,
|
|
|
|
newestBook,
|
|
|
|
secret,
|
|
|
|
obscured,
|
|
|
|
createdAt,
|
|
|
|
updatedAt
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2019-04-08 15:00:04 +00:00
|
|
|
@override
|
|
|
|
String toString() {
|
|
|
|
return "Author(id=$id, name=$name, age=$age, books=$books, newestBook=$newestBook, secret=$secret, obscured=$obscured, createdAt=$createdAt, updatedAt=$updatedAt)";
|
|
|
|
}
|
|
|
|
|
2019-04-08 04:41:58 +00:00
|
|
|
Map<String, dynamic> toJson() {
|
|
|
|
return AuthorSerializer.toMap(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@generatedSerializable
|
|
|
|
class Library extends _Library {
|
|
|
|
Library(
|
|
|
|
{this.id, Map<String, _Book> collection, this.createdAt, this.updatedAt})
|
|
|
|
: this.collection = new Map.unmodifiable(collection ?? {});
|
|
|
|
|
|
|
|
@override
|
|
|
|
final String id;
|
|
|
|
|
|
|
|
@override
|
|
|
|
final Map<String, _Book> collection;
|
|
|
|
|
|
|
|
@override
|
|
|
|
final DateTime createdAt;
|
|
|
|
|
|
|
|
@override
|
|
|
|
final DateTime updatedAt;
|
|
|
|
|
|
|
|
Library copyWith(
|
|
|
|
{String id,
|
|
|
|
Map<String, _Book> collection,
|
|
|
|
DateTime createdAt,
|
|
|
|
DateTime updatedAt}) {
|
|
|
|
return new Library(
|
|
|
|
id: id ?? this.id,
|
|
|
|
collection: collection ?? this.collection,
|
|
|
|
createdAt: createdAt ?? this.createdAt,
|
|
|
|
updatedAt: updatedAt ?? this.updatedAt);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator ==(other) {
|
|
|
|
return other is _Library &&
|
|
|
|
other.id == id &&
|
|
|
|
const MapEquality<String, _Book>(
|
|
|
|
keys: const DefaultEquality<String>(),
|
|
|
|
values: const DefaultEquality<_Book>())
|
|
|
|
.equals(other.collection, collection) &&
|
|
|
|
other.createdAt == createdAt &&
|
|
|
|
other.updatedAt == updatedAt;
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
int get hashCode {
|
|
|
|
return hashObjects([id, collection, createdAt, updatedAt]);
|
|
|
|
}
|
|
|
|
|
2019-04-08 15:00:04 +00:00
|
|
|
@override
|
|
|
|
String toString() {
|
|
|
|
return "Library(id=$id, collection=$collection, createdAt=$createdAt, updatedAt=$updatedAt)";
|
|
|
|
}
|
|
|
|
|
2019-04-08 04:41:58 +00:00
|
|
|
Map<String, dynamic> toJson() {
|
|
|
|
return LibrarySerializer.toMap(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@generatedSerializable
|
|
|
|
class Bookmark extends _Bookmark {
|
|
|
|
Bookmark(_Book book,
|
|
|
|
{this.id,
|
|
|
|
List<int> history,
|
|
|
|
@required this.page,
|
|
|
|
this.comment,
|
|
|
|
this.createdAt,
|
|
|
|
this.updatedAt})
|
|
|
|
: this.history = new List.unmodifiable(history ?? []),
|
|
|
|
super(book);
|
|
|
|
|
|
|
|
@override
|
|
|
|
final String id;
|
|
|
|
|
|
|
|
@override
|
|
|
|
final List<int> history;
|
|
|
|
|
|
|
|
@override
|
|
|
|
final int page;
|
|
|
|
|
|
|
|
@override
|
|
|
|
final String comment;
|
|
|
|
|
|
|
|
@override
|
|
|
|
final DateTime createdAt;
|
|
|
|
|
|
|
|
@override
|
|
|
|
final DateTime updatedAt;
|
|
|
|
|
|
|
|
Bookmark copyWith(_Book book,
|
|
|
|
{String id,
|
|
|
|
List<int> history,
|
|
|
|
int page,
|
|
|
|
String comment,
|
|
|
|
DateTime createdAt,
|
|
|
|
DateTime updatedAt}) {
|
|
|
|
return new Bookmark(book,
|
|
|
|
id: id ?? this.id,
|
|
|
|
history: history ?? this.history,
|
|
|
|
page: page ?? this.page,
|
|
|
|
comment: comment ?? this.comment,
|
|
|
|
createdAt: createdAt ?? this.createdAt,
|
|
|
|
updatedAt: updatedAt ?? this.updatedAt);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator ==(other) {
|
|
|
|
return other is _Bookmark &&
|
|
|
|
other.id == id &&
|
|
|
|
const ListEquality<int>(const DefaultEquality<int>())
|
|
|
|
.equals(other.history, history) &&
|
|
|
|
other.page == page &&
|
|
|
|
other.comment == comment &&
|
|
|
|
other.createdAt == createdAt &&
|
|
|
|
other.updatedAt == updatedAt;
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
int get hashCode {
|
|
|
|
return hashObjects([id, history, page, comment, createdAt, updatedAt]);
|
|
|
|
}
|
|
|
|
|
2019-04-08 15:00:04 +00:00
|
|
|
@override
|
|
|
|
String toString() {
|
|
|
|
return "Bookmark(id=$id, history=$history, page=$page, comment=$comment, createdAt=$createdAt, updatedAt=$updatedAt)";
|
|
|
|
}
|
|
|
|
|
2019-04-08 04:41:58 +00:00
|
|
|
Map<String, dynamic> toJson() {
|
|
|
|
return BookmarkSerializer.toMap(this);
|
|
|
|
}
|
|
|
|
}
|
2019-04-04 21:40:36 +00:00
|
|
|
|
2019-04-08 04:41:58 +00:00
|
|
|
// **************************************************************************
|
|
|
|
// SerializerGenerator
|
|
|
|
// **************************************************************************
|
|
|
|
|
2019-04-08 15:00:04 +00:00
|
|
|
const BookSerializer bookSerializer = const BookSerializer();
|
|
|
|
|
|
|
|
class BookEncoder extends Converter<Book, Map> {
|
|
|
|
const BookEncoder();
|
|
|
|
|
|
|
|
@override
|
|
|
|
Map convert(Book model) => BookSerializer.toMap(model);
|
|
|
|
}
|
|
|
|
|
|
|
|
class BookDecoder extends Converter<Map, Book> {
|
|
|
|
const BookDecoder();
|
|
|
|
|
|
|
|
@override
|
|
|
|
Book convert(Map map) => BookSerializer.fromMap(map);
|
|
|
|
}
|
|
|
|
|
|
|
|
class BookSerializer extends Codec<Book, Map> {
|
|
|
|
const BookSerializer();
|
|
|
|
|
|
|
|
@override
|
|
|
|
get encoder => const BookEncoder();
|
|
|
|
@override
|
|
|
|
get decoder => const BookDecoder();
|
2019-04-08 04:41:58 +00:00
|
|
|
static Book fromMap(Map map) {
|
2018-12-08 20:53:49 +00:00
|
|
|
return new Book(
|
|
|
|
id: map['id'] as String,
|
|
|
|
author: map['author'] as String,
|
|
|
|
title: map['title'] as String,
|
|
|
|
description: map['description'] as String,
|
|
|
|
pageCount: map['page_count'] as int,
|
|
|
|
notModels: map['not_models'] is Iterable
|
|
|
|
? (map['not_models'] as Iterable).cast<double>().toList()
|
|
|
|
: null,
|
|
|
|
camelCaseString: map['camelCase'] as String,
|
|
|
|
createdAt: map['created_at'] != null
|
|
|
|
? (map['created_at'] is DateTime
|
|
|
|
? (map['created_at'] as DateTime)
|
|
|
|
: DateTime.parse(map['created_at'].toString()))
|
|
|
|
: null,
|
|
|
|
updatedAt: map['updated_at'] != null
|
|
|
|
? (map['updated_at'] is DateTime
|
|
|
|
? (map['updated_at'] as DateTime)
|
|
|
|
: DateTime.parse(map['updated_at'].toString()))
|
|
|
|
: null);
|
|
|
|
}
|
|
|
|
|
2018-12-08 22:31:12 +00:00
|
|
|
static Map<String, dynamic> toMap(_Book model) {
|
2018-12-08 20:53:49 +00:00
|
|
|
if (model == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
'id': model.id,
|
|
|
|
'author': model.author,
|
|
|
|
'title': model.title,
|
|
|
|
'description': model.description,
|
|
|
|
'page_count': model.pageCount,
|
|
|
|
'not_models': model.notModels,
|
|
|
|
'camelCase': model.camelCaseString,
|
|
|
|
'created_at': model.createdAt?.toIso8601String(),
|
|
|
|
'updated_at': model.updatedAt?.toIso8601String()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
abstract class BookFields {
|
2019-04-04 21:40:36 +00:00
|
|
|
static const List<String> allFields = <String>[
|
2018-12-08 20:53:49 +00:00
|
|
|
id,
|
|
|
|
author,
|
|
|
|
title,
|
|
|
|
description,
|
|
|
|
pageCount,
|
|
|
|
notModels,
|
|
|
|
camelCaseString,
|
|
|
|
createdAt,
|
|
|
|
updatedAt
|
|
|
|
];
|
|
|
|
|
|
|
|
static const String id = 'id';
|
|
|
|
|
|
|
|
static const String author = 'author';
|
|
|
|
|
|
|
|
static const String title = 'title';
|
|
|
|
|
|
|
|
static const String description = 'description';
|
|
|
|
|
|
|
|
static const String pageCount = 'page_count';
|
|
|
|
|
|
|
|
static const String notModels = 'not_models';
|
|
|
|
|
|
|
|
static const String camelCaseString = 'camelCase';
|
|
|
|
|
|
|
|
static const String createdAt = 'created_at';
|
|
|
|
|
|
|
|
static const String updatedAt = 'updated_at';
|
|
|
|
}
|
2019-04-08 04:41:58 +00:00
|
|
|
|
2019-04-08 15:00:04 +00:00
|
|
|
const AuthorSerializer authorSerializer = const AuthorSerializer();
|
|
|
|
|
|
|
|
class AuthorEncoder extends Converter<Author, Map> {
|
|
|
|
const AuthorEncoder();
|
|
|
|
|
|
|
|
@override
|
|
|
|
Map convert(Author model) => AuthorSerializer.toMap(model);
|
|
|
|
}
|
|
|
|
|
|
|
|
class AuthorDecoder extends Converter<Map, Author> {
|
|
|
|
const AuthorDecoder();
|
|
|
|
|
|
|
|
@override
|
|
|
|
Author convert(Map map) => AuthorSerializer.fromMap(map);
|
|
|
|
}
|
|
|
|
|
|
|
|
class AuthorSerializer extends Codec<Author, Map> {
|
|
|
|
const AuthorSerializer();
|
|
|
|
|
|
|
|
@override
|
|
|
|
get encoder => const AuthorEncoder();
|
|
|
|
@override
|
|
|
|
get decoder => const AuthorDecoder();
|
2019-04-08 04:41:58 +00:00
|
|
|
static Author fromMap(Map map) {
|
|
|
|
if (map['name'] == null) {
|
|
|
|
throw new FormatException("Missing required field 'name' on Author.");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (map['age'] == null) {
|
|
|
|
throw new FormatException("Custom message for missing `age`");
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Author(
|
|
|
|
id: map['id'] as String,
|
|
|
|
name: map['name'] as String,
|
|
|
|
age: map['age'] as int,
|
|
|
|
books: map['books'] is Iterable
|
|
|
|
? new List.unmodifiable(
|
|
|
|
((map['books'] as Iterable).where((x) => x is Map))
|
|
|
|
.cast<Map>()
|
|
|
|
.map(BookSerializer.fromMap))
|
|
|
|
: null,
|
|
|
|
newestBook: map['newest_book'] != null
|
|
|
|
? BookSerializer.fromMap(map['newest_book'] as Map)
|
|
|
|
: null,
|
|
|
|
obscured: map['obscured'] as String,
|
|
|
|
createdAt: map['created_at'] != null
|
|
|
|
? (map['created_at'] is DateTime
|
|
|
|
? (map['created_at'] as DateTime)
|
|
|
|
: DateTime.parse(map['created_at'].toString()))
|
|
|
|
: null,
|
|
|
|
updatedAt: map['updated_at'] != null
|
|
|
|
? (map['updated_at'] is DateTime
|
|
|
|
? (map['updated_at'] as DateTime)
|
|
|
|
: DateTime.parse(map['updated_at'].toString()))
|
|
|
|
: null);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Map<String, dynamic> toMap(_Author model) {
|
|
|
|
if (model == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
if (model.name == null) {
|
|
|
|
throw new FormatException("Missing required field 'name' on Author.");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (model.age == null) {
|
|
|
|
throw new FormatException("Custom message for missing `age`");
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
'id': model.id,
|
|
|
|
'name': model.name,
|
|
|
|
'age': model.age,
|
|
|
|
'books': model.books?.map((m) => BookSerializer.toMap(m))?.toList(),
|
|
|
|
'newest_book': BookSerializer.toMap(model.newestBook),
|
|
|
|
'created_at': model.createdAt?.toIso8601String(),
|
|
|
|
'updated_at': model.updatedAt?.toIso8601String()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
abstract class AuthorFields {
|
|
|
|
static const List<String> allFields = <String>[
|
|
|
|
id,
|
|
|
|
name,
|
|
|
|
age,
|
|
|
|
books,
|
|
|
|
newestBook,
|
|
|
|
secret,
|
|
|
|
obscured,
|
|
|
|
createdAt,
|
|
|
|
updatedAt
|
|
|
|
];
|
|
|
|
|
|
|
|
static const String id = 'id';
|
|
|
|
|
|
|
|
static const String name = 'name';
|
|
|
|
|
|
|
|
static const String age = 'age';
|
|
|
|
|
|
|
|
static const String books = 'books';
|
|
|
|
|
|
|
|
static const String newestBook = 'newest_book';
|
|
|
|
|
|
|
|
static const String secret = 'secret';
|
|
|
|
|
|
|
|
static const String obscured = 'obscured';
|
|
|
|
|
|
|
|
static const String createdAt = 'created_at';
|
|
|
|
|
|
|
|
static const String updatedAt = 'updated_at';
|
|
|
|
}
|
|
|
|
|
2019-04-08 15:00:04 +00:00
|
|
|
const LibrarySerializer librarySerializer = const LibrarySerializer();
|
|
|
|
|
|
|
|
class LibraryEncoder extends Converter<Library, Map> {
|
|
|
|
const LibraryEncoder();
|
|
|
|
|
|
|
|
@override
|
|
|
|
Map convert(Library model) => LibrarySerializer.toMap(model);
|
|
|
|
}
|
|
|
|
|
|
|
|
class LibraryDecoder extends Converter<Map, Library> {
|
|
|
|
const LibraryDecoder();
|
|
|
|
|
|
|
|
@override
|
|
|
|
Library convert(Map map) => LibrarySerializer.fromMap(map);
|
|
|
|
}
|
|
|
|
|
|
|
|
class LibrarySerializer extends Codec<Library, Map> {
|
|
|
|
const LibrarySerializer();
|
|
|
|
|
|
|
|
@override
|
|
|
|
get encoder => const LibraryEncoder();
|
|
|
|
@override
|
|
|
|
get decoder => const LibraryDecoder();
|
2019-04-08 04:41:58 +00:00
|
|
|
static Library fromMap(Map map) {
|
|
|
|
return new Library(
|
|
|
|
id: map['id'] as String,
|
|
|
|
collection: map['collection'] is Map
|
|
|
|
? new Map.unmodifiable(
|
|
|
|
(map['collection'] as Map).keys.fold({}, (out, key) {
|
|
|
|
return out
|
|
|
|
..[key] = BookSerializer.fromMap(
|
|
|
|
((map['collection'] as Map)[key]) as Map);
|
|
|
|
}))
|
|
|
|
: null,
|
|
|
|
createdAt: map['created_at'] != null
|
|
|
|
? (map['created_at'] is DateTime
|
|
|
|
? (map['created_at'] as DateTime)
|
|
|
|
: DateTime.parse(map['created_at'].toString()))
|
|
|
|
: null,
|
|
|
|
updatedAt: map['updated_at'] != null
|
|
|
|
? (map['updated_at'] is DateTime
|
|
|
|
? (map['updated_at'] as DateTime)
|
|
|
|
: DateTime.parse(map['updated_at'].toString()))
|
|
|
|
: null);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Map<String, dynamic> toMap(_Library model) {
|
|
|
|
if (model == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
'id': model.id,
|
|
|
|
'collection': model.collection.keys?.fold({}, (map, key) {
|
|
|
|
return map..[key] = BookSerializer.toMap(model.collection[key]);
|
|
|
|
}),
|
|
|
|
'created_at': model.createdAt?.toIso8601String(),
|
|
|
|
'updated_at': model.updatedAt?.toIso8601String()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
abstract class LibraryFields {
|
|
|
|
static const List<String> allFields = <String>[
|
|
|
|
id,
|
|
|
|
collection,
|
|
|
|
createdAt,
|
|
|
|
updatedAt
|
|
|
|
];
|
|
|
|
|
|
|
|
static const String id = 'id';
|
|
|
|
|
|
|
|
static const String collection = 'collection';
|
|
|
|
|
|
|
|
static const String createdAt = 'created_at';
|
|
|
|
|
|
|
|
static const String updatedAt = 'updated_at';
|
|
|
|
}
|
|
|
|
|
|
|
|
abstract class BookmarkSerializer {
|
|
|
|
static Bookmark fromMap(Map map, _Book book) {
|
|
|
|
if (map['page'] == null) {
|
|
|
|
throw new FormatException("Missing required field 'page' on Bookmark.");
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Bookmark(book,
|
|
|
|
id: map['id'] as String,
|
|
|
|
history: map['history'] is Iterable
|
|
|
|
? (map['history'] as Iterable).cast<int>().toList()
|
|
|
|
: null,
|
|
|
|
page: map['page'] as int,
|
|
|
|
comment: map['comment'] as String,
|
|
|
|
createdAt: map['created_at'] != null
|
|
|
|
? (map['created_at'] is DateTime
|
|
|
|
? (map['created_at'] as DateTime)
|
|
|
|
: DateTime.parse(map['created_at'].toString()))
|
|
|
|
: null,
|
|
|
|
updatedAt: map['updated_at'] != null
|
|
|
|
? (map['updated_at'] is DateTime
|
|
|
|
? (map['updated_at'] as DateTime)
|
|
|
|
: DateTime.parse(map['updated_at'].toString()))
|
|
|
|
: null);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Map<String, dynamic> toMap(_Bookmark model) {
|
|
|
|
if (model == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
if (model.page == null) {
|
|
|
|
throw new FormatException("Missing required field 'page' on Bookmark.");
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
'id': model.id,
|
|
|
|
'history': model.history,
|
|
|
|
'page': model.page,
|
|
|
|
'comment': model.comment,
|
|
|
|
'created_at': model.createdAt?.toIso8601String(),
|
|
|
|
'updated_at': model.updatedAt?.toIso8601String()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
abstract class BookmarkFields {
|
|
|
|
static const List<String> allFields = <String>[
|
|
|
|
id,
|
|
|
|
history,
|
|
|
|
page,
|
|
|
|
comment,
|
|
|
|
createdAt,
|
|
|
|
updatedAt
|
|
|
|
];
|
|
|
|
|
|
|
|
static const String id = 'id';
|
|
|
|
|
|
|
|
static const String history = 'history';
|
|
|
|
|
|
|
|
static const String page = 'page';
|
|
|
|
|
|
|
|
static const String comment = 'comment';
|
|
|
|
|
|
|
|
static const String createdAt = 'created_at';
|
|
|
|
|
|
|
|
static const String updatedAt = 'updated_at';
|
|
|
|
}
|