|
|
|
@ -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)
|
|
|
|
|