This commit is contained in:
thosakwe 2016-12-03 12:39:48 -05:00
parent fa7cc701bf
commit 84e63e8dc6
10 changed files with 33 additions and 8 deletions

View file

@ -1,6 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Generic Tests" type="DartTestRunConfigurationType" factoryName="Dart Test" singleton="true">
<option name="filePath" value="$PROJECT_DIR$/test/generic_tests.dart" />
<option name="filePath" value="$PROJECT_DIR$/test/generic_test.dart" />
<method />
</configuration>
</component>

View file

@ -1,6 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Typed Tests" type="DartTestRunConfigurationType" factoryName="Dart Test" singleton="true">
<option name="filePath" value="$PROJECT_DIR$/test/typed_tests.dart" />
<option name="filePath" value="$PROJECT_DIR$/test/typed_test.dart" />
<method />
</configuration>
</component>

1
.travis.yml Normal file
View file

@ -0,0 +1 @@
language: dart

View file

@ -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.

View file

@ -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<List> 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);
}
}

View file

@ -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<T> 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<T> extends Service {
}
}
void log(e, st, msg) {
if (debug) {
stderr.writeln('$msg ERROR: $e');
stderr.writeln(st);
}
}
@override
Future<List> index([Map params]) async {
return await (await collection.find(_makeQuery(params)))
@ -54,8 +62,7 @@ class MongoTypedService<T> 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<T> 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<T> extends Service {
}
return result;
} catch (e, st) {
log(e, st, 'UPDATE');
throw new AngelHttpException(e, stackTrace: st);
}
}
@ -129,6 +138,7 @@ class MongoTypedService<T> 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);
}
}

View file

@ -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;

View file

@ -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 <thosakwe@gmail.com>
homepage: https://github.com/angel-dart/angel_mongo