Skip to content

Commit

Permalink
Merge pull request #151 from times-yasunori/yasunori-yasunoried
Browse files Browse the repository at this point in the history
Add yasunori query to GET /awesome API
  • Loading branch information
tomoya authored Nov 2, 2024
2 parents 445d680 + 508a773 commit 95c8b9e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
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

0 comments on commit 95c8b9e

Please sign in to comment.