import {listArtists, listAlbums, listAlbumsByArtist,
        listSongs, listSongsByAlbum, } from '../queries/list-tracks';

export const getLibrary = {
    url: '/library',
    generateHandler: function(tracks) {
        return function(req, res) {
            res.send(JSON.stringify(tracks));
        };
    }
}

export const getArtists = {
    url: '/artists',
    generateHandler: function(db) {
        return function(req, res) {
            listArtists(db).then(results => {
                res.send(JSON.stringify(results));
            });
        };
    }
}

export const getAlbums = {
    url: '/albums',
    generateHandler: function(db) {
        return function(req, res) {
            if (req.param.artist) {
                listAlbumsByArtist(db, req.param.artist).then(results => {
                    res.send(JSON.stringify(results));
                });
            } else {
                listAlbums(db).then(results => {
                    res.send(JSON.stringify(results));
                });
            }
        };
    }
}

export const getSongs = {
    url: '/songs',
    generateHandler: function(db) {
        return function(req, res) {
            if (req.param.album) {
                listSongsByAlbum(db, req.param.album).then(results => {
                    res.send(JSON.stringify(results));
                });
            } else if (req.param.artist) {
                listSongsByArtist(db, req.param.artist).then(results => {
                    res.send(JSON.stringify(results));
                });
            } else {
                listSongs(db).then(results => {
                    res.send(JSON.stringify(results));
                });
            }
        }
    }
}

@@ -693,37 +693,37 @@
         if (req.
-param
+query
 .artist) %7B%0A     
@@ -752,37 +752,37 @@
 yArtist(db, req.
-param
+query
 .artist).then(re
@@ -1179,29 +1179,29 @@
     if (req.
-param
+query
 .album) %7B%0A  
@@ -1239,21 +1239,21 @@
 db, req.
-param
+query
 .album).
@@ -1368,29 +1368,29 @@
 lse if (req.
-param
+query
 .artist) %7B%0A 
@@ -1434,13 +1434,13 @@
 req.
-param
+query
 .art

Fix library routes