rluv_client/lib/models/shared_note.dart

69 lines
1.5 KiB
Dart
Raw Permalink Normal View History

2023-07-27 01:40:26 -06:00
import 'dart:convert';
2023-07-22 21:29:32 -06:00
import 'dart:ui';
import 'package:json_annotation/json_annotation.dart';
import '../global/utils.dart';
part 'shared_note.g.dart';
@JsonSerializable()
class SharedNote {
2023-07-27 01:40:26 -06:00
SharedNote({
2023-07-22 21:29:32 -06:00
this.id,
required this.familyId,
required this.createdByUserId,
required this.content,
2023-07-27 01:40:26 -06:00
required this.title,
2023-07-22 21:29:32 -06:00
this.color,
this.createdAt,
this.updatedAt,
2023-07-27 01:40:26 -06:00
required this.tagIds,
2023-07-22 21:29:32 -06:00
this.isMarkdown = false,
this.hide = false,
});
final int? id;
final int familyId, createdByUserId;
2023-07-27 01:40:26 -06:00
String content, title;
@JsonKey(fromJson: _tagIdsFromJson, toJson: _tagIdsToJson)
List<int> tagIds;
2023-07-22 21:29:32 -06:00
@JsonKey(fromJson: optionalColorFromJson, toJson: optionalColorToJson)
2023-07-27 01:40:26 -06:00
Color? color;
2023-07-22 21:29:32 -06:00
@JsonKey(fromJson: boolFromJson, toJson: boolToJson)
2023-07-27 01:40:26 -06:00
bool isMarkdown;
2023-07-22 21:29:32 -06:00
@JsonKey(fromJson: boolFromJson, toJson: boolToJson)
final bool hide;
@JsonKey(fromJson: dateFromJson, toJson: dateToJson)
final DateTime? createdAt;
@JsonKey(fromJson: dateFromJson, toJson: dateToJson)
final DateTime? updatedAt;
factory SharedNote.fromJson(Map<String, dynamic> json) =>
_$SharedNoteFromJson(json);
Map<String, dynamic> toJson() => _$SharedNoteToJson(this);
2023-07-27 01:40:26 -06:00
factory SharedNote.copy(SharedNote note) =>
SharedNote.fromJson(note.toJson());
}
List<int> _tagIdsFromJson(String tagJson) {
final tagsMap = jsonDecode(tagJson) as List<dynamic>;
return tagsMap
.map(
(e) => int.parse(e),
)
.toList();
}
String _tagIdsToJson(List<int> tagIds) {
return jsonEncode(tagIds);
2023-07-22 21:29:32 -06:00
}