Skip to content

Commit 97488f6

Browse files
committed
[WIP] Kalpataru - get NoteCardEntity from editor
1 parent b490c06 commit 97488f6

File tree

9 files changed

+467
-7
lines changed

9 files changed

+467
-7
lines changed
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
import 'package:json_annotation/json_annotation.dart';
2+
3+
part 'note_card.g.dart';
4+
5+
@JsonSerializable()
6+
class NoteCard {
7+
String id;
8+
@JsonKey(name: _KeyString._adoptedAt)
9+
String? adoptedAt;
10+
@JsonKey(name: _KeyString._adoptedStatus)
11+
bool adoptedStatus;
12+
@JsonKey(name: _KeyString._blocksCount)
13+
int blocksCount;
14+
@JsonKey(name: _KeyString._backlinksCount)
15+
int backlinksCount;
16+
@JsonKey(name: _KeyString._forwardlinksCount)
17+
int forwardlinksCount;
18+
@JsonKey(name: _KeyString._createdAt)
19+
String createdAt;
20+
@JsonKey(name: _KeyString._currentOwnerId)
21+
int currentOwnerId;
22+
@JsonKey(name: _KeyString._deckId)
23+
String? deckId;
24+
@JsonKey(name: _KeyString._emoji)
25+
String? emoji;
26+
@JsonKey(name: _KeyString._isPremium)
27+
bool isPremium;
28+
@JsonKey(name: _KeyString._orderPosition)
29+
int orderPosition;
30+
@JsonKey(name: _KeyString._originalOwnerId)
31+
int originalOwnerId;
32+
@JsonKey(name: _KeyString._ownedStatus)
33+
bool ownedStatus;
34+
List<dynamic> tags; //dynamic => Tag
35+
String title;
36+
String type;
37+
@JsonKey(name: _KeyString._updatedAt)
38+
String? updatedAt;
39+
List<String> channels;
40+
String? image;
41+
42+
NoteCard(
43+
{required this.id,
44+
required this.createdAt,
45+
required this.currentOwnerId,
46+
required this.originalOwnerId,
47+
required this.title,
48+
required this.channels,
49+
this.updatedAt = null,
50+
this.adoptedAt = null,
51+
this.adoptedStatus = false,
52+
this.blocksCount = 0,
53+
this.backlinksCount = 0,
54+
this.forwardlinksCount = 0,
55+
this.deckId = null,
56+
this.emoji = null,
57+
this.isPremium = false,
58+
this.orderPosition = 0,
59+
this.ownedStatus = true,
60+
this.tags = const [],
61+
this.type = objectAlias,
62+
this.image = null});
63+
64+
factory NoteCard.fromJson(Map<String, dynamic> json) =>
65+
_$SymNoteCardFromJson(json);
66+
67+
Map<String, dynamic> toJson() => _$SymNoteCardToJson(this);
68+
69+
static const _KeyString keyString = const _KeyString();
70+
71+
static const String objectAlias = 'card';
72+
}
73+
74+
class _KeyString {
75+
const _KeyString();
76+
77+
static const String _id = 'id';
78+
static const String _adoptedAt = 'adopted_at';
79+
static const String _adoptedStatus = 'adopted_status';
80+
static const String _blocksCount = 'blocks_count';
81+
static const String _backlinksCount = 'backlinks_count';
82+
static const String _forwardlinksCount = 'forwardlinks_count';
83+
static const String _createdAt = 'created_at';
84+
static const String _currentOwnerId = 'current_owner_id';
85+
static const String _deckId = 'deck_id';
86+
static const String _emoji = 'emoji';
87+
static const String _isPremium = 'is_premium';
88+
static const String _orderPosition = 'order_position';
89+
static const String _originalOwnerId = 'original_owner_id';
90+
static const String _ownedStatus = 'owned_status';
91+
static const String _tags = 'tags'; //dynamic => Tag
92+
static const String _title = 'title';
93+
static const String _type = 'type';
94+
static const String _updatedAt = 'updated_at';
95+
static const String _channels = 'channels';
96+
97+
String get id => _id;
98+
String get adoptedAt => _adoptedAt;
99+
String get adoptedStatus => _adoptedStatus;
100+
String get channels => _channels;
101+
String get updatedAt => _updatedAt;
102+
String get type => _type;
103+
String get title => _title;
104+
String get tags => _tags;
105+
String get ownedStatus => _ownedStatus;
106+
String get originalOwnerId => _originalOwnerId;
107+
String get orderPosition => _orderPosition;
108+
String get isPremium => _isPremium;
109+
String get emoji => _emoji;
110+
String get deckId => _deckId;
111+
String get currentOwnerId => _currentOwnerId;
112+
String get createdAt => _createdAt;
113+
String get forwardlinksCount => _forwardlinksCount;
114+
String get backlinksCount => _backlinksCount;
115+
String get blocksCount => _blocksCount;
116+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import '../sym_block/sym_block.dart';
2+
import 'note_card.dart';
3+
4+
class SymNoteCardEntity extends NoteCard {
5+
final List<SymBlock> blocks;
6+
SymNoteCardEntity({
7+
required String id,
8+
required String? adoptedAt,
9+
required bool adoptedStatus,
10+
required int blocksCount,
11+
required int backlinksCount,
12+
required int forwardlinksCount,
13+
required String createdAt,
14+
required int currentOwnerId,
15+
required String? deckId,
16+
required String? emoji,
17+
required bool isPremium,
18+
required int orderPosition,
19+
required int originalOwnerId,
20+
required bool ownedStatus,
21+
required List<dynamic> tags, //dynamic => Tag
22+
required String title,
23+
required String type,
24+
required String? updatedAt,
25+
required List<String> channels,
26+
required String? image,
27+
required this.blocks,
28+
}) : super(
29+
id: id,
30+
adoptedAt: adoptedAt,
31+
adoptedStatus: adoptedStatus,
32+
channels: channels,
33+
updatedAt: updatedAt,
34+
type: type,
35+
title: title,
36+
tags: tags,
37+
ownedStatus: ownedStatus,
38+
originalOwnerId: originalOwnerId,
39+
orderPosition: orderPosition,
40+
isPremium: isPremium,
41+
emoji: emoji,
42+
deckId: deckId,
43+
currentOwnerId: currentOwnerId,
44+
createdAt: createdAt,
45+
forwardlinksCount: forwardlinksCount,
46+
backlinksCount: backlinksCount,
47+
blocksCount: blocksCount,
48+
);
49+
50+
static SymNoteCardEntity fromNoteCard(NoteCard card, List<SymBlock> blocks) {
51+
return SymNoteCardEntity(
52+
id: card.id,
53+
adoptedAt: card.adoptedAt,
54+
adoptedStatus: card.adoptedStatus,
55+
blocksCount: card.blocksCount,
56+
backlinksCount: card.backlinksCount,
57+
forwardlinksCount: card.forwardlinksCount,
58+
createdAt: card.createdAt,
59+
currentOwnerId: card.currentOwnerId,
60+
deckId: card.deckId,
61+
emoji: card.emoji,
62+
isPremium: card.isPremium,
63+
orderPosition: card.orderPosition,
64+
originalOwnerId: card.originalOwnerId,
65+
ownedStatus: card.ownedStatus,
66+
tags: card.tags,
67+
title: card.title,
68+
type: card.type,
69+
updatedAt: card.updatedAt,
70+
channels: card.channels,
71+
image: card.image,
72+
blocks: blocks);
73+
}
74+
75+
factory SymNoteCardEntity.fromJson(Map<String, dynamic> json) {
76+
final blocks = json[SymBlock.objectAlias] as List<SymBlock>;
77+
78+
return fromNoteCard(NoteCard.fromJson(json), blocks);
79+
}
80+
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
import 'package:json_annotation/json_annotation.dart';
2+
import '../note_card/note_card.dart';
3+
4+
part 'block.g.dart';
5+
6+
@JsonSerializable()
7+
class Block {
8+
String id;
9+
@JsonKey(name: 'block_type')
10+
String blocktype;
11+
@JsonKey(name: 'card_id')
12+
String cardId;
13+
String content;
14+
String type;
15+
@JsonKey(name: 'created_at')
16+
String createdAt;
17+
@JsonKey(name: 'deck_id')
18+
String? deckId;
19+
@JsonKey(name: 'order_position')
20+
int orderPosition;
21+
@JsonKey(name: 'potential_words')
22+
List<String> potentialWords;
23+
List<dynamic> tags; //dynamic => Tag
24+
@JsonKey(name: 'forwardlinks_count')
25+
int forwardlinksCount;
26+
@JsonKey(name: 'updated_at')
27+
String? updatedAt;
28+
@JsonKey(name: 'current_owner_id')
29+
int currentOwnerId;
30+
@JsonKey(name: 'original_owner_id')
31+
int originalOwnerId;
32+
List<String> channels;
33+
34+
Block(
35+
{required this.id,
36+
required this.blocktype,
37+
required this.cardId,
38+
required this.content,
39+
required this.createdAt,
40+
required this.deckId,
41+
required this.orderPosition,
42+
required this.potentialWords,
43+
required this.tags,
44+
required this.forwardlinksCount,
45+
required this.updatedAt,
46+
required this.currentOwnerId,
47+
required this.originalOwnerId,
48+
required this.type,
49+
required this.channels});
50+
51+
factory Block.fromJson(Map<String, dynamic> json) => _$BlockFromJson(json);
52+
53+
factory Block.emptyBlock(String id, NoteCard card) {
54+
return Block(
55+
id: id,
56+
blocktype: "content",
57+
cardId: card.id,
58+
content: "",
59+
createdAt: card.createdAt,
60+
deckId: null,
61+
orderPosition: 0,
62+
potentialWords: [],
63+
tags: [],
64+
forwardlinksCount: 0,
65+
updatedAt: null,
66+
currentOwnerId: card.originalOwnerId,
67+
originalOwnerId: card.originalOwnerId,
68+
type: objectAlias,
69+
channels: card.channels,
70+
);
71+
}
72+
73+
Map<String, dynamic> toJson() => _$BlockToJson(this);
74+
75+
static const _KeyString keyString = const _KeyString();
76+
77+
static const String objectAlias = 'block';
78+
}
79+
80+
class _KeyString {
81+
const _KeyString();
82+
83+
static const String _id = 'id';
84+
static const String _blockType = 'block_type';
85+
static const String _cardId = 'card_id';
86+
static const String _content = 'content';
87+
static const String _createdAt = 'created_at';
88+
static const String _deckId = 'deck_id';
89+
static const String _order_position = 'order_position';
90+
static const String _potentialWords = 'potential_words';
91+
static const String _tags = 'tags';
92+
static const String _forwardlinksCount = 'forwardlinks_count';
93+
static const String _inline_tag = 'inline_tag';
94+
static const String _title = 'title';
95+
static const String _type = 'type';
96+
static const String _updated_at = 'updated_at';
97+
static const String _currentOwnerId = 'current_owner_id';
98+
static const String _originalOwnerId = 'original_owner_id';
99+
static const String _channels = 'channels';
100+
101+
String get id => _id;
102+
String get blockType => _blockType;
103+
String get cardId => _cardId;
104+
String get content => _content;
105+
String get createdAt => _createdAt;
106+
String get deckId => _deckId;
107+
String get order_position => _order_position;
108+
String get potentialWords => _potentialWords;
109+
String get tags => _tags;
110+
String get forwardlinksCount => _forwardlinksCount;
111+
String get inline_tag => _inline_tag;
112+
String get title => _title;
113+
String get type => _type;
114+
String get updated_at => _updated_at;
115+
String get currentOwnerId => _currentOwnerId;
116+
String get originalOwnerId => _originalOwnerId;
117+
String get channels => _channels;
118+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import 'sym_block.dart';
2+
import '../note_card/note_card.dart';
3+
4+
class NoteCardSingleBlockEntity extends NoteCard {
5+
final SymBlock block;
6+
NoteCardSingleBlockEntity({
7+
required String id,
8+
required String? adoptedAt,
9+
required bool adoptedStatus,
10+
required int blocksCount,
11+
required int backlinksCount,
12+
required int forwardlinksCount,
13+
required String createdAt,
14+
required int currentOwnerId,
15+
required String? deckId,
16+
required String? emoji,
17+
required bool isPremium,
18+
required int orderPosition,
19+
required int originalOwnerId,
20+
required bool ownedStatus,
21+
required List<dynamic> tags, //dynamic => Tag
22+
required String title,
23+
required String type,
24+
required String? updatedAt,
25+
required List<String> channels,
26+
required String? image,
27+
required this.block,
28+
}) : super(
29+
id: id,
30+
adoptedAt: adoptedAt,
31+
adoptedStatus: adoptedStatus,
32+
channels: channels,
33+
updatedAt: updatedAt,
34+
type: type,
35+
title: title,
36+
tags: tags,
37+
ownedStatus: ownedStatus,
38+
originalOwnerId: originalOwnerId,
39+
orderPosition: orderPosition,
40+
isPremium: isPremium,
41+
emoji: emoji,
42+
deckId: deckId,
43+
currentOwnerId: currentOwnerId,
44+
createdAt: createdAt,
45+
forwardlinksCount: forwardlinksCount,
46+
backlinksCount: backlinksCount,
47+
blocksCount: blocksCount,
48+
);
49+
50+
factory NoteCardSingleBlockEntity.fromJson(Map<String, dynamic> json) {
51+
final block = SymBlock.fromJson(json['card']);
52+
53+
return fromNoteCard(NoteCard.fromJson(json), block);
54+
}
55+
56+
static NoteCardSingleBlockEntity fromNoteCard(NoteCard card, SymBlock block) {
57+
return NoteCardSingleBlockEntity(
58+
id: card.id,
59+
adoptedAt: card.adoptedAt,
60+
adoptedStatus: card.adoptedStatus,
61+
blocksCount: card.blocksCount,
62+
backlinksCount: card.backlinksCount,
63+
forwardlinksCount: card.forwardlinksCount,
64+
createdAt: card.createdAt,
65+
currentOwnerId: card.currentOwnerId,
66+
deckId: card.deckId,
67+
emoji: card.emoji,
68+
isPremium: card.isPremium,
69+
orderPosition: card.orderPosition,
70+
originalOwnerId: card.originalOwnerId,
71+
ownedStatus: card.ownedStatus,
72+
tags: card.tags,
73+
title: card.title,
74+
type: card.type,
75+
updatedAt: card.updatedAt,
76+
channels: card.channels,
77+
image: card.image,
78+
block: block);
79+
}
80+
}

lib/src/sym_model/sym_block/sym_block_type.dart

Whitespace-only changes.

lib/src/sym_utils/sym_channels_creator.dart

Whitespace-only changes.

lib/src/sym_utils/sym_timestamp_creator.dart

Whitespace-only changes.

lib/src/sym_utils/sym_uuid_creator.dart

Whitespace-only changes.

0 commit comments

Comments
 (0)