This commit is contained in:
Tobe O 2018-10-21 13:04:21 -04:00
parent 8cff7a3f2c
commit 932c8841ad
2 changed files with 19 additions and 2 deletions

View file

@ -4,6 +4,7 @@ import 'package:angel_framework/angel_framework.dart';
import 'package:resp_client/resp_client.dart';
import 'package:resp_client/resp_commands.dart';
/// An Angel service that reads and writes JSON within a Redis store.
class RedisService extends Service<String, Map<String, dynamic>> {
final RespCommands respCommands;
@ -47,6 +48,14 @@ class RedisService extends Service<String, Map<String, dynamic>> {
return data;
}
@override
Future<Map<String, dynamic>> modify(String id, Map<String, dynamic> data,
[Map<String, dynamic> params]) async {
var input = await read(id);
input.addAll(data);
return await update(id, input, params);
}
@override
Future<Map<String, dynamic>> update(String id, Map<String, dynamic> data,
[Map<String, dynamic> params]) async {

View file

@ -36,11 +36,19 @@ main() async {
expect(await service.read(id), input);
});
test('modify', () async {
var id = 'jamboree${new DateTime.now().millisecondsSinceEpoch}';
await service.create({'id': id, 'bar': 'baz', 'yes': 'no'});
var output = await service.modify(id, {'bar': 'quux'});
expect(output, {'id': id, 'bar': 'quux', 'yes': 'no'});
expect(await service.read(id), output);
});
test('update', () async {
var id = 'hoopla${new DateTime.now().millisecondsSinceEpoch}';
await service.create({'id': id, 'bar': 'baz'});
var output = await service.update(id, {'bar': 'quux'});
expect(output, {'id': id, 'bar': 'quux'});
var output = await service.update(id, {'yes': 'no'});
expect(output, {'id': id, 'yes': 'no'});
expect(await service.read(id), output);
});