관리자 글 목록 고정 기능 추가

This commit is contained in:
2026-07-03 15:19:41 +09:00
parent 55efae810f
commit 288e73c0dc
11 changed files with 160 additions and 16 deletions

View File

@@ -0,0 +1,45 @@
import { createError, getRouterParam, readBody } from 'h3'
import { z } from 'zod'
import { requireAdminSession } from '../../../../../utils/admin-auth'
import { updateAdminPostPinned } from '../../../../../repositories/content-repository'
const pinnedInputSchema = z.object({
adminPinned: 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 = pinnedInputSchema.safeParse(await readBody(event))
if (!id) {
throw createError({
statusCode: 400,
message: '게시물 ID가 필요합니다.'
})
}
if (!parsedBody.success) {
throw createError({
statusCode: 400,
message: '고정 상태 입력 형식이 올바르지 않습니다.'
})
}
const post = await updateAdminPostPinned(id, parsedBody.data.adminPinned)
if (!post) {
throw createError({
statusCode: 404,
message: '게시물을 찾을 수 없습니다.'
})
}
return post
})