platform/packages/serialize/serialize_generator/test/models/book.g.dart

735 lines
18 KiB
Dart
Raw Normal View History

2017-06-17 01:26:19 +00:00
// GENERATED CODE - DO NOT MODIFY BY HAND
2023-05-26 23:59:53 +00:00
part of 'book.dart';
2017-06-17 01:26:19 +00:00
// **************************************************************************
2018-06-29 04:11:57 +00:00
// JsonModelGenerator
2017-06-17 01:26:19 +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 {
2023-04-21 06:25:54 +00:00
Book({
this.id,
this.createdAt,
this.updatedAt,
this.author,
this.title,
this.description,
this.pageCount,
List<double>? notModels = const [],
this.camelCaseString,
}) : notModels = List.unmodifiable(notModels ?? []);
2018-02-27 19:57:05 +00:00
2019-07-04 18:30:45 +00:00
/// A unique identifier corresponding to this item.
2018-02-28 00:36:53 +00:00
@override
2021-05-02 06:02:08 +00:00
String? id;
2017-06-17 01:26:19 +00:00
2019-07-04 18:30:45 +00:00
/// The time at which this item was created.
@override
2021-05-02 06:02:08 +00:00
DateTime? createdAt;
2019-07-04 18:30:45 +00:00
/// The last time at which this item was updated.
@override
2021-05-02 06:02:08 +00:00
DateTime? updatedAt;
2019-07-04 18:30:45 +00:00
2018-02-28 00:36:53 +00:00
@override
2021-05-02 06:02:08 +00:00
String? author;
2017-06-17 01:26:19 +00:00
2018-02-28 00:36:53 +00:00
@override
2021-05-02 06:02:08 +00:00
String? title;
2017-06-17 01:26:19 +00:00
2018-02-28 00:36:53 +00:00
@override
2021-05-02 06:02:08 +00:00
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
2021-05-02 06:02:08 +00:00
int? pageCount;
2017-06-17 01:26:19 +00:00
2018-03-05 06:18:46 +00:00
@override
2021-05-02 06:02:08 +00:00
List<double>? notModels;
2018-03-05 06:18:46 +00:00
2018-03-09 12:43:17 +00:00
@override
2021-05-02 06:02:08 +00:00
String? camelCaseString;
2018-03-09 12:43:17 +00:00
2023-04-21 06:25:54 +00:00
Book copyWith({
String? id,
DateTime? createdAt,
DateTime? updatedAt,
String? author,
String? title,
String? description,
int? pageCount,
List<double>? notModels,
String? camelCaseString,
}) {
2019-04-30 15:44:01 +00:00
return Book(
2018-02-28 00:36:53 +00:00
id: id ?? this.id,
2019-07-04 18:30:45 +00:00
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt,
2018-02-28 00:36:53 +00:00
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,
2019-07-04 18:30:45 +00:00
camelCaseString: camelCaseString ?? this.camelCaseString);
2018-02-28 00:36:53 +00:00
}
2018-02-28 01:49:14 +00:00
2021-06-26 13:13:43 +00:00
@override
2018-05-13 18:02:47 +00:00
bool operator ==(other) {
return other is _Book &&
other.id == id &&
2019-07-04 18:30:45 +00:00
other.createdAt == createdAt &&
other.updatedAt == updatedAt &&
2018-05-13 18:02:47 +00:00
other.author == author &&
other.title == title &&
other.description == description &&
other.pageCount == pageCount &&
2019-04-30 15:44:01 +00:00
ListEquality<double>(DefaultEquality<double>())
2018-05-13 18:02:47 +00:00
.equals(other.notModels, notModels) &&
2019-07-04 18:30:45 +00:00
other.camelCaseString == camelCaseString;
2018-05-13 18:02:47 +00:00
}
2018-11-03 07:36:59 +00:00
@override
int get hashCode {
return hashObjects([
id,
2019-07-04 18:30:45 +00:00
createdAt,
updatedAt,
2018-11-03 07:36:59 +00:00
author,
title,
description,
pageCount,
notModels,
2023-04-21 06:25:54 +00:00
camelCaseString,
2018-11-03 07:36:59 +00:00
]);
}
2019-04-08 15:00:04 +00:00
@override
String toString() {
2021-05-02 06:02:08 +00:00
return 'Book(id=$id, createdAt=$createdAt, updatedAt=$updatedAt, author=$author, title=$title, description=$description, pageCount=$pageCount, notModels=$notModels, camelCaseString=$camelCaseString)';
2019-04-08 15:00:04 +00:00
}
2022-02-27 04:16:31 +00:00
Map<String, dynamic> toJson() {
2018-02-28 01:49:14 +00:00
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 {
2023-04-21 06:25:54 +00:00
Author({
this.id,
this.createdAt,
this.updatedAt,
required this.name,
required this.age,
List<_Book> books = const [],
this.newestBook,
this.secret,
this.obscured,
}) : books = List.unmodifiable(books);
2018-12-08 20:53:49 +00:00
2019-07-04 18:30:45 +00:00
/// A unique identifier corresponding to this item.
2019-04-08 04:41:58 +00:00
@override
2021-05-02 06:02:08 +00:00
String? id;
2019-04-04 21:40:36 +00:00
2019-07-04 18:30:45 +00:00
/// The time at which this item was created.
@override
2021-05-02 06:02:08 +00:00
DateTime? createdAt;
2019-07-04 18:30:45 +00:00
/// The last time at which this item was updated.
@override
2021-05-02 06:02:08 +00:00
DateTime? updatedAt;
2019-07-04 18:30:45 +00:00
2019-04-08 04:41:58 +00:00
@override
2022-02-27 04:16:31 +00:00
String? name;
2019-04-04 21:40:36 +00:00
2019-04-08 04:41:58 +00:00
@override
2022-02-27 04:16:31 +00:00
int? age;
2019-04-04 21:40:36 +00:00
2019-04-08 04:41:58 +00:00
@override
2022-02-27 04:16:31 +00:00
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
2022-02-27 04:16:31 +00:00
_Book? newestBook;
2019-04-08 04:41:58 +00:00
@override
2022-02-27 04:16:31 +00:00
String? secret;
2019-04-08 04:41:58 +00:00
@override
2022-02-27 04:16:31 +00:00
String? obscured;
2019-04-08 04:41:58 +00:00
2023-04-21 06:25:54 +00:00
Author copyWith({
String? id,
DateTime? createdAt,
DateTime? updatedAt,
String? name,
int? age,
List<_Book>? books,
_Book? newestBook,
String? secret,
String? obscured,
}) {
2019-04-30 15:44:01 +00:00
return Author(
2019-04-08 04:41:58 +00:00
id: id ?? this.id,
2019-07-04 18:30:45 +00:00
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt,
2019-04-08 04:41:58 +00:00
name: name ?? this.name,
age: age ?? this.age,
books: books ?? this.books,
newestBook: newestBook ?? this.newestBook,
secret: secret ?? this.secret,
2019-07-04 18:30:45 +00:00
obscured: obscured ?? this.obscured);
2019-04-08 04:41:58 +00:00
}
2021-06-26 13:13:43 +00:00
@override
2019-04-08 04:41:58 +00:00
bool operator ==(other) {
return other is _Author &&
other.id == id &&
2019-07-04 18:30:45 +00:00
other.createdAt == createdAt &&
other.updatedAt == updatedAt &&
2019-04-08 04:41:58 +00:00
other.name == name &&
other.age == age &&
2019-04-30 15:44:01 +00:00
ListEquality<_Book>(DefaultEquality<_Book>())
2019-04-08 04:41:58 +00:00
.equals(other.books, books) &&
other.newestBook == newestBook &&
other.secret == secret &&
2019-07-04 18:30:45 +00:00
other.obscured == obscured;
2019-04-08 04:41:58 +00:00
}
@override
int get hashCode {
return hashObjects([
id,
2019-07-04 18:30:45 +00:00
createdAt,
updatedAt,
2019-04-08 04:41:58 +00:00
name,
age,
books,
newestBook,
secret,
2023-04-21 06:25:54 +00:00
obscured,
2019-04-08 04:41:58 +00:00
]);
}
2019-04-08 15:00:04 +00:00
@override
String toString() {
2021-05-02 06:02:08 +00:00
return 'Author(id=$id, createdAt=$createdAt, updatedAt=$updatedAt, name=$name, age=$age, books=$books, newestBook=$newestBook, secret=$secret, obscured=$obscured)';
2019-04-08 15:00:04 +00:00
}
2019-04-08 04:41:58 +00:00
Map<String, dynamic> toJson() {
return AuthorSerializer.toMap(this);
}
}
@generatedSerializable
class Library extends _Library {
2023-04-21 06:25:54 +00:00
Library({
this.id,
this.createdAt,
this.updatedAt,
required Map<String, _Book> collection,
}) : collection = Map.unmodifiable(collection);
2019-04-08 04:41:58 +00:00
2019-07-04 18:30:45 +00:00
/// A unique identifier corresponding to this item.
2019-04-08 04:41:58 +00:00
@override
2021-05-02 06:02:08 +00:00
String? id;
2019-04-08 04:41:58 +00:00
2019-07-04 18:30:45 +00:00
/// The time at which this item was created.
2019-04-08 04:41:58 +00:00
@override
2021-05-02 06:02:08 +00:00
DateTime? createdAt;
2019-04-08 04:41:58 +00:00
2019-07-04 18:30:45 +00:00
/// The last time at which this item was updated.
2019-04-08 04:41:58 +00:00
@override
2021-05-02 06:02:08 +00:00
DateTime? updatedAt;
2019-04-08 04:41:58 +00:00
2019-07-04 18:30:45 +00:00
@override
2022-02-27 04:16:31 +00:00
Map<String, _Book> collection;
2019-07-04 18:30:45 +00:00
2023-04-21 06:25:54 +00:00
Library copyWith({
String? id,
DateTime? createdAt,
DateTime? updatedAt,
Map<String, _Book>? collection,
}) {
2019-04-30 15:44:01 +00:00
return Library(
2019-04-08 04:41:58 +00:00
id: id ?? this.id,
createdAt: createdAt ?? this.createdAt,
2019-07-04 18:30:45 +00:00
updatedAt: updatedAt ?? this.updatedAt,
collection: collection ?? this.collection);
2019-04-08 04:41:58 +00:00
}
2021-06-26 13:13:43 +00:00
@override
2019-04-08 04:41:58 +00:00
bool operator ==(other) {
return other is _Library &&
other.id == id &&
2019-07-04 18:30:45 +00:00
other.createdAt == createdAt &&
other.updatedAt == updatedAt &&
2019-04-30 15:44:01 +00:00
MapEquality<String, _Book>(
keys: DefaultEquality<String>(),
values: DefaultEquality<_Book>())
2019-07-04 18:30:45 +00:00
.equals(other.collection, collection);
2019-04-08 04:41:58 +00:00
}
@override
int get hashCode {
2023-04-21 06:25:54 +00:00
return hashObjects([
id,
createdAt,
updatedAt,
collection,
]);
2019-04-08 04:41:58 +00:00
}
2019-04-08 15:00:04 +00:00
@override
String toString() {
2021-05-02 06:02:08 +00:00
return 'Library(id=$id, createdAt=$createdAt, updatedAt=$updatedAt, collection=$collection)';
2019-04-08 15:00:04 +00:00
}
2019-04-08 04:41:58 +00:00
Map<String, dynamic> toJson() {
return LibrarySerializer.toMap(this);
}
}
@generatedSerializable
class Bookmark extends _Bookmark {
2023-04-21 06:25:54 +00:00
Bookmark(
_Book book, {
this.id,
this.createdAt,
this.updatedAt,
List<int> history = const [],
required this.page,
this.comment,
}) : history = List.unmodifiable(history),
2019-04-08 04:41:58 +00:00
super(book);
2019-07-04 18:30:45 +00:00
/// A unique identifier corresponding to this item.
2019-04-08 04:41:58 +00:00
@override
2021-05-02 06:02:08 +00:00
String? id;
2019-04-08 04:41:58 +00:00
2019-07-04 18:30:45 +00:00
/// The time at which this item was created.
2019-04-08 04:41:58 +00:00
@override
2021-05-02 06:02:08 +00:00
DateTime? createdAt;
2019-04-08 04:41:58 +00:00
2019-07-04 18:30:45 +00:00
/// The last time at which this item was updated.
2019-04-08 04:41:58 +00:00
@override
2021-05-02 06:02:08 +00:00
DateTime? updatedAt;
2019-04-08 04:41:58 +00:00
@override
2022-02-27 04:16:31 +00:00
List<int> history;
2019-04-08 04:41:58 +00:00
@override
2022-02-27 04:16:31 +00:00
int? page;
2019-04-08 04:41:58 +00:00
@override
2022-02-27 04:16:31 +00:00
String? comment;
2019-04-08 04:41:58 +00:00
2023-04-21 06:25:54 +00:00
Bookmark copyWith(
_Book book, {
String? id,
DateTime? createdAt,
DateTime? updatedAt,
List<int>? history,
int? page,
String? comment,
}) {
2019-04-30 15:44:01 +00:00
return Bookmark(book,
2019-04-08 04:41:58 +00:00
id: id ?? this.id,
2019-07-04 18:30:45 +00:00
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt,
2019-04-08 04:41:58 +00:00
history: history ?? this.history,
page: page ?? this.page,
2019-07-04 18:30:45 +00:00
comment: comment ?? this.comment);
2019-04-08 04:41:58 +00:00
}
2021-06-26 13:13:43 +00:00
@override
2019-04-08 04:41:58 +00:00
bool operator ==(other) {
return other is _Bookmark &&
other.id == id &&
2019-07-04 18:30:45 +00:00
other.createdAt == createdAt &&
other.updatedAt == updatedAt &&
2019-04-30 15:44:01 +00:00
ListEquality<int>(DefaultEquality<int>())
2019-04-08 04:41:58 +00:00
.equals(other.history, history) &&
other.page == page &&
2019-07-04 18:30:45 +00:00
other.comment == comment;
2019-04-08 04:41:58 +00:00
}
@override
int get hashCode {
2023-04-21 06:25:54 +00:00
return hashObjects([
id,
createdAt,
updatedAt,
history,
page,
comment,
]);
2019-04-08 04:41:58 +00:00
}
2019-04-08 15:00:04 +00:00
@override
String toString() {
2021-05-02 06:02:08 +00:00
return 'Bookmark(id=$id, createdAt=$createdAt, updatedAt=$updatedAt, history=$history, page=$page, comment=$comment)';
2019-04-08 15:00:04 +00:00
}
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-30 15:44:01 +00:00
const BookSerializer bookSerializer = BookSerializer();
2019-04-08 15:00:04 +00:00
2022-02-27 04:16:31 +00:00
class BookEncoder extends Converter<Book, Map> {
2019-04-08 15:00:04 +00:00
const BookEncoder();
@override
2022-02-27 04:16:31 +00:00
Map convert(Book model) => BookSerializer.toMap(model);
2019-04-08 15:00:04 +00:00
}
class BookDecoder extends Converter<Map, Book> {
const BookDecoder();
@override
Book convert(Map map) => BookSerializer.fromMap(map);
}
2022-02-27 04:16:31 +00:00
class BookSerializer extends Codec<Book, Map> {
2019-04-08 15:00:04 +00:00
const BookSerializer();
@override
2021-05-02 06:02:08 +00:00
BookEncoder get encoder => const BookEncoder();
2019-04-08 15:00:04 +00:00
@override
2021-05-02 06:02:08 +00:00
BookDecoder get decoder => const BookDecoder();
2019-04-08 04:41:58 +00:00
static Book fromMap(Map map) {
2019-04-30 15:44:01 +00:00
return Book(
2021-05-02 06:02:08 +00:00
id: map['id'] as String?,
2018-12-08 20:53:49 +00:00
createdAt: map['created_at'] != null
? (map['created_at'] is DateTime
2022-02-27 04:16:31 +00:00
? (map['created_at'] as DateTime)
2018-12-08 20:53:49 +00:00
: DateTime.parse(map['created_at'].toString()))
: null,
updatedAt: map['updated_at'] != null
? (map['updated_at'] is DateTime
2022-02-27 04:16:31 +00:00
? (map['updated_at'] as DateTime)
2018-12-08 20:53:49 +00:00
: DateTime.parse(map['updated_at'].toString()))
2019-07-04 18:30:45 +00:00
: null,
2021-05-02 06:02:08 +00:00
author: map['author'] as String?,
title: map['title'] as String?,
description: map['description'] as String?,
pageCount: map['page_count'] as int?,
2019-07-04 18:30:45 +00:00
notModels: map['not_models'] is Iterable
? (map['not_models'] as Iterable).cast<double>().toList()
2022-02-27 04:16:31 +00:00
: [],
2021-05-02 06:02:08 +00:00
camelCaseString: map['camelCase'] as String?);
2018-12-08 20:53:49 +00:00
}
2022-02-27 04:16:31 +00:00
static Map<String, dynamic> toMap(_Book? model) {
2018-12-08 20:53:49 +00:00
if (model == null) {
2022-02-27 04:16:31 +00:00
throw FormatException("Required field [model] cannot be null");
2018-12-08 20:53:49 +00:00
}
return {
'id': model.id,
2019-07-04 18:30:45 +00:00
'created_at': model.createdAt?.toIso8601String(),
'updated_at': model.updatedAt?.toIso8601String(),
2018-12-08 20:53:49 +00:00
'author': model.author,
'title': model.title,
'description': model.description,
'page_count': model.pageCount,
'not_models': model.notModels,
2019-07-04 18:30:45 +00:00
'camelCase': model.camelCaseString
2018-12-08 20:53:49 +00:00
};
}
}
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,
2019-07-04 18:30:45 +00:00
createdAt,
updatedAt,
2018-12-08 20:53:49 +00:00
author,
title,
description,
pageCount,
notModels,
2023-04-21 06:25:54 +00:00
camelCaseString,
2018-12-08 20:53:49 +00:00
];
static const String id = 'id';
2019-07-04 18:30:45 +00:00
static const String createdAt = 'created_at';
static const String updatedAt = 'updated_at';
2018-12-08 20:53:49 +00:00
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';
}
2019-04-08 04:41:58 +00:00
2019-04-30 15:44:01 +00:00
const AuthorSerializer authorSerializer = AuthorSerializer();
2019-04-08 15:00:04 +00:00
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
2021-05-02 06:02:08 +00:00
AuthorEncoder get encoder => const AuthorEncoder();
2019-04-08 15:00:04 +00:00
@override
2021-05-02 06:02:08 +00:00
AuthorDecoder get decoder => const AuthorDecoder();
2019-04-08 04:41:58 +00:00
static Author fromMap(Map map) {
if (map['name'] == null) {
2019-04-30 15:44:01 +00:00
throw FormatException("Missing required field 'name' on Author.");
2019-04-08 04:41:58 +00:00
}
if (map['age'] == null) {
2021-05-02 06:02:08 +00:00
throw FormatException('Custom message for missing `age`');
2019-04-08 04:41:58 +00:00
}
2019-04-30 15:44:01 +00:00
return Author(
2021-05-02 06:02:08 +00:00
id: map['id'] as String?,
2019-04-08 04:41:58 +00:00
createdAt: map['created_at'] != null
? (map['created_at'] is DateTime
2022-02-27 04:16:31 +00:00
? (map['created_at'] as DateTime)
2019-04-08 04:41:58 +00:00
: DateTime.parse(map['created_at'].toString()))
: null,
updatedAt: map['updated_at'] != null
? (map['updated_at'] is DateTime
2022-02-27 04:16:31 +00:00
? (map['updated_at'] as DateTime)
2019-04-08 04:41:58 +00:00
: DateTime.parse(map['updated_at'].toString()))
2019-07-04 18:30:45 +00:00
: null,
2021-05-02 06:02:08 +00:00
name: map['name'] as String?,
age: map['age'] as int?,
2019-07-04 18:30:45 +00:00
books: map['books'] is Iterable
? List.unmodifiable(((map['books'] as Iterable).whereType<Map>())
.map(BookSerializer.fromMap))
2022-02-27 04:16:31 +00:00
: [],
2019-07-04 18:30:45 +00:00
newestBook: map['newest_book'] != null
? BookSerializer.fromMap(map['newest_book'] as Map)
: null,
2021-05-02 06:02:08 +00:00
obscured: map['obscured'] as String?);
2019-04-08 04:41:58 +00:00
}
2022-02-27 04:16:31 +00:00
static Map<String, dynamic> toMap(_Author? model) {
if (model == null) {
throw FormatException("Required field [model] cannot be null");
2019-04-08 04:41:58 +00:00
}
return {
'id': model.id,
2019-07-04 18:30:45 +00:00
'created_at': model.createdAt?.toIso8601String(),
'updated_at': model.updatedAt?.toIso8601String(),
2019-04-08 04:41:58 +00:00
'name': model.name,
'age': model.age,
2021-05-02 06:02:08 +00:00
'books': model.books.map((m) => BookSerializer.toMap(m)).toList(),
2019-07-04 18:30:45 +00:00
'newest_book': BookSerializer.toMap(model.newestBook)
2019-04-08 04:41:58 +00:00
};
}
}
abstract class AuthorFields {
static const List<String> allFields = <String>[
id,
2019-07-04 18:30:45 +00:00
createdAt,
updatedAt,
2019-04-08 04:41:58 +00:00
name,
age,
books,
newestBook,
secret,
2023-04-21 06:25:54 +00:00
obscured,
2019-04-08 04:41:58 +00:00
];
static const String id = 'id';
2019-07-04 18:30:45 +00:00
static const String createdAt = 'created_at';
static const String updatedAt = 'updated_at';
2019-04-08 04:41:58 +00:00
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';
}
2019-04-30 15:44:01 +00:00
const LibrarySerializer librarySerializer = LibrarySerializer();
2019-04-08 15:00:04 +00:00
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
2021-05-02 06:02:08 +00:00
LibraryEncoder get encoder => const LibraryEncoder();
2019-04-08 15:00:04 +00:00
@override
2021-05-02 06:02:08 +00:00
LibraryDecoder get decoder => const LibraryDecoder();
2019-04-08 04:41:58 +00:00
static Library fromMap(Map map) {
2019-04-30 15:44:01 +00:00
return Library(
2021-05-02 06:02:08 +00:00
id: map['id'] as String?,
2019-04-08 04:41:58 +00:00
createdAt: map['created_at'] != null
? (map['created_at'] is DateTime
2022-02-27 04:16:31 +00:00
? (map['created_at'] as DateTime)
2019-04-08 04:41:58 +00:00
: DateTime.parse(map['created_at'].toString()))
: null,
updatedAt: map['updated_at'] != null
? (map['updated_at'] is DateTime
2022-02-27 04:16:31 +00:00
? (map['updated_at'] as DateTime)
2019-04-08 04:41:58 +00:00
: DateTime.parse(map['updated_at'].toString()))
2019-07-04 18:30:45 +00:00
: null,
collection: map['collection'] is Map
? Map.unmodifiable(
(map['collection'] as Map).keys.fold({}, (out, key) {
return out
..[key] = BookSerializer.fromMap(
((map['collection'] as Map)[key]) as Map);
}))
2022-02-27 04:16:31 +00:00
: {});
2019-04-08 04:41:58 +00:00
}
2022-02-27 04:16:31 +00:00
static Map<String, dynamic> toMap(_Library? model) {
if (model == null) {
throw FormatException("Required field [model] cannot be null");
}
2019-04-08 04:41:58 +00:00
return {
'id': model.id,
2019-07-04 18:30:45 +00:00
'created_at': model.createdAt?.toIso8601String(),
'updated_at': model.updatedAt?.toIso8601String(),
2022-02-27 04:16:31 +00:00
'collection': model.collection.keys.fold({}, (map, key) {
2023-04-21 06:25:54 +00:00
return map..[key] = BookSerializer.toMap(model.collection[key]);
2019-07-04 18:30:45 +00:00
})
2019-04-08 04:41:58 +00:00
};
}
}
abstract class LibraryFields {
static const List<String> allFields = <String>[
id,
createdAt,
2019-07-04 18:30:45 +00:00
updatedAt,
2023-04-21 06:25:54 +00:00
collection,
2019-04-08 04:41:58 +00:00
];
static const String id = 'id';
static const String createdAt = 'created_at';
static const String updatedAt = 'updated_at';
2019-07-04 18:30:45 +00:00
static const String collection = 'collection';
2019-04-08 04:41:58 +00:00
}
abstract class BookmarkSerializer {
2023-04-21 06:25:54 +00:00
static Bookmark fromMap(
Map map,
_Book book,
) {
2019-04-08 04:41:58 +00:00
if (map['page'] == null) {
2019-04-30 15:44:01 +00:00
throw FormatException("Missing required field 'page' on Bookmark.");
2019-04-08 04:41:58 +00:00
}
2019-04-30 15:44:01 +00:00
return Bookmark(book,
2021-05-02 06:02:08 +00:00
id: map['id'] as String?,
2019-04-08 04:41:58 +00:00
createdAt: map['created_at'] != null
? (map['created_at'] is DateTime
2022-02-27 04:16:31 +00:00
? (map['created_at'] as DateTime)
2019-04-08 04:41:58 +00:00
: DateTime.parse(map['created_at'].toString()))
: null,
updatedAt: map['updated_at'] != null
? (map['updated_at'] is DateTime
2022-02-27 04:16:31 +00:00
? (map['updated_at'] as DateTime)
2019-04-08 04:41:58 +00:00
: DateTime.parse(map['updated_at'].toString()))
2019-07-04 18:30:45 +00:00
: null,
history: map['history'] is Iterable
? (map['history'] as Iterable).cast<int>().toList()
2022-02-27 04:16:31 +00:00
: [],
2021-05-02 06:02:08 +00:00
page: map['page'] as int?,
comment: map['comment'] as String?);
2019-04-08 04:41:58 +00:00
}
2022-02-27 04:16:31 +00:00
static Map<String, dynamic> toMap(_Bookmark? model) {
if (model == null) {
throw FormatException("Required field [model] cannot be null");
2019-04-08 04:41:58 +00:00
}
return {
'id': model.id,
2019-07-04 18:30:45 +00:00
'created_at': model.createdAt?.toIso8601String(),
'updated_at': model.updatedAt?.toIso8601String(),
2019-04-08 04:41:58 +00:00
'history': model.history,
'page': model.page,
2019-07-04 18:30:45 +00:00
'comment': model.comment
2019-04-08 04:41:58 +00:00
};
}
}
abstract class BookmarkFields {
static const List<String> allFields = <String>[
id,
2019-07-04 18:30:45 +00:00
createdAt,
updatedAt,
2019-04-08 04:41:58 +00:00
history,
page,
2023-04-21 06:25:54 +00:00
comment,
2019-04-08 04:41:58 +00:00
];
static const String id = 'id';
2019-07-04 18:30:45 +00:00
static const String createdAt = 'created_at';
static const String updatedAt = 'updated_at';
2019-04-08 04:41:58 +00:00
static const String history = 'history';
static const String page = 'page';
static const String comment = 'comment';
}