Created get all topics endpoint and fixed topics POST

pull/1/head
Nishant Arora 9 years ago
parent 701378beb7
commit 083ec9676f

@ -11,6 +11,7 @@ then move it to the topics endpoints file.
// Importing the articles model
var Articles = require('../models/article.js');
var db = require('../db.js'); //this file contains the knex file import. it's equal to knex=require('knex')
module.exports = function(app){

@ -8,6 +8,8 @@ comment in the articles.js (same directory).
// Importing the topics model
var Topics = require('../models/topic.js');
var db = require('../db.js'); //this file contains the knex file import. it's equal to knex=require('knex')
module.exports = function(app) {
@ -22,6 +24,23 @@ module.exports = function(app) {
});
app.get('/api/topics',function(req,res){
/*
This is a GET endpoint that responds with the list of all the topics in the topics table
the topics are present in the data object in the returning object.
the error key in the returning object is a boolen which is false if there is no error and true otherwise
*/
Topics.forge()
.fetchAll()
.then(function (collection) {
res.json({error: false, data: collection.toJSON()});
})
.catch(function (err) {
res.status(500).json({error: true, data: {message: err.message}});
});
});
app.get('/api/topic/:id/articles',function(req,res){
/*
This is a GET endpoint that responds with the list of all the articles that belong to a particular topic (topic of given id param)

Binary file not shown.
Loading…
Cancel
Save