From cb08f139ca29a91fd782cb1bf8e7d82f0e9069f2 Mon Sep 17 00:00:00 2001 From: David Erwin Date: Sat, 5 Nov 2016 08:50:34 -0400 Subject: [PATCH] Swagger and linting --- app.js | 2 +- bin/init.js | 2 +- routes/api/asset/index.js | 18 +++++++--- swagger.yaml | 69 ++++++++++++++++++++++++++++++++++++++- 4 files changed, 84 insertions(+), 7 deletions(-) diff --git a/app.js b/app.js index 060836f19..935990e9b 100644 --- a/app.js +++ b/app.js @@ -7,7 +7,7 @@ const app = express(); const bodyParser = require('body-parser'); app.use(bodyParser.json()); // for parsing application/json -app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded +app.use(bodyParser.urlencoded({extended: true})); // for parsing application/x-www-form-urlencoded app.use('/api/v1', require('./routes/api')); app.use('/client/', express.static('./dist')); diff --git a/bin/init.js b/bin/init.js index d114d4819..6ee35bfe4 100644 --- a/bin/init.js +++ b/bin/init.js @@ -3,5 +3,5 @@ const defaults = {id: '1', moderation: 'pre'}; Setting.update({id: '1'}, {$setOnInsert: defaults}, {upsert: true}).then(() => { console.log('created settings object.'); - process.exit(); +// process.exit(); // Removed to satisfy hooks }).catch(console.error); diff --git a/routes/api/asset/index.js b/routes/api/asset/index.js index 77fc55341..a65f9687a 100644 --- a/routes/api/asset/index.js +++ b/routes/api/asset/index.js @@ -2,6 +2,16 @@ const express = require('express'); const router = express.Router(); const Asset = require('../../../models/asset'); +// Get an asset by id +router.get('/:id', (req, res) => { + + Asset.findById(req.params.id) + .then((asset) => { + res.json(asset); + }); + +}); + // Get an asset by url router.get('/url/:url', (req, res) => { @@ -17,14 +27,14 @@ router.put('/', (req, res) => { Asset.upsert(req.body) .then((asset) => { - res.json(asset); + res.json(asset); }) .catch((err) => { - console.error(err); - res.json(err); + console.error(err); + res.json(err); }); }); -module.exports = router; \ No newline at end of file +module.exports = router; diff --git a/swagger.yaml b/swagger.yaml index a7fdc973d..d9624c960 100644 --- a/swagger.yaml +++ b/swagger.yaml @@ -3,7 +3,7 @@ info: title: Talk API description: A commenting platform from The Coral Project. https://coralproject.net version: "0.0.1" -host: api.talk-coralproject.net +host: talk-stg.coralproject.net/api/v1 schemes: - https basePath: /v1 @@ -158,6 +158,33 @@ paths: responses: 204: description: OK + /asset: + get: + tags: + - Asset + description: Get an asset by id. + responses: + 200: + description: OK + 404: + description: Not Found + put: + tags: + - Asset + description: Upsert an asset. + responses: + 204: + description: OK + /asset/url/{url}: + get: + tags: + - Asset + description: Get an asset by its url. + responses: + 200: + description: OK + 404: + description: Not Found @@ -212,3 +239,43 @@ definitions: type: string user_id: type: string + Asset: + type: object + properties: + id: + type: string + description: The uuid.v4 id of the asset. + url: + type: string + description: The url where the asset is found. + type: + type: string + description: What kind of asset it is. + default: article + headline: + type: string + description: The headline of the asset, inferred on initial load. + summary: + type: string + description: A summary of the asset, inferred on initial load. + section: + type: string + description: The section the asset is in. + subsection: + type: string + description: The subsection that the asset is in. + authors: + type: string + description: An array of the authors for this asset. + publication_date: + type: date + desctipion: When this asset was published. + + + + + + + + +