Skip to content
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

Add yasunori query to GET /awesome API #151

Merged
merged 1 commit into from
Nov 2, 2024
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
15 changes: 15 additions & 0 deletions packages/api/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ describe("Test GET /awesome", () => {
title: "yasunoriの母",
});
});

test("Should return entries replaced yasunori response", async () => {
const res = await app.request("/awesome?yasunori=takeokunn");
const parsed = await res.json<Array<unknown>>();
expect(parsed.at(-1)).toStrictEqual({
id: 1,
at: "vim-jp radioお便り",
content:
"tomoyaさん、ありすえさんこんにちは。\nはじめまして、takeokunnの母です。\n\ntakeokunnがソフトウェアエンジニアを志してから様子がおかしくなってしまいました。\n家ですれ違う時「Vim....Vim....」という独り言をずっと唱えていたり、部屋からは「設定させていただきありがとうございます!!」という大声が聞こえてきたり、\n「会合があるから東京に行ってくる、帰りは遅くなる」と言い残して出て行き、帰ってくると満面の笑みで「Vimはいいぞ」と一言言って自室に篭るようになりました。\n\ntomoyaさんありすえさんもVimコミュニティの人達だと伺いましたが、息子の身に一体何が起きてしまったのか教えていただけると幸いです。\n",
date: "2024-06-25",
meta: "",
senpan: "takeokunn",
title: "takeokunnの母",
});
});
});

describe("Test GET /awesome/random", () => {
Expand Down
16 changes: 15 additions & 1 deletion packages/api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,21 @@ const route = app
400,
);
}
return c.json(parsedAwesomeYasunori.output.yasunori);
const yasunori = c.req.query("yasunori");
if (!yasunori) {
return c.json(parsedAwesomeYasunori.output.yasunori);
}
// 他のyasunoriが指定されたら、yasunoriを置換する
// 置換するのは title, content, meta の中身だけ
const replacedYasunori = parsedAwesomeYasunori.output.yasunori.map((ay) => {
return {
...ay,
title: ay.title.replaceAll("yasunori", yasunori),
content: ay.content.replaceAll("yasunori", yasunori),
meta: ay.meta?.replaceAll("yasunori", yasunori),
};
});
return c.json(replacedYasunori);
})
.get("/awesome/random", async (c) => {
if (!parsedAwesomeYasunori.success) {
Expand Down