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 + "


"); + }); + } +}); diff --git a/seed.js b/seed.js index 1943f8f..e963387 100644 --- a/seed.js +++ b/seed.js @@ -3,8 +3,33 @@ var db = require("./models"); +var Album = require("./models/album.js"); + var albumsList =[ - // put data here! + { + artistName: 'Nine Inch Nails', + name: 'The Downward Spiral', + releaseDate: '1994, March 8', + genres: [ 'industrial', 'industrial metal' ] + }, + { + artistName: 'Metallica', + name: 'Metallica', + releaseDate: '1991, August 12', + genres: [ 'heavy metal' ] + }, + { + artistName: 'The Prodigy', + name: 'Music for the Jilted Generation', + releaseDate: '1994, July 4', + genres: [ 'electronica', 'breakbeat hardcore', 'rave', 'jungle' ] + }, + { + artistName: 'Johnny Cash', + name: 'Unchained', + releaseDate: '1996, November 5', + genres: [ 'country', 'rock' ] + } ]; db.Album.remove({}, function(err, albums){ diff --git a/server.js b/server.js index 5da137b..6d829ea 100644 --- a/server.js +++ b/server.js @@ -57,6 +57,10 @@ app.get('/', function homepage (req, res) { res.sendFile(__dirname + '/views/index.html'); }); +app.get('/api/albums', function albums_api (req, res){ + res.json({albums: albums}); +}); + /* * JSON API Endpoints diff --git a/views/index.html b/views/index.html index 5cb6501..4a831db 100644 --- a/views/index.html +++ b/views/index.html @@ -34,57 +34,6 @@

Albums

- - - - -
- -
-
-
- - - -
-
- album image -
- -
-
    -
  • -

    Album Name:

    - Ladyhawke -
  • - -
  • -

    Artist Name:

    - Ladyhawke -
  • - -
  • -

    Released date:

    - 2008, November 18 -
  • -
-
- -
- - - - -
-
-
-
- - - - -