Skip to content

(#14) 게시글의 제목으로 검색 #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;