diff --git a/assets/schema.json b/assets/schema.json index c33fab2..eedfb05 100644 --- a/assets/schema.json +++ b/assets/schema.json @@ -13,6 +13,9 @@ "id": { "type": "string" }, + "createdAt": { + "type": "string" + }, "name": { "type": "string" }, @@ -28,6 +31,7 @@ }, "required": [ "id", + "createdAt", "name", "players", "group", @@ -45,6 +49,9 @@ "id": { "type": "string" }, + "createdAt": { + "type": "string" + }, "name": { "type": "string" }, @@ -57,19 +64,7 @@ "id": { "type": "string" }, - "name": { - "type": "string" - } - }, - "required": [ - "id", - "name" - ] - }, - { - "type": "object", - "properties": { - "id": { + "createdAt": { "type": "string" }, "name": { @@ -78,6 +73,7 @@ }, "required": [ "id", + "createdAt", "name" ] } @@ -86,6 +82,7 @@ }, "required": [ "id", + "createdAt", "name", "members" ] @@ -101,19 +98,7 @@ "id": { "type": "string" }, - "name": { - "type": "string" - } - }, - "required": [ - "id", - "name" - ] - }, - { - "type": "object", - "properties": { - "id": { + "createdAt": { "type": "string" }, "name": { @@ -122,16 +107,12 @@ }, "required": [ "id", + "createdAt", "name" ] } ] } - }, - "required": [ - "games", - "groups", - "players" - ] + } } diff --git a/lib/data/dto/game.dart b/lib/data/dto/game.dart index 30898e5..4188bc4 100644 --- a/lib/data/dto/game.dart +++ b/lib/data/dto/game.dart @@ -5,11 +5,11 @@ import 'package:uuid/uuid.dart'; class Game { final String id; + final DateTime createdAt; final String name; final List? players; final Group? group; final String? winner; - final DateTime createdAt; Game({ String? id, @@ -30,6 +30,7 @@ class Game { Game.fromJson(Map json) : id = json['id'], name = json['name'], + createdAt = DateTime.parse(json['createdAt']), players = json['players'] != null ? (json['players'] as List) .map((playerJson) => Player.fromJson(playerJson)) @@ -41,6 +42,7 @@ class Game { /// Converts the Game instance to a JSON object. Map toJson() => { 'id': id, + 'createdAt': createdAt.toIso8601String(), 'name': name, 'players': players?.map((player) => player.toJson()).toList(), 'group': group?.toJson(), diff --git a/lib/data/dto/group.dart b/lib/data/dto/group.dart index 3f00bf5..92dbd09 100644 --- a/lib/data/dto/group.dart +++ b/lib/data/dto/group.dart @@ -4,9 +4,9 @@ import 'package:uuid/uuid.dart'; class Group { final String id; + final DateTime createdAt; final String name; final List members; - final DateTime createdAt; Group({ String? id, @@ -24,6 +24,7 @@ class Group { /// Creates a Group instance from a JSON object. Group.fromJson(Map json) : id = json['id'], + createdAt = DateTime.parse(json['createdAt']), name = json['name'], members = (json['members'] as List) .map((memberJson) => Player.fromJson(memberJson)) @@ -32,6 +33,7 @@ class Group { /// Converts the Group instance to a JSON object. Map toJson() => { 'id': id, + 'createdAt': createdAt.toIso8601String(), 'name': name, 'members': members.map((member) => member.toJson()).toList(), }; diff --git a/lib/data/dto/player.dart b/lib/data/dto/player.dart index f7e05d2..cfb4f4b 100644 --- a/lib/data/dto/player.dart +++ b/lib/data/dto/player.dart @@ -3,8 +3,8 @@ import 'package:uuid/uuid.dart'; class Player { final String id; - final String name; final DateTime createdAt; + final String name; Player({String? id, DateTime? createdAt, required this.name}) : id = id ?? const Uuid().v4(), @@ -18,8 +18,13 @@ class Player { /// Creates a Player instance from a JSON object. Player.fromJson(Map json) : id = json['id'], + createdAt = DateTime.parse(json['createdAt']), name = json['name']; /// Converts the Player instance to a JSON object. - Map toJson() => {'id': id, 'name': name}; + Map toJson() => { + 'id': id, + 'createdAt': createdAt.toIso8601String(), + 'name': name, + }; }