Fix MapService.modify
This commit is contained in:
parent
1ba5ffd167
commit
106a5683dd
4 changed files with 29 additions and 2 deletions
|
@ -1,3 +1,6 @@
|
|||
# 2.0.0-rc.3
|
||||
* `MapService.modify` was not actually modifying items.
|
||||
|
||||
# 2.0.0-rc.2
|
||||
* Fixes Pub analyzer lints (see `angel_route@3.0.6`)
|
||||
|
||||
|
|
22
example/map_service.dart
Normal file
22
example/map_service.dart
Normal file
|
@ -0,0 +1,22 @@
|
|||
import 'package:angel_container/mirrors.dart';
|
||||
import 'package:angel_framework/angel_framework.dart';
|
||||
import 'package:angel_framework/http.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
|
||||
main() async {
|
||||
// Logging set up/boilerplate
|
||||
Logger.root.onRecord.listen(print);
|
||||
|
||||
// Create our server.
|
||||
var app = Angel(
|
||||
logger: Logger('angel'),
|
||||
reflector: MirrorsReflector(),
|
||||
);
|
||||
|
||||
// Create a RESTful service that manages an in-memory collection.
|
||||
app.use('/api/todos', MapService());
|
||||
|
||||
var http = AngelHttp(app);
|
||||
await http.startServer('127.0.0.1', 0);
|
||||
print('Listening at ${http.uri}');
|
||||
}
|
|
@ -102,13 +102,15 @@ class MapService extends Service<String, Map<String, dynamic>> {
|
|||
if (!items.any(_matchesId(id))) return create(data, params);
|
||||
|
||||
return read(id).then((item) {
|
||||
var idx = items.indexOf(item);
|
||||
if (idx < 0) return create(data, params);
|
||||
var result = new Map<String, dynamic>.from(item)..addAll(data);
|
||||
|
||||
if (autoIdAndDateFields == true)
|
||||
result
|
||||
..[autoSnakeCaseNames == false ? 'updatedAt' : 'updated_at'] =
|
||||
new DateTime.now().toIso8601String();
|
||||
return new Future.value(result);
|
||||
return new Future.value(items[idx] = result);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
name: angel_framework
|
||||
version: 2.0.0-rc.2
|
||||
version: 2.0.0-rc.3
|
||||
description: A high-powered HTTP server with dependency injection, routing and much more.
|
||||
author: Tobe O <thosakwe@gmail.com>
|
||||
homepage: https://github.com/angel-dart/angel_framework
|
||||
|
|
Loading…
Reference in a new issue