Change/add endpoints

pull/7/head
Sander Vocke 5 years ago
parent 04c7e78baf
commit 483c0791ec
  1. 29
      server/server.js

@ -22,22 +22,41 @@ app.post('/api/world', (req, res) => {
});
app.post('/song/create', (req, res) => {
// TODO error handling
console.log('Create song: ' + req.body.title)
const song = models.Song.build({ title: req.body.title });
console.log(song.title);
console.log('Create song: ' + JSON.stringify(req.body))
include = [];
if ("Artist" in req.body) {
include.push(models.Artist);
}
const song = models.Song.build(req.body, { include: include });
song.save();
res.sendStatus(200);
});
app.get('/song/list', (req, res) => {
console.log("List songs");
models.Song.findAll()
models.Song.findAll({
include: [models.Artist]
})
.then(songs => {
res.send(songs);
});
});
app.post('/artist/create', (req, res) => {
console.log('Create artist: ' + req.body.name)
const artist = models.Artist.build(req.body);
artist.save();
res.sendStatus(200);
});
app.get('/artist/list', (req, res) => {
console.log("List artists");
models.Artist.findAll()
.then(artists => {
res.send(artists);
});
});
models.sequelize.sync().then(() => {
app.listen(port, () => console.log(`Listening on port ${port}`));
})
Loading…
Cancel
Save