service.create, etc

This commit is contained in:
regiostech 2016-05-03 20:58:28 -04:00
parent 476fc13a80
commit b373db1110
2 changed files with 10 additions and 7 deletions

View file

@ -26,9 +26,10 @@ class MemoryService<T> extends Service {
} else throw new AngelHttpException.NotFound();
}
Future<Object> create(Map data, [Map params]) async {
Future<Object> create(data, [Map params]) async {
try {
items[items.length] = god.deserializeFromMap(data, T);
items[items.length] =
(data is Map) ? god.deserializeFromMap(data, T) : data;
T created = items[items.length - 1];
return makeJson(items.length - 1, created);
} catch (e) {
@ -36,13 +37,14 @@ class MemoryService<T> extends Service {
}
}
Future<Object> modify(id, Map data, [Map params]) async {
Future<Object> modify(id, data, [Map params]) async {
int desiredId = int.parse(id.toString());
if (items.containsKey(desiredId)) {
try {
Map existing = god.serializeToMap(items[desiredId]);
data = mergeMap([existing, data]);
items[desiredId] = god.deserializeFromMap(data, T);
items[desiredId] =
(data is Map) ? god.deserializeFromMap(data, T) : data;
return makeJson(desiredId, items[desiredId]);
} catch (e) {
throw new AngelHttpException.BadRequest(message: 'Invalid data.');
@ -50,11 +52,12 @@ class MemoryService<T> extends Service {
} else throw new AngelHttpException.NotFound();
}
Future<Object> update(id, Map data, [Map params]) async {
Future<Object> update(id, data, [Map params]) async {
int desiredId = int.parse(id.toString());
if (items.containsKey(desiredId)) {
try {
items[desiredId] = god.deserializeFromMap(data, T);
items[desiredId] =
(data is Map) ? god.deserializeFromMap(data, T) : data;
return makeJson(desiredId, items[desiredId]);
} catch (e) {
throw new AngelHttpException.BadRequest(message: 'Invalid data.');

View file

@ -1,5 +1,5 @@
name: angel_framework
version: 0.0.0-dev.15
version: 0.0.0-dev.16
description: Core libraries for the Angel framework.
author: Tobe O <thosakwe@gmail.com>
homepage: https://github.com/angel-dart/angel_framework