feat: add admin dashboard and core API routes with Docker configuration
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import prisma from '../../../../lib/prisma'
|
||||
|
||||
type Params = { params: Promise<{ id: string }> }
|
||||
import { isAdmin } from '@/lib/auth-utils'
|
||||
|
||||
// GET /api/blog/[id]
|
||||
export async function GET(
|
||||
@@ -19,12 +18,16 @@ export async function GET(
|
||||
}
|
||||
}
|
||||
|
||||
// PATCH /api/blog/[id]
|
||||
// PATCH /api/blog/[id] (Admin only)
|
||||
export async function PATCH(
|
||||
request: NextRequest,
|
||||
context: { params: Promise<{ id: string }> }
|
||||
): Promise<Response> {
|
||||
try {
|
||||
if (!(await isAdmin(request))) {
|
||||
return NextResponse.json({ error: 'Accès réservé aux administrateurs' }, { status: 403 })
|
||||
}
|
||||
|
||||
const { id } = await context.params
|
||||
const body = await request.json()
|
||||
if (body.title && body.slug === undefined) {
|
||||
@@ -39,12 +42,16 @@ export async function PATCH(
|
||||
}
|
||||
}
|
||||
|
||||
// DELETE /api/blog/[id]
|
||||
// DELETE /api/blog/[id] (Admin only)
|
||||
export async function DELETE(
|
||||
_request: NextRequest,
|
||||
request: NextRequest,
|
||||
context: { params: Promise<{ id: string }> }
|
||||
): Promise<Response> {
|
||||
try {
|
||||
if (!(await isAdmin(request))) {
|
||||
return NextResponse.json({ error: 'Accès réservé aux administrateurs' }, { status: 403 })
|
||||
}
|
||||
|
||||
const { id } = await context.params
|
||||
await prisma.blogPost.delete({ where: { id } })
|
||||
return NextResponse.json({ success: true })
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import prisma from '@/lib/prisma'
|
||||
import { generateSlug } from '@/lib/utils'
|
||||
import { isAdmin } from '@/lib/auth-utils'
|
||||
|
||||
// GET /api/blog
|
||||
export async function GET() {
|
||||
@@ -21,9 +22,13 @@ export async function GET() {
|
||||
}
|
||||
}
|
||||
|
||||
// POST /api/blog
|
||||
// POST /api/blog (Admin only)
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
if (!(await isAdmin(request))) {
|
||||
return NextResponse.json({ error: 'Accès réservé aux administrateurs' }, { status: 403 })
|
||||
}
|
||||
|
||||
const body = await request.json()
|
||||
if (!body.slug && body.title) {
|
||||
body.slug = generateSlug(body.title)
|
||||
|
||||
Reference in New Issue
Block a user