Add readMany
This commit is contained in:
parent
a396f16de3
commit
7fec4c243d
3 changed files with 26 additions and 1 deletions
|
@ -1,3 +1,6 @@
|
|||
# 2.0.0-alpha.11
|
||||
* Add `readMany` to `Service`.
|
||||
|
||||
# 2.0.0-alpha.10
|
||||
* All calls to `Service.parseId` are now affixed with the `<Id>` argument.
|
||||
* Added `uri` getter to `AngelHttp`.
|
||||
|
|
|
@ -105,6 +105,14 @@ class Service<Id, Data> extends Routable {
|
|||
throw new AngelHttpException.methodNotAllowed();
|
||||
}
|
||||
|
||||
/// Reads multiple resources at once.
|
||||
///
|
||||
/// Service implementations should override this to ensure data is fetched within a
|
||||
/// single round trip.
|
||||
Future<List<Data>> readMany(List<Id> ids, [Map<String, dynamic> params]) {
|
||||
return Future.wait(ids.map((id) => read(id, params)));
|
||||
}
|
||||
|
||||
/// Creates a resource.
|
||||
Future<Data> create(Data data, [Map<String, dynamic> params]) {
|
||||
throw new AngelHttpException.methodNotAllowed();
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:angel_container/mirrors.dart';
|
||||
import 'package:angel_framework/angel_framework.dart';
|
||||
import 'package:angel_framework/http.dart';
|
||||
|
@ -17,12 +19,13 @@ main() {
|
|||
'Content-Type': 'application/json'
|
||||
};
|
||||
Angel app;
|
||||
MapService service;
|
||||
String url;
|
||||
http.Client client;
|
||||
|
||||
setUp(() async {
|
||||
app = new Angel(reflector: MirrorsReflector())
|
||||
..use('/todos', new MapService())
|
||||
..use('/todos', service = new MapService())
|
||||
..errorHandler = (e, req, res) {
|
||||
print('Whoops: ${e.error}');
|
||||
if (e.stackTrace != null) print(new Chain.forTrace(e.stackTrace).terse);
|
||||
|
@ -98,6 +101,17 @@ main() {
|
|||
expect(jsons['over'], equals('write'));
|
||||
});
|
||||
|
||||
test('readMany', () async {
|
||||
var items = <Map>[
|
||||
await service.create({'foo': 'bar'}),
|
||||
await service.create({'bar': 'baz'}),
|
||||
await service.create({'baz': 'quux'})
|
||||
];
|
||||
|
||||
var ids = items.map((m) => m['id'] as String).toList();
|
||||
expect(await service.readMany(ids), items);
|
||||
});
|
||||
|
||||
test('can delete data', () async {
|
||||
String postData = json.encode({'text': 'Hello, world!'});
|
||||
var created = await client
|
||||
|
|
Loading…
Reference in a new issue