Neue Datenbank Struktur #156
50
lib/data/dto/game.dart
Normal file
50
lib/data/dto/game.dart
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
import 'package:clock/clock.dart';
|
||||||
|
import 'package:uuid/uuid.dart';
|
||||||
|
|
||||||
|
class Game {
|
||||||
|
final String id;
|
||||||
|
final DateTime createdAt;
|
||||||
|
final String name;
|
||||||
|
final String? ruleset;
|
||||||
|
gelbeinhalb marked this conversation as resolved
|
|||||||
|
final String? description;
|
||||||
|
final int? color;
|
||||||
|
final String? icon;
|
||||||
|
|
||||||
|
Game({
|
||||||
|
String? id,
|
||||||
|
DateTime? createdAt,
|
||||||
|
required this.name,
|
||||||
|
this.ruleset,
|
||||||
|
this.description,
|
||||||
|
this.color,
|
||||||
|
flixcoo
commented
Description sollte nicht obligatorisch sein, sondern optional. Wenn nicht gesetzt soll es ein leerer String werden. Description sollte nicht obligatorisch sein, sondern optional. Wenn nicht gesetzt soll es ein leerer String werden.
gelbeinhalb
commented
Dachte man soll den als leeren String selber setzen müssen Dachte man soll den als leeren String selber setzen müssen
flixcoo
commented
würde das lieber so machen, weil man ja sonst immer unnötig die description setzten muss würde das lieber so machen, weil man ja sonst immer unnötig die description setzten muss
sneeex
commented
finde auch optional finde auch optional
|
|||||||
|
this.icon,
|
||||||
|
}) : id = id ?? const Uuid().v4(),
|
||||||
|
createdAt = createdAt ?? clock.now();
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'Game{id: $id, name: $name, ruleset: $ruleset, description: $description, color: $color, icon: $icon}';
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Creates a Game instance from a JSON object.
|
||||||
|
Game.fromJson(Map<String, dynamic> json)
|
||||||
|
: id = json['id'],
|
||||||
|
createdAt = DateTime.parse(json['createdAt']),
|
||||||
|
name = json['name'],
|
||||||
|
ruleset = json['ruleset'],
|
||||||
|
description = json['description'],
|
||||||
|
color = json['color'],
|
||||||
|
icon = json['icon'];
|
||||||
|
|
||||||
|
/// Converts the Game instance to a JSON object.
|
||||||
|
Map<String, dynamic> toJson() => {
|
||||||
|
'id': id,
|
||||||
|
'createdAt': createdAt.toIso8601String(),
|
||||||
|
'name': name,
|
||||||
|
'ruleset': ruleset,
|
||||||
|
'description': description,
|
||||||
|
'color': color,
|
||||||
|
'icon': icon,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user
Ruleset sollte nicht optional, weil das immer gebraucht wird
Ruleset als enum