기능구현중

This commit is contained in:
2026-01-11 17:01:01 +09:00
parent 375d5bf91a
commit 954ba21211
148 changed files with 2276 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
import { execute } from '../../../utils/db'
import { requireAuth } from '../../../utils/session'
/**
* 저장소 삭제 (비활성화)
* DELETE /api/repository/[id]
*/
export default defineEventHandler(async (event) => {
await requireAuth(event)
const repoId = parseInt(event.context.params?.id || '0')
if (!repoId) {
throw createError({ statusCode: 400, message: '저장소 ID가 필요합니다.' })
}
// 실제 삭제 대신 비활성화
await execute(`
UPDATE wr_repository SET is_active = false, updated_at = NOW() WHERE repo_id = $1
`, [repoId])
return { success: true }
})

View File

@@ -0,0 +1,64 @@
import { execute } from '../../../utils/db'
import { requireAuth } from '../../../utils/session'
import { getClientIp } from '../../../utils/ip'
interface UpdateRepoBody {
repoName?: string
repoPath?: string
repoUrl?: string
defaultBranch?: string
description?: string
isActive?: boolean
}
/**
* 저장소 수정
* PUT /api/repository/[id]
*/
export default defineEventHandler(async (event) => {
await requireAuth(event)
const repoId = parseInt(event.context.params?.id || '0')
const body = await readBody<UpdateRepoBody>(event)
const ip = getClientIp(event)
if (!repoId) {
throw createError({ statusCode: 400, message: '저장소 ID가 필요합니다.' })
}
const updates: string[] = ['updated_at = NOW()', 'updated_ip = $1']
const values: any[] = [ip]
let idx = 2
if (body.repoName !== undefined) {
updates.push(`repo_name = $${idx++}`)
values.push(body.repoName)
}
if (body.repoPath !== undefined) {
updates.push(`repo_path = $${idx++}`)
values.push(body.repoPath)
}
if (body.repoUrl !== undefined) {
updates.push(`repo_url = $${idx++}`)
values.push(body.repoUrl)
}
if (body.defaultBranch !== undefined) {
updates.push(`default_branch = $${idx++}`)
values.push(body.defaultBranch)
}
if (body.description !== undefined) {
updates.push(`description = $${idx++}`)
values.push(body.description)
}
if (body.isActive !== undefined) {
updates.push(`is_active = $${idx++}`)
values.push(body.isActive)
}
values.push(repoId)
await execute(`
UPDATE wr_repository SET ${updates.join(', ')} WHERE repo_id = $${idx}
`, values)
return { success: true }
})

View File

@@ -0,0 +1,39 @@
import { queryOne } from '../../../utils/db'
import { requireAuth } from '../../../utils/session'
import { syncGitRepository } from '../../../utils/git-sync'
import { syncSvnRepository } from '../../../utils/svn-sync'
/**
* 저장소 동기화 (수동)
* POST /api/repository/[id]/sync
*/
export default defineEventHandler(async (event) => {
await requireAuth(event)
const repoId = parseInt(getRouterParam(event, 'id') || '0')
if (!repoId) {
throw createError({ statusCode: 400, message: '저장소 ID가 필요합니다.' })
}
// 저장소 정보 확인
const repo = await queryOne(`
SELECT r.*, s.server_type
FROM wr_repository r
JOIN wr_vcs_server s ON r.server_id = s.server_id
WHERE r.repo_id = $1
`, [repoId])
if (!repo) {
throw createError({ statusCode: 404, message: '저장소를 찾을 수 없습니다.' })
}
if (repo.server_type === 'GIT') {
const result = await syncGitRepository(repoId)
return result
} else if (repo.server_type === 'SVN') {
const result = await syncSvnRepository(repoId)
return result
}
return { success: false, message: '지원하지 않는 서버 타입입니다.' }
})

View File

@@ -0,0 +1,47 @@
import { insertReturning } from '../../utils/db'
import { requireAuth } from '../../utils/session'
import { getClientIp } from '../../utils/ip'
interface CreateRepoBody {
projectId: number
serverId: number
repoName: string
repoPath: string
repoUrl?: string
defaultBranch?: string
description?: string
}
/**
* 저장소 추가
* POST /api/repository/create
*/
export default defineEventHandler(async (event) => {
const employeeId = await requireAuth(event)
const body = await readBody<CreateRepoBody>(event)
const ip = getClientIp(event)
if (!body.projectId || !body.serverId || !body.repoPath) {
throw createError({ statusCode: 400, message: '필수 항목을 입력해주세요.' })
}
const repo = await insertReturning(`
INSERT INTO wr_repository (
project_id, server_id, repo_name, repo_path, repo_url,
default_branch, description, created_by, created_at, created_ip
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, NOW(), $9)
RETURNING repo_id
`, [
body.projectId,
body.serverId,
body.repoName || body.repoPath,
body.repoPath,
body.repoUrl || null,
body.defaultBranch || 'main',
body.description || null,
employeeId,
ip
])
return { success: true, repoId: repo.repo_id }
})

View File

@@ -0,0 +1,67 @@
import { query } from '../../utils/db'
/**
* 저장소 목록 조회
* GET /api/repository/list
*/
export default defineEventHandler(async (event) => {
const params = getQuery(event)
const projectId = params.projectId ? Number(params.projectId) : null
const serverId = params.serverId ? Number(params.serverId) : null
const includeInactive = params.includeInactive === 'true'
const conditions: string[] = []
const values: any[] = []
let paramIndex = 1
if (projectId) {
conditions.push(`r.project_id = $${paramIndex++}`)
values.push(projectId)
}
if (serverId) {
conditions.push(`r.server_id = $${paramIndex++}`)
values.push(serverId)
}
if (!includeInactive) {
conditions.push('r.is_active = true')
}
const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(' AND ')}` : ''
const repos = await query(`
SELECT
r.*,
s.server_name,
s.server_type,
p.project_name,
e.employee_name as created_by_name
FROM wr_repository r
JOIN wr_vcs_server s ON r.server_id = s.server_id
LEFT JOIN wr_project_info p ON r.project_id = p.project_id
LEFT JOIN wr_employee_info e ON r.created_by = e.employee_id
${whereClause}
ORDER BY r.repo_name
`, values)
return {
repositories: repos.map((r: any) => ({
repoId: r.repo_id,
serverId: r.server_id,
serverName: r.server_name,
serverType: r.server_type,
projectId: r.project_id,
projectName: r.project_name,
repoName: r.repo_name,
repoPath: r.repo_path,
repoUrl: r.repo_url,
defaultBranch: r.default_branch,
description: r.description,
isActive: r.is_active,
lastSyncAt: r.last_sync_at,
createdAt: r.created_at,
createdByName: r.created_by_name
}))
}
})