forked from avenum/mvvm_todo_list
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_service.dart
40 lines (34 loc) · 1.03 KB
/
data_service.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import 'package:mvvm_todo_list/data/services/database.dart';
import 'package:mvvm_todo_list/domain/db_model.dart';
import 'package:mvvm_todo_list/domain/models/todo_item.dart';
class DataService {
Future createUpdateToDoItem(ToDoItem item) async {
await DB.instance.createUpdate(item);
}
Future rangeUpdateEntities<T extends DbModel>(Iterable<T> elements) async {
await DB.instance.createUpdateRange(elements);
}
Future<ToDoItem> getToDoItemById(int itemId) async {
var res = await DB.instance.get<ToDoItem>(itemId);
if (res != null) return res;
throw Exception('Item not found');
}
Future deleteTodoItem(int id) async {
var model = await DB.instance.get<ToDoItem>(id);
if (model != null) {
await DB.instance.delete(model);
} else {
throw Exception('Item not found');
}
}
Future<List<ToDoItem>> getToDoList({
int take = 10,
int skip = 0,
}) async {
var items = await DB.instance.getAll<ToDoItem>(
skip: skip,
take: take,
);
return items.toList();
}
}