Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions jack_sneed/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
db/
build/
29 changes: 1 addition & 28 deletions jack_sneed/README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1 @@
Mongo Backed REST API
==========================
To complete this assignment:
* fork this repository (the sub module for this specific assignment)
* clone down your fork
* place all of your work in a folder that is your full name, use `_`s instead of spaces
* push back up to your fork
* create a pull request back to the original repo
* submit a link to the PR in canvas

Assignment Description
--------------------------
Create a single resource rest API with Express that's backed by Mongo.

I'm leaving this pretty open to interpretation. I want you to write this from scratch, don't just copy and paste code from class or previous projects.

Add a feature of Mongoose that we didn't use class, such as data validation.

Also, implement a non CRUD resource (meaning that it doesn't use the full GET/POST/PUT/PATCH/DELETE interface).



Rubric

* Use of Express: 3pts
* Use of Mongo: 3pts
* Tests: 2pts
* Project Organization: 2pts
NINJA PARTY BATTLE
70 changes: 70 additions & 0 deletions jack_sneed/app/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Ninja Battle</title>
<link href='https://fonts.googleapis.com/css?family=Play' rel='stylesheet' type='text/css'>
<link href='application.css'rel='stylesheet' type='text/css'>
</head>
<body data-ng-app="NinjaApp">
<h1>Ninja Battle</h1>
<main data-ng-controller="NinjasController" data-ng-init="getAll()">
<ul id="errorslist">
<li data-ng-repeat="error in errors">{{error}}</li>
</ul>

<form name="newNinjaForm" data-ng-submit="create(newNinja)">
<h2>New Ninja:</h2>

<label for="newNinjaName">Name:</label>
<input type="text" id="newNinjaName" required data-ng-model="newNinja.name">

<label for="newNinjaSuperPower">Super Power: </label>
<input type="text" id="newNinjaSuperPower" data-ng-model="newNinja.superPower" placeholder="invisibility">

<label for="newNinjaWeapon">Weapon: </label>
<input type="text" id="newNinjaWeapon" data-ng-model="newNinja.weapon" placeholder="brass knuckles">

<label for="newNinjaFood">Food:</label>
<input type="text" id="newNinjaFood" data-ng-model="newNinja.food" placeholder="will power">

<label for="newNinjaCountry">Country: </label>
<input type="text" id="newNinjaCountry" data-ng-model="newNinja.country" placeholder="Ninjland">

<button type="submit" data-ng-disabled="newNinjaForm.$invalid">Create New Ninja</button>
</form>

<ul class="flex-container" id="ninjalist">
<li class="flex-item" data-ng-repeat="ninja in ninjas">
{{ninja.name}}
<form name="ninjaForm{{ninja._id}}" data-ng-submit="update(ninja)" data-ng-if="ninja.editing">
<h2>Update {{ninja.name}}</h2>

<label for="ninja{{ninja._id}}">Name:</label>
<input type="text" id="ninja{{ninja._id}}" required data-ng-model="ninja.name">

<label for="ninja{{ninja._id}}">Weapon:</label>
<input type="text" id="ninja{{ninja._id}}" data-ng-model="ninja.weapon" placeholder="invisibility">

<label for="ninja{{ninja._id}}">Super Power: </label>
<input type="text" id="ninja{{ninja._id}}" data-ng-model="ninja.superPower" placeholder="brass knuckles">

<label for="ninja{{ninja._id}}">Food:</label>
<input type="text" id="ninja{{ninja._id}}" data-ng-model="ninja.food" placeholder="will power">

<label for="ninja{{ninja._id}}">Country:</label>
<input type="text" id="ninja{{ninja._id}}" data-ng-model="ninja.country" placeholder="Ninjland">

<button type="submit">Save</button>
<button data-ng-click="ninja.editing = false">Cancel</button>
</form>
<br><br>
<button data-ng-if="!ninja.editing" data-ng-click="ninja.editing = true">Update Ninja</button>

<button data-ng-if="!ninja.editing" data-ng-click="remove(ninja)">Delete</button>
</li>
</ul>
</main>
<script src="/bundle.js"></script>
</body>
</html>
5 changes: 5 additions & 0 deletions jack_sneed/app/js/entry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require('angular/angular');
var angular = window.angular;

var ninjaApp = angular.module('NinjaApp', []);
require('./ninjas/ninjas')(ninjaApp);
5 changes: 5 additions & 0 deletions jack_sneed/app/js/entry.js~
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require('angular/angular');
var angular = window.angular;

var ninjaApp = angular.module('NinjaApp', []);
require('./ninjas/ninjas')(ninjaApp);
3 changes: 3 additions & 0 deletions jack_sneed/app/js/ninjas/controllers/ninja_controllers.js~
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function(app) {
require('./controllers/ninja_controller')(app);
};
59 changes: 59 additions & 0 deletions jack_sneed/app/js/ninjas/controllers/ninjas_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
module.exports = function(app) {
app.controller('NinjasController', ['$scope', '$http', function($scope, $http) {
$scope.ninjas = [];
$scope.errors = [];
$scope.newNinja = null;

$scope.getAll = function() {
$http.get('/api/ninja')
.then(function(res) {
$scope.ninjas = res.data;
}, function(err) {
console.log(err.data);
});
};

$scope.create = function(ninja) {
$http.post('/api/ninja', ninja)
.then(function(res) {
$scope.ninjas.push(res.data);
$scope.newNinja = null;
}, function(err) {
console.log(err.data)
});
};

$scope.update = function(ninja) {
ninja.editing = false;
$http.put('/api/ninja/' + ninja._id, ninja)
.then(function(res) {
console.log('this ninja has a been modified');
}, function(err) {
$scope.errors.push('could not get ninja: ' + ninja.name + ' to dojo');
console.log(err.data);
});
};

$scope.remove = function(ninja) {
$scope.ninjas.splice($scope.ninjas.indexOf(ninja), 1);
$http.delete('/api/ninja/' + ninja._id)
.then(function(res) {
console.log('ninja deleted');
}, function(err) {
console.log(err.data);
$scope.errors.push('could not delete ninja: ' + ninja.name);
$scope.getAll();
});
};

$scope.edit = function(ninja) {
$scope.orig = angular.copy(ninja);
ninja.editing = true;
};

$scope.cancelEdit = function(ninja) {
angular.copy($scope.orig, ninja);
ninja.editing = false;
};
}]);
};
49 changes: 49 additions & 0 deletions jack_sneed/app/js/ninjas/controllers/ninjas_controller.js~
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
module.exports = function(app) {
app.controller('NinjasController', ['$scope', '$http', function($scope, $http) {
$scope.ninjas = [];
$scope.errors = [];
$scope.newNinja = null;

$scope.getAll = function() {
$http.get('/api/ninja')
.then(function(res) {
$scope.ninjas = res.data;
}, function(err) {
console.log(err.data);
});
};

$scope.create = function(ninja) {
$http.post('/api/ninja', ninja)
.then(function(res) {
$scope.ninjas.push(res.data);
$scope.newNinja = null;
}, function(err) {
console.log(err.data)
});
};

$scope.update = function(ninja) {
ninja.editing = false;
$http.put('/api/ninja/' + ninja._id, ninja)
.then(function(res) {
console.log('this ninja has a been modified');
}, function(err) {
$scope.errors.push('could not get ninja: ' + ninja.name + ' to dojo');
console.log(err.data);
});
};

$scope.remove = function(ninja) {
$scope.ninjas.splice($scope.ninjas.indexOf(ninja), 1);
$http.delete('/api/ninja/' + ninja._id)
.then(function(res) {
console.log('ninja deleted');
}, function(err) {
console.log(err.data);
$scope.errors.push('could not delete ninja: ' + ninja.name);
$scope.getAll();
});
};
}]);
};
49 changes: 49 additions & 0 deletions jack_sneed/app/js/ninjas/controllers/ninjas_controllers.js~
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
module.exports = function(app) {
app.controller('NinjasController', ['$scope', '$http', function($scope, $http) {
$scope.ninjas = [];
$scope.errors = [];
$scope.newNinja = null;

$scope.getAll = function() {
$http.get('/api/ninjas')
.then(function(res) {
$scope.ninjas = res.data;
}, function(err) {
console.log(err.data);
});
};

$scope.create = function(ninja) {
$http.post('/api/ninjas', ninja)
.then(function(res) {
$scope.ninjas.push(res.data);
$scope.newNinja = null;
}, function(err) {
console.log(err.data)
});
};

$scope.update = function(ninja) {
ninja.editing = false;
$http.put('/api/ninjas/' + ninja._id, ninja)
.then(function(res) {
console.log('this ninja has a been modified');
}, function(err) {
$scope.errors.push('could not get ninja: ' + ninja.name + ' to dojo');
console.log(err.data);
});
};

$scope.remove = function(ninja) {
$scope.ninjas.splice($scope.ninjas.indexOf(ninja), 1);
$http.delete('/api/ninjas/' + ninja._id)
.then(function(res) {
console.log('ninja deleted');
}, function(err) {
console.log(err.data);
$scope.errors.push('could not delete ninja: ' + ninja.name);
$scope.getAll();
});
};
}]);
};
3 changes: 3 additions & 0 deletions jack_sneed/app/js/ninjas/ninjas.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function(app) {
require('./controllers/ninjas_controller')(app);
};
3 changes: 3 additions & 0 deletions jack_sneed/app/js/ninjas/ninjas.js~
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function(app) {
require('./controllers/ninja_controller')(app);
};
5 changes: 5 additions & 0 deletions jack_sneed/app/sass/_base.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
body {
font-family: 'Play', sans-serif;
color: white;
background-color: black;
}
16 changes: 16 additions & 0 deletions jack_sneed/app/sass/_layout.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.flex-container {
display: flex;
justify-content: space-between;
flex-direction: column;
align-content: center;
}

.flex-item {
padding: 1em;
order: 1;
}

form {
display: flex;
flex-direction: column;
}
13 changes: 13 additions & 0 deletions jack_sneed/app/sass/_module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
$border-radius: .4em;

button {
@if $border-radius > 0 {
border-radius: $border-radius;
}
background-color: #FFF21D;
color: black;
}

input {
color: black;
}
Loading