Done
This commit is contained in:
parent
8cff7a3f2c
commit
932c8841ad
2 changed files with 19 additions and 2 deletions
|
@ -4,6 +4,7 @@ import 'package:angel_framework/angel_framework.dart';
|
||||||
import 'package:resp_client/resp_client.dart';
|
import 'package:resp_client/resp_client.dart';
|
||||||
import 'package:resp_client/resp_commands.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>> {
|
class RedisService extends Service<String, Map<String, dynamic>> {
|
||||||
final RespCommands respCommands;
|
final RespCommands respCommands;
|
||||||
|
|
||||||
|
@ -47,6 +48,14 @@ class RedisService extends Service<String, Map<String, dynamic>> {
|
||||||
return data;
|
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
|
@override
|
||||||
Future<Map<String, dynamic>> update(String id, Map<String, dynamic> data,
|
Future<Map<String, dynamic>> update(String id, Map<String, dynamic> data,
|
||||||
[Map<String, dynamic> params]) async {
|
[Map<String, dynamic> params]) async {
|
||||||
|
|
|
@ -36,11 +36,19 @@ main() async {
|
||||||
expect(await service.read(id), input);
|
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 {
|
test('update', () async {
|
||||||
var id = 'hoopla${new DateTime.now().millisecondsSinceEpoch}';
|
var id = 'hoopla${new DateTime.now().millisecondsSinceEpoch}';
|
||||||
await service.create({'id': id, 'bar': 'baz'});
|
await service.create({'id': id, 'bar': 'baz'});
|
||||||
var output = await service.update(id, {'bar': 'quux'});
|
var output = await service.update(id, {'yes': 'no'});
|
||||||
expect(output, {'id': id, 'bar': 'quux'});
|
expect(output, {'id': id, 'yes': 'no'});
|
||||||
expect(await service.read(id), output);
|
expect(await service.read(id), output);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue