Fixed more bugs with hooked services
This commit is contained in:
parent
d3b486b283
commit
1899e586f1
4 changed files with 68 additions and 15 deletions
|
@ -195,7 +195,7 @@ class Angel extends Routable {
|
|||
if (routable is Service) {
|
||||
routable.app = this;
|
||||
}
|
||||
super.use(path, routable,
|
||||
return super.use(path, routable,
|
||||
hooked: hooked, middlewareNamespace: middlewareNamespace);
|
||||
}
|
||||
|
||||
|
|
|
@ -6,31 +6,84 @@ class HookedService extends Service {
|
|||
final Service inner;
|
||||
|
||||
HookedServiceEventDispatcher beforeIndexed =
|
||||
new HookedServiceEventDispatcher();
|
||||
new HookedServiceEventDispatcher();
|
||||
HookedServiceEventDispatcher beforeRead = new HookedServiceEventDispatcher();
|
||||
HookedServiceEventDispatcher beforeCreated =
|
||||
new HookedServiceEventDispatcher();
|
||||
new HookedServiceEventDispatcher();
|
||||
HookedServiceEventDispatcher beforeModified =
|
||||
new HookedServiceEventDispatcher();
|
||||
new HookedServiceEventDispatcher();
|
||||
HookedServiceEventDispatcher beforeUpdated =
|
||||
new HookedServiceEventDispatcher();
|
||||
new HookedServiceEventDispatcher();
|
||||
HookedServiceEventDispatcher beforeRemoved =
|
||||
new HookedServiceEventDispatcher();
|
||||
new HookedServiceEventDispatcher();
|
||||
HookedServiceEventDispatcher afterIndexed =
|
||||
new HookedServiceEventDispatcher();
|
||||
new HookedServiceEventDispatcher();
|
||||
HookedServiceEventDispatcher afterRead = new HookedServiceEventDispatcher();
|
||||
HookedServiceEventDispatcher afterCreated =
|
||||
new HookedServiceEventDispatcher();
|
||||
new HookedServiceEventDispatcher();
|
||||
HookedServiceEventDispatcher afterModified =
|
||||
new HookedServiceEventDispatcher();
|
||||
new HookedServiceEventDispatcher();
|
||||
HookedServiceEventDispatcher afterUpdated =
|
||||
new HookedServiceEventDispatcher();
|
||||
new HookedServiceEventDispatcher();
|
||||
HookedServiceEventDispatcher afterRemoved =
|
||||
new HookedServiceEventDispatcher();
|
||||
new HookedServiceEventDispatcher();
|
||||
|
||||
HookedService(Service this.inner) {
|
||||
// Clone all routes, including middleware
|
||||
routes..clear()..addAll(inner.routes);
|
||||
// Clone app instance
|
||||
if (inner.app != null)
|
||||
this.app = inner.app;
|
||||
|
||||
routes.clear();
|
||||
// Set up our routes. We still need to copy middleware from inner service
|
||||
Map restProvider = {'provider': Providers.REST};
|
||||
|
||||
// Add global middleware if declared on the instance itself
|
||||
Middleware before = _getAnnotation(inner, Middleware);
|
||||
if (before != null) {
|
||||
routes.add(new Route("*", "*", before.handlers));
|
||||
}
|
||||
|
||||
Middleware indexMiddleware = _getAnnotation(inner.index, Middleware);
|
||||
get('/', (req, res) async {
|
||||
return await this.index(mergeMap([req.query, restProvider]));
|
||||
}, middleware: (indexMiddleware == null) ? [] : indexMiddleware.handlers);
|
||||
|
||||
Middleware createMiddleware = _getAnnotation(inner.create, Middleware);
|
||||
post('/', (req, res) async => await this.create(req.body, restProvider),
|
||||
middleware:
|
||||
(createMiddleware == null) ? [] : createMiddleware.handlers);
|
||||
|
||||
Middleware readMiddleware = _getAnnotation(inner.read, Middleware);
|
||||
|
||||
get(
|
||||
'/:id',
|
||||
(req, res) async => await this
|
||||
.read(req.params['id'], mergeMap([req.query, restProvider])),
|
||||
middleware: (readMiddleware == null) ? [] : readMiddleware.handlers);
|
||||
|
||||
Middleware modifyMiddleware = _getAnnotation(inner.modify, Middleware);
|
||||
patch(
|
||||
'/:id',
|
||||
(req, res) async =>
|
||||
await this.modify(req.params['id'], req.body, restProvider),
|
||||
middleware:
|
||||
(modifyMiddleware == null) ? [] : modifyMiddleware.handlers);
|
||||
|
||||
Middleware updateMiddleware = _getAnnotation(inner.update, Middleware);
|
||||
post(
|
||||
'/:id',
|
||||
(req, res) async =>
|
||||
await this.update(req.params['id'], req.body, restProvider),
|
||||
middleware:
|
||||
(updateMiddleware == null) ? [] : updateMiddleware.handlers);
|
||||
|
||||
Middleware removeMiddleware = _getAnnotation(inner.remove, Middleware);
|
||||
delete(
|
||||
'/:id',
|
||||
(req, res) async => await this
|
||||
.remove(req.params['id'], mergeMap([req.query, restProvider])),
|
||||
middleware:
|
||||
(removeMiddleware == null) ? [] : removeMiddleware.handlers);
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -30,9 +30,7 @@ class MemoryService<T> extends Service {
|
|||
|
||||
Future create(data, [Map params]) async {
|
||||
//try {
|
||||
print("Data: $data");
|
||||
var created = (data is Map) ? god.deserializeDatum(data, outputType: T) : data;
|
||||
print("Created $created");
|
||||
items[items.length] = created;
|
||||
return _makeJson(items.length - 1, created);
|
||||
/*} catch (e) {
|
||||
|
|
|
@ -6,6 +6,8 @@ import 'package:test/test.dart';
|
|||
class Todo {
|
||||
String text;
|
||||
String over;
|
||||
|
||||
Todo({String this.text, String this.over});
|
||||
}
|
||||
|
||||
main() {
|
||||
|
|
Loading…
Reference in a new issue