관리자 글 목록 API 응답 경량화

This commit is contained in:
2026-07-03 10:55:11 +09:00
parent 3f80bbb4ea
commit 94782d5873
12 changed files with 158 additions and 42 deletions

View File

@@ -0,0 +1,45 @@
import { createError, getRouterParam, readBody } from 'h3'
import { z } from 'zod'
import { requireAdminSession } from '../../../../../utils/admin-auth'
import { updateAdminPostFeatured } from '../../../../../repositories/content-repository'
const featuredInputSchema = z.object({
isFeatured: z.boolean()
})
/**
* 관리자 게시물 추천 상태 변경 API
* @param {import('h3').H3Event} event - 요청 이벤트
* @returns {Promise<Object>} 수정된 게시물
*/
export default defineEventHandler(async (event) => {
requireAdminSession(event)
const id = String(getRouterParam(event, 'id') || '').trim()
const parsedBody = featuredInputSchema.safeParse(await readBody(event))
if (!id) {
throw createError({
statusCode: 400,
message: '게시물 ID가 필요합니다.'
})
}
if (!parsedBody.success) {
throw createError({
statusCode: 400,
message: '추천 상태 입력 형식이 올바르지 않습니다.'
})
}
const post = await updateAdminPostFeatured(id, parsedBody.data.isFeatured)
if (!post) {
throw createError({
statusCode: 404,
message: '게시물을 찾을 수 없습니다.'
})
}
return post
})