사이트 설정 관리 추가

This commit is contained in:
2026-05-02 16:37:11 +09:00
parent d5666fdcc3
commit 27cf05aba6
18 changed files with 431 additions and 25 deletions

View File

@@ -5,6 +5,7 @@ import {
getSamplePosts,
getSampleTags
} from '../utils/sample-content'
import { getDefaultSiteSettings } from '../utils/site-settings'
import { getPostgresClient } from './postgres-client'
/**
@@ -55,6 +56,20 @@ const mapTagRow = (row) => ({
color: row.color
})
/**
* 사이트 설정 행을 API 응답 구조로 변환
* @param {Object} row - 사이트 설정 행
* @returns {Object} 사이트 설정 응답
*/
const mapSiteSettingsRow = (row) => ({
title: row.title,
description: row.description,
siteUrl: row.site_url,
logoText: row.logo_text,
copyrightText: row.copyright_text,
updatedAt: row.updated_at.toISOString()
})
/**
* 태그 슬러그 목록 정규화
* @param {Array<string>} tags - 태그 슬러그 목록
@@ -488,6 +503,72 @@ export const listTags = async () => {
return rows.map(mapTagRow)
}
/**
* 사이트 설정 조회
* @returns {Promise<Object>} 사이트 설정
*/
export const getSiteSettings = async () => {
const sql = getPostgresClient()
if (!sql) {
return getDefaultSiteSettings()
}
const rows = await sql`
SELECT *
FROM site_settings
WHERE id = 1
LIMIT 1
`
return rows[0] ? mapSiteSettingsRow(rows[0]) : getDefaultSiteSettings()
}
/**
* 관리자 사이트 설정 수정
* @param {Object} input - 사이트 설정 입력값
* @returns {Promise<Object>} 수정된 사이트 설정
*/
export const updateSiteSettings = async (input) => {
const sql = getPostgresClient()
if (!sql) {
throw new Error('DATABASE_REQUIRED')
}
const rows = await sql`
INSERT INTO site_settings (
id,
title,
description,
site_url,
logo_text,
copyright_text,
updated_at
)
VALUES (
1,
${input.title},
${input.description},
${input.siteUrl},
${input.logoText},
${input.copyrightText},
now()
)
ON CONFLICT (id) DO UPDATE
SET
title = EXCLUDED.title,
description = EXCLUDED.description,
site_url = EXCLUDED.site_url,
logo_text = EXCLUDED.logo_text,
copyright_text = EXCLUDED.copyright_text,
updated_at = now()
RETURNING *
`
return mapSiteSettingsRow(rows[0])
}
/**
* 관리자 태그 상세 조회
* @param {string} id - 태그 ID