Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Postv2 #4

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
finish sprint 1.
  • Loading branch information
Monk Wellington authored and Monk Wellington committed Mar 4, 2016
commit f969ba6ee9400677519965f82f39e9d4cf1c7e71
11 changes: 11 additions & 0 deletions models/album.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
var mongoose = require("mongoose");
var Schema = mongoose.Schema;

var AlbumSchema = new Schema({
artistName: String,
name: String,
releaseDate: String,
genres: [ String ]
});

var Album = mongoose.model('Album', AlbumSchema);

module.exports = Album;
5 changes: 4 additions & 1 deletion models/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
var mongoose = require("mongoose");
mongoose.connect("mongodb://localhost/tunely");
mongoose.connect("mongodb://localhost/tunely_test");
var Album = require('./album');

module.exports.Album = Album;
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "An app for tracking your music collection",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon server.js"
},
"repository": {
"type": "git",
Expand All @@ -17,6 +18,7 @@
},
"homepage": "https://github.com/tgaff/tunely#readme",
"dependencies": {
"express": "^4.13.3"
"express": "^4.13.3",
"mongoose": "^4.2.9"
}
}
1 change: 0 additions & 1 deletion public/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@
vertical-align: baseline;
margin-right: 12px;
}

16 changes: 11 additions & 5 deletions public/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ sampleAlbums.push({

$(document).ready(function() {
console.log('app.js loaded!');
$.get('/api/albums').success(function (albums) {
albums.forEach(function(album) {
renderAlbum(album);
});

});
});


Expand All @@ -64,15 +70,15 @@ function renderAlbum(album) {
" <ul class='list-group'>" +
" <li class='list-group-item'>" +
" <h4 class='inline-header'>Album Name:</h4>" +
" <span class='album-name'>" + "HARDCODED ALBUM NAME" + "</span>" +
" <span class='album-name'>" + album.name + "</span>" +
" </li>" +
" <li class='list-group-item'>" +
" <h4 class='inline-header'>Artist Name:</h4>" +
" <span class='artist-name'>" + "HARDCODED ARTIST NAME" + "</span>" +
" <span class='artist-name'>" + album.artistName + "</span>" +
" </li>" +
" <li class='list-group-item'>" +
" <h4 class='inline-header'>Released date:</h4>" +
" <span class='album-releaseDate'>" + "HARDCODED RELEASE DATE" + "</span>" +
" <span class='album-name'>" + album.releaseDate + "</span>" +
" </li>" +
" </ul>" +
" </div>" +
Expand All @@ -88,5 +94,5 @@ function renderAlbum(album) {
" </div>" +
" <!-- end one album -->";

// render to the page with jQuery
}
$('#albums').prepend(albumHtml);
}
31 changes: 27 additions & 4 deletions seed.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,36 @@

var db = require("./models");

var albumsList =[
// put data here!
];
var albumList =[];
albumList.push({
artistName: 'Nine Inch Nails',
name: 'The Downward Spiral',
releaseDate: '1994, March 8',
genres: [ 'industrial', 'industrial metal' ]
});
albumList.push({
artistName: 'Metallica',
name: 'Metallica',
releaseDate: '1991, August 12',
genres: [ 'heavy metal' ]
});
albumList.push({
artistName: 'The Prodigy',
name: 'Music for the Jilted Generation',
releaseDate: '1994, July 4',
genres: [ 'electronica', 'breakbeat hardcore', 'rave', 'jungle' ]
});
albumList.push({
artistName: 'Johnny Cash',
name: 'Unchained',
releaseDate: '1996, November 5',
genres: [ 'country', 'rock' ]
});


db.Album.remove({}, function(err, albums){

db.Album.create(albumsList, function(err, albums){
db.Album.create(albumList, function(err, albums){
if (err) { return console.log('ERROR', err); }
console.log("all albums:", albums);
console.log("created", albums.length, "albums");
Expand Down
43 changes: 10 additions & 33 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,16 @@
var express = require('express');
// generate a new express app and call it 'app'
var app = express();

var mongoose = require('mongoose');
// serve static files from public folder
app.use(express.static(__dirname + '/public'));


/************
* DATABASE *
************/

/* hard-coded data */
var albums = [];
albums.push({
_id: 132,
artistName: 'Nine Inch Nails',
name: 'The Downward Spiral',
releaseDate: '1994, March 8',
genres: [ 'industrial', 'industrial metal' ]
});
albums.push({
_id: 133,
artistName: 'Metallica',
name: 'Metallica',
releaseDate: '1991, August 12',
genres: [ 'heavy metal' ]
});
albums.push({
_id: 134,
artistName: 'The Prodigy',
name: 'Music for the Jilted Generation',
releaseDate: '1994, July 4',
genres: [ 'electronica', 'breakbeat hardcore', 'rave', 'jungle' ]
});
albums.push({
_id: 135,
artistName: 'Johnny Cash',
name: 'Unchained',
releaseDate: '1996, November 5',
genres: [ 'country', 'rock' ]
});


var db = require('./models');

/**********
* ROUTES *
Expand Down Expand Up @@ -73,6 +43,13 @@ app.get('/api', function api_index (req, res){
});
});

app.get('/api/albums', function albumsIndex(req, res) {
db.Album.find({}, function(err, albums) {
res.json(albums);
});
});


/**********
* SERVER *
**********/
Expand Down
51 changes: 0 additions & 51 deletions views/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,57 +34,6 @@ <h2>Albums</h2>
<!-- albums! -->
<div id='albums'>




<!-- one album -->
<div class="row album">

<div class="col-md-10 col-md-offset-1">
<div class="panel panel-default">
<div class="panel-body">


<!-- begin album internal row -->
<div class='row'>
<div class="col-md-3 col-xs-12 thumbnail album-art">
<img src="http://placehold.it/800x800" alt="album image">
</div>

<div class="col-md-9 col-xs-12">
<ul class="list-group">
<li class="list-group-item">
<h4 class='inline-header'>Album Name:</h4>
<span class='album-name'>Ladyhawke</span>
</li>

<li class="list-group-item">
<h4 class='inline-header'>Artist Name:</h4>
<span class='artist-name'>Ladyhawke</span>
</li>

<li class="list-group-item">
<h4 class='inline-header'>Released date:</h4>
<span class='album-releaseDate'>2008, November 18</span>
</li>
</ul>
</div>

</div>
<!-- end of album internal row -->

<div class='panel-footer'>
</div>

</div>
</div>
</div>
</div>
<!-- end one album -->




</div>
</section>

Expand Down