diff --git a/api/articles.js b/api/articles.js index bbeb172..e036123 100644 --- a/api/articles.js +++ b/api/articles.js @@ -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){ diff --git a/api/topics.js b/api/topics.js index bcd540b..4ddfcc2 100644 --- a/api/topics.js +++ b/api/topics.js @@ -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) diff --git a/db/matterwiki.sqlite b/db/matterwiki.sqlite index 7940c93..fcc7f70 100644 Binary files a/db/matterwiki.sqlite and b/db/matterwiki.sqlite differ