diff --git a/lib/models/task.dart b/lib/models/task.dart index 897f63e..63f9c9b 100644 --- a/lib/models/task.dart +++ b/lib/models/task.dart @@ -2,47 +2,70 @@ import 'package:vikunja_app/models/user.dart'; import 'package:meta/meta.dart'; class Task { - final int id; - final DateTime created, updated, due; - final List reminders; + final int id, parentTaskID, priority; + final DateTime created, updated, dueDate, startDate, endDate; + final List reminderDates; final String text, description; final bool done; - final User owner; + final User createdBy; + final Duration repeatAfter; + final List subtasks; + + //labels Task( {@required this.id, + this.text, + this.description, + this.done, + this.reminderDates, + this.dueDate, + this.startDate, + this.endDate, + this.parentTaskID, + this.priority, + this.repeatAfter, + this.subtasks, this.created, this.updated, - this.reminders, - this.due, - @required this.text, - this.description, - @required this.done, - @required this.owner}); + this.createdBy}); Task.fromJson(Map json) : id = json['id'], - updated = DateTime.fromMillisecondsSinceEpoch(json['updated']), - created = DateTime.fromMillisecondsSinceEpoch(json['created']), - reminders = (json['reminderDates'] as List) + text = json['text'], + description = json['description'], + done = json['done'], + reminderDates = (json['reminderDates'] as List) ?.map((milli) => DateTime.fromMillisecondsSinceEpoch(milli)) ?.toList(), - due = DateTime.fromMillisecondsSinceEpoch(json['dueDate']), - description = json['description'], - text = json['text'], - done = json['done'], - owner = User.fromJson(json['createdBy']); + dueDate = DateTime.fromMillisecondsSinceEpoch(json['dueDate']), + startDate = DateTime.fromMillisecondsSinceEpoch(json['startDate']), + endDate = DateTime.fromMillisecondsSinceEpoch(json['endDate']), + parentTaskID = json['parentTaskID'], + priority = json['priority'], + repeatAfter = Duration(seconds: json['repeatAfter']), + subtasks = (json['subtasks'] as List) + ?.map((subtask) => Task.fromJson(subtask)) + ?.toList(), + updated = DateTime.fromMillisecondsSinceEpoch(json['updated']), + created = DateTime.fromMillisecondsSinceEpoch(json['created']), + createdBy = User.fromJson(json['createdBy']); toJSON() => { 'id': id, + 'text': text, + 'description': description, + 'done': done ?? false, + 'reminderDates': + reminderDates?.map((date) => date.millisecondsSinceEpoch)?.toList(), + 'dueDate': dueDate?.millisecondsSinceEpoch, + 'startDate': startDate?.millisecondsSinceEpoch, + 'endDate': endDate?.millisecondsSinceEpoch, + 'priority': priority, + 'repeatAfter': repeatAfter.inSeconds, + 'subtasks': subtasks?.map((subtask) => subtask.toJSON())?.toList(), + 'createdBy': createdBy?.toJSON(), 'updated': updated?.millisecondsSinceEpoch, 'created': created?.millisecondsSinceEpoch, - 'reminderDates': - reminders?.map((date) => date.millisecondsSinceEpoch)?.toList(), - 'dueDate': due?.millisecondsSinceEpoch, - 'description': description, - 'text': text, - 'done': done ?? false, - 'createdBy': owner?.toJSON() }; }