시스템 모니터
This commit is contained in:
10
backend/api/network/privnet/targets/[id].delete.ts
Normal file
10
backend/api/network/privnet/targets/[id].delete.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { getDb } from '../../../../utils/db'
|
||||
|
||||
export default defineEventHandler((event) => {
|
||||
const db = getDb()
|
||||
const id = getRouterParam(event, 'id')
|
||||
|
||||
db.prepare(`DELETE FROM privnet_targets WHERE id = ?`).run(id)
|
||||
|
||||
return { success: true }
|
||||
})
|
||||
29
backend/api/network/privnet/targets/[id].put.ts
Normal file
29
backend/api/network/privnet/targets/[id].put.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { getDb } from '../../../../utils/db'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const db = getDb()
|
||||
const id = getRouterParam(event, 'id')
|
||||
const body = await readBody(event)
|
||||
|
||||
const { name, url, is_active } = body
|
||||
|
||||
if (!name || !url) {
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
message: 'name과 url은 필수입니다'
|
||||
})
|
||||
}
|
||||
|
||||
db.prepare(`
|
||||
UPDATE privnet_targets
|
||||
SET name = ?, url = ?, is_active = ?, updated_at = datetime('now', 'localtime')
|
||||
WHERE id = ?
|
||||
`).run(name, url, is_active ? 1 : 0, id)
|
||||
|
||||
return {
|
||||
id: Number(id),
|
||||
name,
|
||||
url,
|
||||
is_active: is_active ? 1 : 0
|
||||
}
|
||||
})
|
||||
12
backend/api/network/privnet/targets/index.get.ts
Normal file
12
backend/api/network/privnet/targets/index.get.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { getDb } from '../../../../utils/db'
|
||||
|
||||
export default defineEventHandler(() => {
|
||||
const db = getDb()
|
||||
|
||||
const targets = db.prepare(`
|
||||
SELECT * FROM privnet_targets
|
||||
ORDER BY id ASC
|
||||
`).all()
|
||||
|
||||
return targets
|
||||
})
|
||||
27
backend/api/network/privnet/targets/index.post.ts
Normal file
27
backend/api/network/privnet/targets/index.post.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { getDb } from '../../../../utils/db'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const db = getDb()
|
||||
const body = await readBody(event)
|
||||
|
||||
const { name, url, is_active } = body
|
||||
|
||||
if (!name || !url) {
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
message: 'name과 url은 필수입니다'
|
||||
})
|
||||
}
|
||||
|
||||
const result = db.prepare(`
|
||||
INSERT INTO privnet_targets (name, url, is_active)
|
||||
VALUES (?, ?, ?)
|
||||
`).run(name, url, is_active ? 1 : 0)
|
||||
|
||||
return {
|
||||
id: result.lastInsertRowid,
|
||||
name,
|
||||
url,
|
||||
is_active: is_active ? 1 : 0
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user