forked from vikunja/app
Fixed task fromJson
This commit is contained in:
parent
f5c2c486d7
commit
55686ae25e
|
@ -1,13 +1,9 @@
|
|||
import 'package:meta/meta.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import 'package:vikunja_app/models/label.dart';
|
||||
import 'package:vikunja_app/models/user.dart';
|
||||
import 'package:vikunja_app/utils/datetime_to_unix.dart';
|
||||
|
||||
part 'task.g.dart';
|
||||
|
||||
@JsonSerializable(nullable: true)
|
||||
class Task {
|
||||
final int id, parentTaskID, priority;
|
||||
final DateTime created, updated, dueDate, startDate, endDate;
|
||||
|
@ -36,39 +32,40 @@ class Task {
|
|||
this.created,
|
||||
this.updated,
|
||||
this.createdBy});
|
||||
factory Task.fromJson(Map<String, dynamic> json) => _$TaskFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$TaskToJson(this);
|
||||
/*
|
||||
Task.fromJson(Map<String, dynamic> json)
|
||||
: id = json['id'],
|
||||
text = json['text'],
|
||||
description = json['description'],
|
||||
done = json['done'],
|
||||
reminderDates = json['reminderDates'] == null
|
||||
|
||||
Task.fromJson(Map<String, dynamic> inp)
|
||||
: id = inp['id'],
|
||||
text = inp['text'],
|
||||
description = inp['description'],
|
||||
done = inp['done'],
|
||||
reminderDates = inp['reminderDates'] == null
|
||||
? null
|
||||
: (json['reminderDates'].cast<int>() as List<dynamic>)
|
||||
?.map((milli) => dateTimeFromUnixTimestamp(milli))
|
||||
?.toList(),
|
||||
dueDate = dateTimeFromUnixTimestamp(json['dueDate']),
|
||||
startDate = dateTimeFromUnixTimestamp(json['startDate']),
|
||||
endDate = dateTimeFromUnixTimestamp(json['endDate']),
|
||||
parentTaskID = json['parentTaskID'],
|
||||
priority = json['priority'],
|
||||
repeatAfter = Duration(seconds: json['repeatAfter']),
|
||||
labels = json['labels'] == null
|
||||
: inp['reminderDates']
|
||||
.map((ts) => dateTimeFromUnixTimestamp(ts))
|
||||
.cast<DateTime>()
|
||||
.toList(),
|
||||
dueDate = dateTimeFromUnixTimestamp(inp['dueDate']),
|
||||
startDate = dateTimeFromUnixTimestamp(inp['startDate']),
|
||||
endDate = dateTimeFromUnixTimestamp(inp['endDate']),
|
||||
parentTaskID = inp['parentTaskID'],
|
||||
priority = inp['priority'],
|
||||
repeatAfter = Duration(seconds: inp['repeatAfter']),
|
||||
labels = inp['labels'] == null
|
||||
? null
|
||||
: (json['labels'] as List<dynamic>)
|
||||
?.map((label) => Label.fromJson(label))
|
||||
?.toList(),
|
||||
subtasks = json['subtasks'] == null
|
||||
: (inp['labels'] as List<dynamic>)
|
||||
.map((label) => Label.fromJson(label))
|
||||
.cast<Label>()
|
||||
.toList(),
|
||||
subtasks = inp['subtasks'] == null
|
||||
? null
|
||||
: (json['subtasks'] as List<dynamic>)
|
||||
?.map((subtask) => Task.fromJson(subtask))
|
||||
?.toList(),
|
||||
updated = dateTimeFromUnixTimestamp(json['updated']),
|
||||
created = dateTimeFromUnixTimestamp(json['created']),
|
||||
createdBy = User.fromJson(json['createdBy']);
|
||||
*/
|
||||
: (inp['subtasks'] as List<dynamic>)
|
||||
.map((subtask) => Task.fromJson(subtask))
|
||||
.cast<Task>()
|
||||
.toList(),
|
||||
updated = dateTimeFromUnixTimestamp(inp['updated']),
|
||||
created = dateTimeFromUnixTimestamp(inp['created']),
|
||||
createdBy = User.fromJson(inp['createdBy']);
|
||||
|
||||
toJSON() => {
|
||||
'id': id,
|
||||
'text': text,
|
||||
|
|
196
pubspec.lock
196
pubspec.lock
|
@ -7,7 +7,7 @@ packages:
|
|||
name: analyzer
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.35.4"
|
||||
version: "0.34.3"
|
||||
archive:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -36,20 +36,6 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.4"
|
||||
build:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: build
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.1.1"
|
||||
build_config:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: build_config
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.3.1+4"
|
||||
charcode:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -78,6 +64,13 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.6"
|
||||
csslib:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: csslib
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.14.6"
|
||||
cupertino_icons:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
@ -94,13 +87,6 @@ packages:
|
|||
url: "https://github.com/MarkOSullivan94/dart_config.git"
|
||||
source: git
|
||||
version: "0.5.0"
|
||||
dart_style:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: dart_style
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.2.4"
|
||||
datetime_picker_formfield:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
@ -138,7 +124,7 @@ packages:
|
|||
name: front_end
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.1.14"
|
||||
version: "0.1.9+1"
|
||||
glob:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -146,6 +132,13 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.1.7"
|
||||
html:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: html
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.13.4+1"
|
||||
http:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
@ -153,6 +146,13 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.12.0"
|
||||
http_multi_server:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: http_multi_server
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.5"
|
||||
http_parser:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -174,27 +174,34 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.15.7"
|
||||
json_annotation:
|
||||
io:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: json_annotation
|
||||
name: io
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.0"
|
||||
json_serializable:
|
||||
dependency: "direct main"
|
||||
version: "0.3.3"
|
||||
js:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: json_serializable
|
||||
name: js
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.3"
|
||||
version: "0.6.1+1"
|
||||
json_rpc_2:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: json_rpc_2
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.9"
|
||||
kernel:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: kernel
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.3.14"
|
||||
version: "0.3.9+1"
|
||||
logging:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -216,6 +223,27 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.1.6"
|
||||
mime:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: mime
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.9.6+2"
|
||||
multi_server_socket:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: multi_server_socket
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.2"
|
||||
node_preamble:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: node_preamble
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.4.4"
|
||||
package_config:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -223,6 +251,13 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.5"
|
||||
package_resolver:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: package_resolver
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.9"
|
||||
path:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -231,12 +266,26 @@ packages:
|
|||
source: hosted
|
||||
version: "1.6.2"
|
||||
petitparser:
|
||||
dependency: "direct main"
|
||||
dependency: transitive
|
||||
description:
|
||||
name: petitparser
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.1"
|
||||
plugin:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: plugin
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.2.0+3"
|
||||
pool:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: pool
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.4.0"
|
||||
pub_semver:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -244,13 +293,6 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.4.2"
|
||||
pubspec_parse:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: pubspec_parse
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.1.4"
|
||||
quiver:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -258,18 +300,53 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.1"
|
||||
shelf:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shelf
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.7.4"
|
||||
shelf_packages_handler:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shelf_packages_handler
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.4"
|
||||
shelf_static:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shelf_static
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.2.8"
|
||||
shelf_web_socket:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shelf_web_socket
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.2.2+4"
|
||||
sky_engine:
|
||||
dependency: transitive
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.99"
|
||||
source_gen:
|
||||
source_map_stack_trace:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: source_gen
|
||||
name: source_map_stack_trace
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.9.4+1"
|
||||
version: "1.1.5"
|
||||
source_maps:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: source_maps
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.10.8"
|
||||
source_span:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -305,6 +382,13 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.1"
|
||||
test:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
name: test
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.5.1+1"
|
||||
test_api:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -312,6 +396,13 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.2.1"
|
||||
test_core:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: test_core
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.2.0+1"
|
||||
typed_data:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -319,6 +410,13 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.1.6"
|
||||
utf:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: utf
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.9.0+5"
|
||||
vector_math:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -326,6 +424,13 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.8"
|
||||
vm_service_client:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: vm_service_client
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.2.6"
|
||||
watcher:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -333,6 +438,13 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.9.7+10"
|
||||
web_socket_channel:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: web_socket_channel
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.9"
|
||||
xml:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
|
@ -13,13 +13,11 @@ dependencies:
|
|||
flutter_secure_storage: 3.1.1
|
||||
http: 0.12.0
|
||||
datetime_picker_formfield: ^0.1.8
|
||||
build: ^1.1.1
|
||||
json_serializable: ^2.0.3
|
||||
petitparser: ^2.1.1
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
test: ^1.4.0
|
||||
flutter_launcher_icons: "^0.6.1"
|
||||
|
||||
flutter_icons:
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:vikunja_app/models/task.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
test('Check encoding with all values set', () {
|
||||
final String json = '{"id": 1,"text": "test","description": "Lorem Ipsum","done": true,"dueDate": 1543834800,"reminderDates": [1543834800,1544612400],"repeatAfter": 3600,"parentTaskID": 0,"priority": 100,"startDate": 1543834800,"endDate": 1543835000,"assignees": null,"labels": null,"subtasks": null,"created": 1542465818,"updated": 1552771527,"createdBy": {"id": 4,"username": "konrad","email": "vikunjatry@kolaente.de","created": 1537855131,"updated": 1545233325}}';
|
||||
final JsonDecoder _decoder = new JsonDecoder();
|
||||
final task = Task.fromJson(_decoder.convert(json));
|
||||
|
||||
expect(task.id, 1);
|
||||
expect(task.text, 'test');
|
||||
expect(task.description, 'Lorem Ipsum');
|
||||
expect(task.done, true);
|
||||
expect(task.reminderDates, [
|
||||
DateTime.fromMillisecondsSinceEpoch(1543834800 * 1000),
|
||||
DateTime.fromMillisecondsSinceEpoch(1544612400 * 1000),
|
||||
]);
|
||||
expect(task.dueDate, DateTime.fromMillisecondsSinceEpoch(1543834800 * 1000));
|
||||
expect(task.repeatAfter, Duration(seconds: 3600));
|
||||
expect(task.parentTaskID, 0);
|
||||
expect(task.priority, 100);
|
||||
expect(task.startDate, DateTime.fromMillisecondsSinceEpoch(1543834800 * 1000));
|
||||
expect(task.endDate, DateTime.fromMillisecondsSinceEpoch(1543835000 * 1000));
|
||||
expect(task.labels, null);
|
||||
expect(task.subtasks, null);
|
||||
expect(task.created, DateTime.fromMillisecondsSinceEpoch(1542465818 * 1000));
|
||||
expect(task.updated, DateTime.fromMillisecondsSinceEpoch(1552771527 * 1000));
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue