feat(ai-cases-write): 등록된 사례 목록 5건 단위 페이징

- 최신순 정렬 후 페이지당 5개, 이전/다음 네비
- edit·page 쿼리 유지, 목록 영역 스타일 보강

Made-with: Cursor
This commit is contained in:
2026-04-08 20:20:41 +09:00
parent b9baa7ec12
commit 6126291257
3 changed files with 60 additions and 4 deletions

View File

@@ -1167,6 +1167,8 @@ pageRouter.get("/ai-explore/task-checklist", (req, res) =>
opsState: normalizeOpsState(),
})
);
const AI_SUCCESS_ADMIN_LIST_PAGE_SIZE = 5;
pageRouter.get("/ai-cases/write", (req, res) => {
if (!res.locals.adminMode) {
return res.status(403).send(
@@ -1180,11 +1182,31 @@ pageRouter.get("/ai-cases/write", (req, res) => {
const m = meta.find((x) => x.slug === editSlug);
if (m) story = enrichAiSuccessStory(m);
}
const sortedStories = [...meta].sort((a, b) => {
const da = new Date(a.publishedAt || a.updatedAt || a.createdAt || 0);
const db = new Date(b.publishedAt || b.updatedAt || b.createdAt || 0);
return db - da;
});
const pageRaw = req.query.page;
const pageNum = Math.max(1, parseInt(Array.isArray(pageRaw) ? pageRaw[0] : pageRaw, 10) || 1);
const totalCount = sortedStories.length;
const totalPages = Math.max(1, Math.ceil(totalCount / AI_SUCCESS_ADMIN_LIST_PAGE_SIZE));
const currentPage = Math.min(pageNum, totalPages);
const start = (currentPage - 1) * AI_SUCCESS_ADMIN_LIST_PAGE_SIZE;
const allStories = sortedStories.slice(start, start + AI_SUCCESS_ADMIN_LIST_PAGE_SIZE);
const listPagination = {
page: currentPage,
totalPages,
totalCount,
hasPrev: currentPage > 1,
hasNext: currentPage < totalPages,
};
res.render("ai-cases-write", {
activeMenu: "ai-cases",
adminMode: true,
story,
allStories: meta,
allStories,
listPagination,
editSlug: editSlug || null,
});
});