2022-07-15 14:25:16 +00:00
|
|
|
import 'package:meta/meta.dart';
|
|
|
|
import 'package:json_annotation/json_annotation.dart';
|
|
|
|
|
|
|
|
import 'package:vikunja_app/models/task.dart';
|
|
|
|
import 'package:vikunja_app/models/user.dart';
|
|
|
|
|
|
|
|
@JsonSerializable()
|
|
|
|
class Bucket {
|
|
|
|
int id, listId, limit;
|
2022-08-27 21:04:43 +00:00
|
|
|
String? title;
|
2022-07-15 14:25:16 +00:00
|
|
|
double position;
|
2022-08-27 21:04:43 +00:00
|
|
|
DateTime? created, updated;
|
|
|
|
User? createdBy;
|
2022-07-15 14:25:16 +00:00
|
|
|
bool isDoneBucket;
|
|
|
|
Bucket({
|
2022-08-27 21:04:43 +00:00
|
|
|
required this.id,
|
|
|
|
required this.listId,
|
2022-07-15 14:25:16 +00:00
|
|
|
this.title,
|
2022-08-27 21:04:43 +00:00
|
|
|
this.position = 0,
|
|
|
|
required this.limit,
|
|
|
|
this.isDoneBucket = false,
|
2022-07-15 14:25:16 +00:00
|
|
|
this.created,
|
|
|
|
this.updated,
|
|
|
|
this.createdBy,
|
2022-08-27 21:04:43 +00:00
|
|
|
this.tasks = const <Task>[],
|
2022-07-15 14:25:16 +00:00
|
|
|
});
|
|
|
|
|
2022-08-27 21:04:43 +00:00
|
|
|
List<Task> tasks = [];
|
|
|
|
|
2022-07-15 14:25:16 +00:00
|
|
|
Bucket.fromJSON(Map<String, dynamic> json)
|
|
|
|
: id = json['id'],
|
|
|
|
listId = json['list_id'],
|
|
|
|
title = json['title'],
|
|
|
|
position = json['position'] is int
|
|
|
|
? json['position'].toDouble()
|
|
|
|
: json['position'],
|
|
|
|
limit = json['limit'],
|
|
|
|
isDoneBucket = json['is_done_bucket'],
|
|
|
|
created = DateTime.parse(json['created']),
|
|
|
|
updated = DateTime.parse(json['updated']),
|
|
|
|
createdBy = json['created_by'] == null
|
|
|
|
? null
|
|
|
|
: User.fromJson(json['created_by']),
|
|
|
|
tasks = (json['tasks'] as List<dynamic>)
|
2022-08-27 21:04:43 +00:00
|
|
|
.map((task) => Task.fromJson(task))
|
|
|
|
.cast<Task>()
|
|
|
|
.toList() ?? <Task>[];
|
2022-07-15 14:25:16 +00:00
|
|
|
|
|
|
|
toJSON() => {
|
|
|
|
'id': id,
|
|
|
|
'list_id': listId,
|
|
|
|
'title': title,
|
|
|
|
'position': position,
|
|
|
|
'limit': limit,
|
|
|
|
'is_done_bucket': isDoneBucket ?? false,
|
2022-08-27 21:04:43 +00:00
|
|
|
'created': created?.toUtc().toIso8601String(),
|
|
|
|
'updated': updated?.toUtc().toIso8601String(),
|
2022-07-15 14:25:16 +00:00
|
|
|
'createdBy': createdBy?.toJSON(),
|
2022-08-27 21:04:43 +00:00
|
|
|
'tasks': tasks?.map((task) => task.toJSON()).toList(),
|
2022-07-15 14:25:16 +00:00
|
|
|
};
|
|
|
|
}
|