service.create, etc
This commit is contained in:
parent
b373db1110
commit
315e0bca7a
2 changed files with 11 additions and 8 deletions
|
@ -5,8 +5,11 @@ class MemoryService<T> extends Service {
|
||||||
God god = new God();
|
God god = new God();
|
||||||
Map <int, T> items = {};
|
Map <int, T> items = {};
|
||||||
|
|
||||||
Map makeJson(int index, T t) {
|
makeJson(int index, T t) {
|
||||||
return mergeMap([god.serializeToMap(t), {'id': index}]);
|
if (T == null || T == Map)
|
||||||
|
return mergeMap([god.serializeToMap(t), {'id': index}]);
|
||||||
|
else
|
||||||
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List> index([Map params]) async {
|
Future<List> index([Map params]) async {
|
||||||
|
@ -16,7 +19,7 @@ class MemoryService<T> extends Service {
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Object> read(id, [Map params]) async {
|
Future read(id, [Map params]) async {
|
||||||
int desiredId = int.parse(id.toString());
|
int desiredId = int.parse(id.toString());
|
||||||
if (items.containsKey(desiredId)) {
|
if (items.containsKey(desiredId)) {
|
||||||
T found = items[desiredId];
|
T found = items[desiredId];
|
||||||
|
@ -26,7 +29,7 @@ class MemoryService<T> extends Service {
|
||||||
} else throw new AngelHttpException.NotFound();
|
} else throw new AngelHttpException.NotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Object> create(data, [Map params]) async {
|
Future create(data, [Map params]) async {
|
||||||
try {
|
try {
|
||||||
items[items.length] =
|
items[items.length] =
|
||||||
(data is Map) ? god.deserializeFromMap(data, T) : data;
|
(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());
|
int desiredId = int.parse(id.toString());
|
||||||
if (items.containsKey(desiredId)) {
|
if (items.containsKey(desiredId)) {
|
||||||
try {
|
try {
|
||||||
|
@ -52,7 +55,7 @@ class MemoryService<T> extends Service {
|
||||||
} else throw new AngelHttpException.NotFound();
|
} 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());
|
int desiredId = int.parse(id.toString());
|
||||||
if (items.containsKey(desiredId)) {
|
if (items.containsKey(desiredId)) {
|
||||||
try {
|
try {
|
||||||
|
@ -65,7 +68,7 @@ class MemoryService<T> extends Service {
|
||||||
} else throw new AngelHttpException.NotFound();
|
} else throw new AngelHttpException.NotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Object> remove(id, [Map params]) async {
|
Future remove(id, [Map params]) async {
|
||||||
int desiredId = int.parse(id.toString());
|
int desiredId = int.parse(id.toString());
|
||||||
if (items.containsKey(desiredId)) {
|
if (items.containsKey(desiredId)) {
|
||||||
T item = items[desiredId];
|
T item = items[desiredId];
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
name: angel_framework
|
name: angel_framework
|
||||||
version: 0.0.0-dev.16
|
version: 0.0.0-dev.17
|
||||||
description: Core libraries for the Angel framework.
|
description: Core libraries for the Angel framework.
|
||||||
author: Tobe O <thosakwe@gmail.com>
|
author: Tobe O <thosakwe@gmail.com>
|
||||||
homepage: https://github.com/angel-dart/angel_framework
|
homepage: https://github.com/angel-dart/angel_framework
|
||||||
|
|
Loading…
Reference in a new issue