feat: initial brainstorming app — Nuxt 3 + SQLite + admin auth
Nuxt 3 app with: - SQLite (better-sqlite3) for persistence - Anonymous idea submission and voting - Admin auth with session cookies - AI analysis via Gemini API - Nuxt UI components + Tailwind Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
9
server/api/ideas/[id].delete.ts
Normal file
9
server/api/ideas/[id].delete.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import db from '../../utils/db'
|
||||
import { requireAdmin } from '../../utils/auth'
|
||||
|
||||
export default defineEventHandler((event) => {
|
||||
requireAdmin(event)
|
||||
const id = getRouterParam(event, 'id')
|
||||
db.prepare('DELETE FROM ideas WHERE id = ?').run(id)
|
||||
return { ok: true }
|
||||
})
|
||||
20
server/api/ideas/[id].patch.ts
Normal file
20
server/api/ideas/[id].patch.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import db from '../../utils/db'
|
||||
import { requireAdmin } from '../../utils/auth'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
requireAdmin(event)
|
||||
const id = getRouterParam(event, 'id')
|
||||
const body = await readBody(event)
|
||||
|
||||
if (body.hidden !== undefined) {
|
||||
db.prepare('UPDATE ideas SET hidden = ? WHERE id = ?').run(body.hidden ? 1 : 0, id)
|
||||
}
|
||||
if (body.text !== undefined) {
|
||||
db.prepare('UPDATE ideas SET text = ? WHERE id = ?').run(body.text, id)
|
||||
}
|
||||
if (body.category !== undefined) {
|
||||
db.prepare('UPDATE ideas SET category = ? WHERE id = ?').run(body.category, id)
|
||||
}
|
||||
|
||||
return { ok: true }
|
||||
})
|
||||
10
server/api/ideas/index.get.ts
Normal file
10
server/api/ideas/index.get.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import db from '../../utils/db'
|
||||
import { isAdmin } from '../../utils/auth'
|
||||
|
||||
export default defineEventHandler((event) => {
|
||||
const admin = isAdmin(event)
|
||||
const rows = admin
|
||||
? db.prepare('SELECT * FROM ideas ORDER BY created_at DESC').all()
|
||||
: db.prepare('SELECT * FROM ideas WHERE hidden = 0 ORDER BY created_at DESC').all()
|
||||
return rows
|
||||
})
|
||||
11
server/api/ideas/index.post.ts
Normal file
11
server/api/ideas/index.post.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import db from '../../utils/db'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const { text, category } = await readBody(event)
|
||||
if (!text?.trim()) {
|
||||
throw createError({ statusCode: 400, statusMessage: 'Text is required' })
|
||||
}
|
||||
const cat = category || 'General'
|
||||
const result = db.prepare('INSERT INTO ideas (text, category) VALUES (?, ?)').run(text.trim(), cat)
|
||||
return { id: result.lastInsertRowid }
|
||||
})
|
||||
Reference in New Issue
Block a user