Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/src/dao/dictionary_infos_dao.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions lib/src/dao/flashcard_sets_dao.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions lib/src/dao/kanjis_dao.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions lib/src/dao/my_dictionary_lists_dao.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,33 @@ class MyDictionaryListsDao extends DatabaseAccessor<AppDatabase>
});
}

Future<void> addDictionaryItems(
MyDictionaryList dictionaryList,
List<DictionaryItem> dictionaryItems,
) async {
final items = dictionaryItems.map((item) {
final vocabId = item is Vocab ? item.id : 0;
final kanjiId = item is Kanji ? item.id : 0;
return MyDictionaryListItemsCompanion(
listId: Value(dictionaryList.id),
vocabId: Value(vocabId),
kanjiId: Value(kanjiId),
);
}).toList();

await transaction(() async {
for (final item in items) {
await db
.into(db.myDictionaryListItems)
.insert(item, mode: InsertMode.insertOrIgnore);
}

await (db.update(db.myDictionaryLists)
..where((list) => list.id.equals(dictionaryList.id)))
.write(MyDictionaryListsCompanion(timestamp: Value(DateTime.now())));
});
}

Future<void> removeDictionaryItem(
MyDictionaryList dictionaryList,
DictionaryItem dictionaryItem,
Expand Down
12 changes: 12 additions & 0 deletions lib/src/dao/my_dictionary_lists_dao.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions lib/src/dao/predefined_dictionary_lists_dao.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions lib/src/dao/proper_nouns_dao.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions lib/src/dao/radicals_dao.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions lib/src/dao/search_history_items_dao.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions lib/src/dao/spaced_repetition_datas_dao.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions lib/src/dao/text_analysis_history_items_dao.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions lib/src/dao/vocabs_dao.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 47 additions & 1 deletion test/dao/my_dictionary_lists_dao_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ void main() {
expect(newFlashcardSets[0].myDictionaryLists.length, 0);
});

test('Dictionary items', () async {
test('Dictionary item operations', () async {
final dictionaryList1 =
await database.myDictionaryListsDao.create('list1');
final dictionaryList2 =
Expand Down Expand Up @@ -241,6 +241,52 @@ void main() {
expect(list2Items.kanjiIds.length, 0);
});

test('addDictionaryItems', () async {
final dictionaryList = await database.myDictionaryListsDao.create('list');

// Get empty items
final emptyList1Items = await database.myDictionaryListsDao
.getDictionaryListItems(dictionaryList);
expect(emptyList1Items.vocabIds.length, 0);
expect(emptyList1Items.kanjiIds.length, 0);

// Add items to dictionary list
await database.myDictionaryListsDao.addDictionaryItem(
dictionaryList,
await database.vocabsDao.get(1000220),
);
await database.myDictionaryListsDao.addDictionaryItem(
dictionaryList,
await database.vocabsDao.get(1003430),
);

// Get newly added to list
var listItems = await database.myDictionaryListsDao
.getDictionaryListItems(dictionaryList);
expect(listItems.vocabIds.length, 2);
expect(listItems.vocabIds[0], 1003430);
expect(listItems.vocabIds[1], 1000220);

// Add several items at once
await database.myDictionaryListsDao.addDictionaryItems(
dictionaryList,
[
await database.vocabsDao.get(1000160),
await database.vocabsDao.get(1003430),
await database.vocabsDao.get(1001390),
],
);

// Check new contents
listItems = await database.myDictionaryListsDao
.getDictionaryListItems(dictionaryList);
expect(listItems.vocabIds.length, 4);
expect(listItems.vocabIds[0], 1001390);
expect(listItems.vocabIds[1], 1000160);
expect(listItems.vocabIds[2], 1003430);
expect(listItems.vocabIds[3], 1000220);
});

test('getContainingDictionaryItem', () async {
final dictionaryList1 =
await database.myDictionaryListsDao.create('list1');
Expand Down