Skip to content

Commit

Permalink
Merge pull request #15 from eungyeole/develop
Browse files Browse the repository at this point in the history
(#14) 게시글의 제목으로 검색
  • Loading branch information
eungyeole authored Jun 30, 2021
2 parents 02e5146 + 1a3a8c9 commit 6674cb8
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
5 changes: 3 additions & 2 deletions api/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
const createCard = require('../src/cards/new-log');
const createCardDark = require('../src/cards/new-log-black');
const fetchPost = require('../src/fetchers/post-fetcher');
const fetchReadPost = require('../src/fetchers/readpost-fetcher');


module.exports = async (req, res) => {
const { name, tag, color } = req.query;
const { name, tag, color, slug } = req.query;
res.setHeader('Content-Type', 'image/svg+xml');
try{
const post = await fetchPost(name, tag);
const post = !slug ? await fetchPost(name, tag) : await fetchReadPost(name, slug);
return res.send(color==='dark' ? createCardDark(post) : createCard(post))
} catch(e){
return res.send(e.message)
Expand Down
43 changes: 43 additions & 0 deletions src/fetchers/readpost-fetcher.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const { request } = require("../utils")

const fetcher = (variables) => {
return request(
{
query: `
query ReadPost($username: String, $url_slug: String) {
post(username: $username, url_slug: $url_slug) {
id
title
short_description
thumbnail
user {
username
profile {
thumbnail
}
}
url_slug
released_at
updated_at
comments_count
tags
likes
}
}
`,
variables
}
)
}

async function fetchReadPost(name, slug) {
try{
const { data } = await fetcher({"username": name, "url_slug" : slug});
return data.data.post;
}catch(e){
throw new Error(e)
}

}

module.exports=fetchReadPost;

0 comments on commit 6674cb8

Please sign in to comment.