From 106a5683dd165d12e381b832afdc7a9720d33ed6 Mon Sep 17 00:00:00 2001 From: Tobe O Date: Thu, 11 Apr 2019 13:44:09 -0400 Subject: [PATCH] Fix MapService.modify --- CHANGELOG.md | 3 +++ example/map_service.dart | 22 ++++++++++++++++++++++ lib/src/core/map_service.dart | 4 +++- pubspec.yaml | 2 +- 4 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 example/map_service.dart diff --git a/CHANGELOG.md b/CHANGELOG.md index 2cb68f3d..ad7599d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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`) diff --git a/example/map_service.dart b/example/map_service.dart new file mode 100644 index 00000000..4650dd09 --- /dev/null +++ b/example/map_service.dart @@ -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}'); +} diff --git a/lib/src/core/map_service.dart b/lib/src/core/map_service.dart index 511ce780..c7d64d8a 100644 --- a/lib/src/core/map_service.dart +++ b/lib/src/core/map_service.dart @@ -102,13 +102,15 @@ class MapService extends Service> { 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.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); }); } diff --git a/pubspec.yaml b/pubspec.yaml index df1bf31f..c655f684 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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 homepage: https://github.com/angel-dart/angel_framework