7.2 목록 페이징/정렬/검색(제목/태그/작성자/기간) o
This commit is contained in:
@@ -38,6 +38,10 @@ const listQuerySchema = z.object({
|
||||
boardId: z.string().optional(),
|
||||
q: z.string().optional(),
|
||||
sort: z.enum(["recent", "popular"]).default("recent").optional(),
|
||||
tag: z.string().optional(), // Tag.slug
|
||||
author: z.string().optional(), // User.nickname contains
|
||||
start: z.coerce.date().optional(), // createdAt >= start
|
||||
end: z.coerce.date().optional(), // createdAt <= end
|
||||
});
|
||||
|
||||
export async function GET(req: Request) {
|
||||
@@ -46,7 +50,7 @@ export async function GET(req: Request) {
|
||||
if (!parsed.success) {
|
||||
return NextResponse.json({ error: parsed.error.flatten() }, { status: 400 });
|
||||
}
|
||||
const { page, pageSize, boardId, q, sort = "recent" } = parsed.data;
|
||||
const { page, pageSize, boardId, q, sort = "recent", tag, author, start, end } = parsed.data;
|
||||
const where = {
|
||||
NOT: { status: "deleted" as const },
|
||||
...(boardId ? { boardId } : {}),
|
||||
@@ -58,6 +62,24 @@ export async function GET(req: Request) {
|
||||
],
|
||||
}
|
||||
: {}),
|
||||
...(tag
|
||||
? {
|
||||
postTags: { some: { tag: { slug: tag } } },
|
||||
}
|
||||
: {}),
|
||||
...(author
|
||||
? {
|
||||
author: { nickname: { contains: author } },
|
||||
}
|
||||
: {}),
|
||||
...(start || end
|
||||
? {
|
||||
createdAt: {
|
||||
...(start ? { gte: start } : {}),
|
||||
...(end ? { lte: end } : {}),
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
} as const;
|
||||
|
||||
const [total, items] = await Promise.all([
|
||||
|
||||
Reference in New Issue
Block a user