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

import 'dart:async';
import 'package:vikunja_app/api/client.dart';
import 'package:vikunja_app/api/service.dart';
import 'package:vikunja_app/models/list.dart';
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())
.then((response) => TaskList.fromJson(response.body));
}
@override
Future delete(int listId) {
return client.delete('/lists/$listId').then((_) {});
}
@override
Future<TaskList> get(int listId) {
/*
return client
.get('/lists/$listId')
.then((response) => TaskList.fromJson(response.body));
*/
return client.get('/lists/$listId').then((response) {
final map = response.body;
if (map.containsKey('id')) {
return client.get("/lists/$listId/tasks")
.then((tasks) => TaskList.fromJson(
map, tasksJson: tasks.body));
}
return TaskList.fromJson(map);
});
}
@override
Future<List<TaskList>> getAll() {
return client.get('/lists').then((response) =>
convertList(response.body, (result) => TaskList.fromJson(result)));
}
@override
Future<List<TaskList>> getByNamespace(int namespaceId) {
return client.get('/namespaces/$namespaceId/lists').then((response) =>
convertList(response.body, (result) => TaskList.fromJson(result)));
}
@override
Future<TaskList> update(TaskList tl) {
return client
.post('/lists/${tl.id}', body: tl.toJSON())
.then((response) => TaskList.fromJson(response.body));
}
}