diff --git a/models/album.js b/models/album.js index 0411a57..6a1156f 100644 --- a/models/album.js +++ b/models/album.js @@ -1,2 +1,12 @@ var mongoose = require("mongoose"); var Schema = mongoose.Schema; + +var AlbumSchema = new mongoose.Schema({ + artistName: String, + name: String, + releaseDate: String, + genre: [ String ] +}); + +var Album = mongoose.model('Album', AlbumSchema); +module.exports = Album; \ No newline at end of file diff --git a/models/index.js b/models/index.js index 6c10401..d445c3c 100644 --- a/models/index.js +++ b/models/index.js @@ -1,2 +1,4 @@ var mongoose = require("mongoose"); mongoose.connect("mongodb://localhost/tunely"); + +module.exports.album = require("./album.js"); \ No newline at end of file diff --git a/package.json b/package.json index 0d3e4f8..d80d9ef 100644 --- a/package.json +++ b/package.json @@ -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": "node server.js" }, "repository": { "type": "git", @@ -18,5 +19,8 @@ "homepage": "https://github.com/tgaff/tunely#readme", "dependencies": { "express": "^4.13.3" + }, + "directories": { + "doc": "docs" } } diff --git a/public/js/app.js b/public/js/app.js index 164eb55..b3ca440 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -5,7 +5,6 @@ * */ - /* hard-coded data! */ var sampleAlbums = []; sampleAlbums.push({ @@ -34,20 +33,15 @@ sampleAlbums.push({ }); /* end of hard-coded data */ - - - $(document).ready(function() { console.log('app.js loaded!'); + renderAlbum(sampleAlbums[0]); }); - - - - // this function takes a single album and renders it to the page function renderAlbum(album) { console.log('rendering album:', album); + var albumHtml = " " + @@ -89,4 +83,22 @@ function renderAlbum(album) { " "; // render to the page with jQuery + sampleAlbums.forEach(function (element) { + $('#albums').append(albumHtml); + }); } + +//Step 2 + +$.ajax({ + method: 'GET', + url: '/api/albums', + success: function show_albums (data) { + sampleAlbums.forEach(function (element){ + $("#albums").append("
" + "Artist Name: " + element.artistName + "
" ); + $("#albums").append("" + "Name: " + element.name + "
"); + $("#albums").append("" + "Release Date: " + element.releaseDate + "
"); + $("#albums").append("" + "Genres: " + element.genres + "