diff --git a/.idea/runConfigurations/Generic_Tests.xml b/.idea/runConfigurations/Generic_Tests.xml index afb55d6f..034d37e1 100644 --- a/.idea/runConfigurations/Generic_Tests.xml +++ b/.idea/runConfigurations/Generic_Tests.xml @@ -1,6 +1,6 @@ - \ No newline at end of file diff --git a/.idea/runConfigurations/Typed_Tests.xml b/.idea/runConfigurations/Typed_Tests.xml index ea002d9b..0f5d6a48 100644 --- a/.idea/runConfigurations/Typed_Tests.xml +++ b/.idea/runConfigurations/Typed_Tests.xml @@ -1,6 +1,6 @@ - \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..de2210c9 --- /dev/null +++ b/.travis.yml @@ -0,0 +1 @@ +language: dart \ No newline at end of file diff --git a/README.md b/README.md index eb3b6faa..57ab7239 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # angel_mongo -![version 1.0.0-dev](https://img.shields.io/badge/version-1.0.0--dev-red.svg) +![version 1.0.0-dev+4](https://img.shields.io/badge/version-1.0.0--dev+4-red.svg) +![build status](https://travis-ci.org/angel-dart/mongo.svg?branch=master) MongoDB-enabled services for the Angel framework. diff --git a/lib/mongo_service.dart b/lib/mongo_service.dart index b2d35308..bfc7ffaa 100644 --- a/lib/mongo_service.dart +++ b/lib/mongo_service.dart @@ -3,8 +3,9 @@ part of angel_mongo.services; /// Manipulates data from MongoDB as Maps. class MongoService extends Service { DbCollection collection; + bool debug; - MongoService(DbCollection this.collection) : super(); + MongoService(DbCollection this.collection, {this.debug: true}) : super(); _jsonify(Map doc, [Map params]) { Map result = {}; @@ -18,6 +19,13 @@ class MongoService extends Service { return _transformId(result); } + void log(e, st, msg) { + if (debug) { + stderr.writeln('$msg ERROR: $e'); + stderr.writeln(st); + } + } + @override Future index([Map params]) async { return await (await collection.find(_makeQuery(params))) @@ -35,6 +43,7 @@ class MongoService extends Service { await collection.insert(item); return await _lastItem(collection, _jsonify, params); } catch (e, st) { + log(e, st, 'CREATE'); throw new AngelHttpException(e, stackTrace: st); } } @@ -64,6 +73,7 @@ class MongoService extends Service { result['id'] = id; return result; } catch (e, st) { + log(e, st, 'MODIFY'); throw new AngelHttpException(e, stackTrace: st); } } @@ -82,6 +92,7 @@ class MongoService extends Service { result['id'] = id; return result; } catch (e, st) { + log(e, st); throw new AngelHttpException(e, stackTrace: st); } } @@ -94,6 +105,7 @@ class MongoService extends Service { await collection.remove(where.id(_makeId(id)).and(_makeQuery(params))); return result; } catch (e, st) { + log(e, st, 'REMOVE'); throw new AngelHttpException(e, stackTrace: st); } } diff --git a/lib/mongo_service_typed.dart b/lib/mongo_service_typed.dart index 736d3f17..ecb02229 100644 --- a/lib/mongo_service_typed.dart +++ b/lib/mongo_service_typed.dart @@ -3,8 +3,9 @@ part of angel_mongo.services; /// Manipulates data from MongoDB by serializing BSON from and deserializing BSON to a target class. class MongoTypedService extends Service { DbCollection collection; + bool debug; - MongoTypedService(DbCollection this.collection) : super() { + MongoTypedService(DbCollection this.collection, {this.debug: true}) : super() { if (!reflectType(T).isAssignableTo(reflectType(Model))) throw new Exception( "If you specify a type for MongoService, it must be dynamic, Map, or extend from Model."); @@ -33,6 +34,13 @@ class MongoTypedService extends Service { } } + void log(e, st, msg) { + if (debug) { + stderr.writeln('$msg ERROR: $e'); + stderr.writeln(st); + } + } + @override Future index([Map params]) async { return await (await collection.find(_makeQuery(params))) @@ -54,8 +62,7 @@ class MongoTypedService extends Service { await collection.insert(item); return await _lastItem(collection, _jsonify, params); } catch (e, st) { - print(e); - print(st); + log(e, st, 'CREATE'); throw new AngelHttpException.BadRequest(); } } @@ -93,6 +100,7 @@ class MongoTypedService extends Service { await collection.update(where.id(_id), result); return await read(_id, params); } catch (e, st) { + log(e, st, 'MODIFY'); throw new AngelHttpException(e, stackTrace: st); } } @@ -117,6 +125,7 @@ class MongoTypedService extends Service { } return result; } catch (e, st) { + log(e, st, 'UPDATE'); throw new AngelHttpException(e, stackTrace: st); } } @@ -129,6 +138,7 @@ class MongoTypedService extends Service { await collection.remove(where.id(_makeId(id)).and(_makeQuery(params))); return result; } catch (e, st) { + log(e, st, 'REMOVE'); throw new AngelHttpException(e, stackTrace: st); } } diff --git a/lib/services.dart b/lib/services.dart index 0b2f3cc5..fb70688f 100644 --- a/lib/services.dart +++ b/lib/services.dart @@ -1,6 +1,7 @@ library angel_mongo.services; import 'dart:async'; +import 'dart:io'; import 'dart:mirrors'; import 'package:angel_framework/angel_framework.dart'; import 'package:json_god/json_god.dart' as god; diff --git a/pubspec.yaml b/pubspec.yaml index a7d63b20..9ef7f0b7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: angel_mongo -version: 1.0.0-dev+3 +version: 1.0.0-dev+4 description: MongoDB-enabled services for the Angel framework. author: Tobe O homepage: https://github.com/angel-dart/angel_mongo diff --git a/test/generic_tests.dart b/test/generic_test.dart similarity index 100% rename from test/generic_tests.dart rename to test/generic_test.dart diff --git a/test/typed_tests.dart b/test/typed_test.dart similarity index 100% rename from test/typed_tests.dart rename to test/typed_test.dart