service.create, etc

This commit is contained in:
regiostech 2016-05-03 21:01:29 -04:00
parent b373db1110
commit 315e0bca7a
2 changed files with 11 additions and 8 deletions

View file

@ -5,8 +5,11 @@ class MemoryService<T> extends Service {
God god = new God();
Map <int, T> items = {};
Map makeJson(int index, T t) {
makeJson(int index, T t) {
if (T == null || T == Map)
return mergeMap([god.serializeToMap(t), {'id': index}]);
else
return t;
}
Future<List> index([Map params]) async {
@ -16,7 +19,7 @@ class MemoryService<T> extends Service {
.toList();
}
Future<Object> read(id, [Map params]) async {
Future read(id, [Map params]) async {
int desiredId = int.parse(id.toString());
if (items.containsKey(desiredId)) {
T found = items[desiredId];
@ -26,7 +29,7 @@ class MemoryService<T> extends Service {
} else throw new AngelHttpException.NotFound();
}
Future<Object> create(data, [Map params]) async {
Future create(data, [Map params]) async {
try {
items[items.length] =
(data is Map) ? god.deserializeFromMap(data, T) : data;
@ -37,7 +40,7 @@ class MemoryService<T> extends Service {
}
}
Future<Object> modify(id, data, [Map params]) async {
Future modify(id, data, [Map params]) async {
int desiredId = int.parse(id.toString());
if (items.containsKey(desiredId)) {
try {
@ -52,7 +55,7 @@ class MemoryService<T> extends Service {
} else throw new AngelHttpException.NotFound();
}
Future<Object> update(id, data, [Map params]) async {
Future update(id, data, [Map params]) async {
int desiredId = int.parse(id.toString());
if (items.containsKey(desiredId)) {
try {
@ -65,7 +68,7 @@ class MemoryService<T> extends Service {
} else throw new AngelHttpException.NotFound();
}
Future<Object> remove(id, [Map params]) async {
Future remove(id, [Map params]) async {
int desiredId = int.parse(id.toString());
if (items.containsKey(desiredId)) {
T item = items[desiredId];

View file

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