This commit is contained in:
thosakwe 2017-04-09 22:28:29 -04:00
parent fbad320e83
commit dff4f228c0
4 changed files with 32 additions and 12 deletions

View file

@ -1,6 +1,6 @@
# angel_mongo
[![version 1.1.4](https://img.shields.io/badge/pub-1.1.4-brightgreen.svg)](https://pub.dartlang.org/packages/angel_mongo)
[![version 1.1.5](https://img.shields.io/badge/pub-1.1.5-brightgreen.svg)](https://pub.dartlang.org/packages/angel_mongo)
[![build status](https://travis-ci.org/angel-dart/mongo.svg?branch=master)](https://travis-ci.org/angel-dart/mongo)
MongoDB-enabled services for the Angel framework.

View file

@ -126,7 +126,17 @@ class MongoService extends Service {
@override
Future modify(id, data, [Map params]) async {
var target = await read(id, params);
var target;
try {
target = await read(id, params);
} on AngelHttpException catch (e) {
if (e.statusCode == HttpStatus.NOT_FOUND)
return await create(data, params);
else
rethrow;
}
Map result = mergeMap([
target is Map ? target : god.serializeObject(target),
_removeSensitive(data)
@ -146,7 +156,17 @@ class MongoService extends Service {
@override
Future update(id, data, [Map params]) async {
var target = await read(id, params);
var target;
try {
target = await read(id, params);
} on AngelHttpException catch (e) {
if (e.statusCode == HttpStatus.NOT_FOUND)
return await create(data, params);
else
rethrow;
}
Map result = _removeSensitive(data);
result['_id'] = _makeId(id);
result['createdAt'] =

View file

@ -1,5 +1,5 @@
name: angel_mongo
version: 1.1.4
version: 1.1.5
description: MongoDB-enabled services for the Angel framework.
author: Tobe O <thosakwe@gmail.com>
homepage: https://github.com/angel-dart/angel_mongo

View file

@ -73,10 +73,10 @@ main() {
test('insert items', () async {
var response = await client.post("$url/api",
body: god.serialize(testGreeting), headers: headers);
expect(response.statusCode, equals(HttpStatus.OK));
expect(response.statusCode, isIn([200, 201]));
response = await client.get("$url/api");
expect(response.statusCode, 200);
expect(response.statusCode, isIn([200, 201]));
List<Map> users = god.deserialize(response.body);
expect(users.length, equals(1));
});
@ -84,11 +84,11 @@ main() {
test('read item', () async {
var response = await client.post("$url/api",
body: god.serialize(testGreeting), headers: headers);
expect(response.statusCode, equals(HttpStatus.OK));
expect(response.statusCode, isIn([200, 201]));
Map created = god.deserialize(response.body);
response = await client.get("$url/api/${created['id']}");
expect(response.statusCode, equals(HttpStatus.OK));
expect(response.statusCode, isIn([200, 201]));
Map read = god.deserialize(response.body);
expect(read['id'], equals(created['id']));
expect(read['to'], equals('world'));
@ -98,13 +98,13 @@ main() {
test('modify item', () async {
var response = await client.post("$url/api",
body: god.serialize(testGreeting), headers: headers);
expect(response.statusCode, equals(HttpStatus.OK));
expect(response.statusCode, isIn([200, 201]));
Map created = god.deserialize(response.body);
response = await client.patch("$url/api/${created['id']}",
body: god.serialize({"to": "Mom"}), headers: headers);
Map modified = god.deserialize(response.body);
expect(response.statusCode, equals(HttpStatus.OK));
expect(response.statusCode, isIn([200, 201]));
expect(modified['id'], equals(created['id']));
expect(modified['to'], equals('Mom'));
expect(modified['updatedAt'], isNot(null));
@ -113,13 +113,13 @@ main() {
test('update item', () async {
var response = await client.post("$url/api",
body: god.serialize(testGreeting), headers: headers);
expect(response.statusCode, equals(HttpStatus.OK));
expect(response.statusCode, isIn([200, 201]));
Map created = god.deserialize(response.body);
response = await client.post("$url/api/${created['id']}",
body: god.serialize({"to": "Updated"}), headers: headers);
Map modified = god.deserialize(response.body);
expect(response.statusCode, equals(HttpStatus.OK));
expect(response.statusCode, isIn([200, 201]));
expect(modified['id'], equals(created['id']));
expect(modified['to'], equals('Updated'));
expect(modified['updatedAt'], isNot(null));