var restpress = require( 'restpress' );
var monsterRoutes = new restpress( 'monsters' );
var monsterData = require( '../../app/models/monster' );

monsterRoutes.list( function( request, response ) {
	monsterData.find( function( err, monsters ) {
		if ( err ) response.send( err );
		response.json( monsters );
	} );
});

monsterRoutes.get( function( request, response ) {
	monsterData.findById( request.params.id, function( err, monster ) {
		if ( err ) response.send( err );
		response.json( monster );
	} );
});

monsterRoutes.create( function( request, response ) {
	if ( ! request.body.hasOwnProperty( 'name' ) ) {
		response.statusCode = 400;
		return response.send( 'Error: 400: Invalid data.' );
	}
	var monster = new monsterData();
	monster.name = request.body.name;
	if ( request.body.hasOwnProperty( 'description' ) ) monster.description = request.body.description;
	monster.save( function( err ) {
		if ( err ) response.send( err );
		response.json( monster );
	} );
});

monsterRoutes.update( function( request, response ) {
	monsterData.findById( request.params.id, function( err, monster ) {
		if ( err ) response.send( err );
		if ( request.body.hasOwnProperty( 'name' ) ) monster.name = request.body.name;
		if ( request.body.hasOwnProperty( 'description' ) ) monster.description = request.body.description;
		monster.save( function( err ) {
			if ( err ) response.send( err );
			response.json( monster );
		} );
	} );
});

module.exports = monsterRoutes;

@@ -1434,16 +1434,223 @@
 );%0A%7D);%0A%0A
+monsterRoutes.delete( function( request, response ) %7B%0A%09monsterData.remove( %7B%0A%09%09_id: request.params.id%0A%09%7D, function( err, monster ) %7B%0A%09%09if ( err ) response.send( err );%0A%09%09response.json( monster );%0A%09%7D );%0A%7D);%0A%0A
 module.e

Add DELETE method for monsters