Skip to content
This repository was archived by the owner on Aug 12, 2023. It is now read-only.

Commit 6dab2a3

Browse files
authored
Add endpoint for fetching individual articles (#383)
1 parent 4a19f44 commit 6dab2a3

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

src/app/routes/v1/articles.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,35 @@ const createRouter = () => {
3838
await next();
3939
});
4040

41+
router.get('/:feedSlug/:articleSlug', async ({ response, params }, next) => {
42+
const { feedSlug, articleSlug } = params;
43+
const sources = await getArticleSources();
44+
const feed = _.findKey(sources, s => s.slug === feedSlug);
45+
const article = await Article.findOne({ feed, slug: articleSlug }).lean();
46+
47+
if (article === null) {
48+
response.status = 404;
49+
await next();
50+
return;
51+
}
52+
53+
const source = _.find(sources, s => s.slug === feedSlug);
54+
const { author, content, date, slug, summary, title, url } = article;
55+
56+
response.body = {
57+
author,
58+
content,
59+
date,
60+
slug,
61+
source,
62+
summary,
63+
title,
64+
url,
65+
};
66+
67+
await next();
68+
});
69+
4170
return router;
4271
};
4372

src/app/routes/v1/util/transform-article.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const transformArticle = (sources, article) => {
44
const source = sources[article.feed];
55

66
return {
7-
..._.pick(article, ['date', 'id', 'summary', 'title', 'url']),
7+
..._.pick(article, ['date', 'id', 'slug', 'summary', 'title', 'url']),
88
source,
99
};
1010
};

src/model/article.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ const mongoosePaginate = require('mongoose-paginate');
33

44
const schema = mongoose.Schema({
55
author: String,
6+
content: String,
67
date: Date,
78
feed: String,
89
guid: String,
10+
slug: String,
911
summary: String,
1012
title: String,
1113
url: String,

0 commit comments

Comments
 (0)