33 lines
817 B
Dart
33 lines
817 B
Dart
import 'package:json_annotation/json_annotation.dart';
|
|
import 'drink.dart';
|
|
|
|
part 'journal_entry.g.dart';
|
|
|
|
@JsonSerializable()
|
|
class JournalEntry {
|
|
final String id;
|
|
@JsonKey(fromJson: _dateTimeFromJson, toJson: _dateTimeToJson)
|
|
final DateTime date;
|
|
final Drink drink;
|
|
final String? notes;
|
|
final String? mood;
|
|
final String? weather;
|
|
|
|
JournalEntry({
|
|
required this.id,
|
|
required this.date,
|
|
required this.drink,
|
|
this.notes,
|
|
this.mood,
|
|
this.weather,
|
|
});
|
|
|
|
factory JournalEntry.fromJson(Map<String, dynamic> json) =>
|
|
_$JournalEntryFromJson(json);
|
|
Map<String, dynamic> toJson() => _$JournalEntryToJson(this);
|
|
|
|
static DateTime _dateTimeFromJson(String json) => DateTime.parse(json);
|
|
static String _dateTimeToJson(DateTime dateTime) =>
|
|
dateTime.toIso8601String();
|
|
}
|