Admin: gestión de opciones de oro (home_goldprice)
- lib/admin-gold.ts: list/create/delete sobre home_goldprice (id, gold_amount, price). - API: POST /api/admin/gold, DELETE /api/admin/gold/[id] (403 sin admin). - UI: /admin/gold con AdminGoldManager (alta ordenada por cantidad + borrado), enlace desde el índice del admin. - i18n es/en (Admin): manageGold, gold, goldAmount, goldPrice, goldUnit, noGold. Verificado: build OK, /admin/gold 307→login sin sesión, APIs 403 sin admin, columnas confirmadas en la migración Django. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import { getTranslations, setRequestLocale } from 'next-intl/server'
|
||||
import { redirect } from '@/i18n/navigation'
|
||||
import { getSession } from '@/lib/session'
|
||||
import { isAdmin } from '@/lib/admin'
|
||||
import { listGoldOptions } from '@/lib/admin-gold'
|
||||
import { AdminGoldManager } from '@/components/AdminGoldManager'
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
export default async function AdminGoldPage({ params }: { params: Promise<{ locale: string }> }) {
|
||||
const { locale } = await params
|
||||
setRequestLocale(locale)
|
||||
const t = await getTranslations('Admin')
|
||||
const session = await getSession()
|
||||
if (!session.bnetId) redirect({ href: '/login', locale })
|
||||
if (!(await isAdmin(session))) redirect({ href: '/', locale })
|
||||
const options = await listGoldOptions()
|
||||
return (
|
||||
<main className="mx-auto max-w-3xl px-4 py-8">
|
||||
<h1 className="mb-6 text-2xl font-bold text-amber-500">{t('gold')}</h1>
|
||||
<AdminGoldManager initial={options} />
|
||||
</main>
|
||||
)
|
||||
}
|
||||
@@ -32,6 +32,11 @@ export default async function AdminPage({ params }: { params: Promise<{ locale:
|
||||
{t('manageVotes')}
|
||||
</Link>
|
||||
</li>
|
||||
<li>
|
||||
<Link href="/admin/gold" className="text-sky-400 hover:underline">
|
||||
{t('manageGold')}
|
||||
</Link>
|
||||
</li>
|
||||
</ul>
|
||||
</main>
|
||||
)
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import { getSession } from '@/lib/session'
|
||||
import { isAdmin } from '@/lib/admin'
|
||||
import { deleteGoldOption } from '@/lib/admin-gold'
|
||||
|
||||
export async function DELETE(_request: Request, { params }: { params: Promise<{ id: string }> }) {
|
||||
const session = await getSession()
|
||||
if (!(await isAdmin(session))) return Response.json({ success: false, error: 'forbidden' }, { status: 403 })
|
||||
const { id } = await params
|
||||
await deleteGoldOption(Number(id))
|
||||
return Response.json({ success: true })
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { getSession } from '@/lib/session'
|
||||
import { isAdmin } from '@/lib/admin'
|
||||
import { createGoldOption } from '@/lib/admin-gold'
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const session = await getSession()
|
||||
if (!(await isAdmin(session))) return Response.json({ success: false, error: 'forbidden' }, { status: 403 })
|
||||
let b: Record<string, unknown> = {}
|
||||
try { b = await request.json() } catch { return Response.json({ success: false, error: 'invalidRequest' }, { status: 400 }) }
|
||||
const goldAmount = Number(b.goldAmount)
|
||||
const price = Number(b.price)
|
||||
if (!(goldAmount > 0) || !(price >= 0)) return Response.json({ success: false, error: 'emptyError' })
|
||||
const id = await createGoldOption(goldAmount, price)
|
||||
return Response.json({ success: true, id })
|
||||
}
|
||||
Reference in New Issue
Block a user