This repository has been archived on 2022-04-20. You can view files and clone it, but cannot push or open issues or pull requests.
app/lib/api/list_implementation.dart

60 lines
1.7 KiB
Dart
Raw Normal View History

import 'dart:async';
2018-09-22 20:56:16 +00:00
import 'package:vikunja_app/api/client.dart';
import 'package:vikunja_app/api/service.dart';
2019-03-11 20:29:15 +00:00
import 'package:vikunja_app/models/list.dart';
2018-09-22 20:56:16 +00:00
import 'package:vikunja_app/service/services.dart';
class ListAPIService extends APIService implements ListService {
ListAPIService(Client client) : super(client);
@override
Future<TaskList> create(namespaceId, TaskList tl) {
return client
.put('/namespaces/$namespaceId/lists', body: tl.toJSON())
2021-06-04 09:34:25 +00:00
.then((response) => TaskList.fromJson(response.body));
}
@override
Future delete(int listId) {
return client.delete('/lists/$listId').then((_) {});
}
@override
Future<TaskList> get(int listId) {
2021-06-08 05:50:05 +00:00
/*
2021-06-04 09:34:25 +00:00
return client
.get('/lists/$listId')
.then((response) => TaskList.fromJson(response.body));
2021-06-08 05:50:05 +00:00
*/
return client.get('/lists/$listId').then((response) {
final map = response.body;
2021-03-15 07:31:38 +00:00
if (map.containsKey('id')) {
2021-06-08 05:50:05 +00:00
return client.get("/lists/$listId/tasks")
.then((tasks) => TaskList.fromJson(
map, tasksJson: tasks.body));
2021-03-15 07:31:38 +00:00
}
return TaskList.fromJson(map);
});
}
@override
Future<List<TaskList>> getAll() {
2021-06-04 09:34:25 +00:00
return client.get('/lists').then((response) =>
convertList(response.body, (result) => TaskList.fromJson(result)));
}
@override
Future<List<TaskList>> getByNamespace(int namespaceId) {
2021-06-04 09:34:25 +00:00
return client.get('/namespaces/$namespaceId/lists').then((response) =>
convertList(response.body, (result) => TaskList.fromJson(result)));
}
@override
Future<TaskList> update(TaskList tl) {
return client
2019-03-11 20:29:15 +00:00
.post('/lists/${tl.id}', body: tl.toJSON())
2021-06-04 09:34:25 +00:00
.then((response) => TaskList.fromJson(response.body));
}
}