save avant prochaine modif
This commit is contained in:
42
app/api/blog/[id]/route.ts
Normal file
42
app/api/blog/[id]/route.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import prisma from '../../../../lib/prisma'
|
||||
|
||||
type Params = { params: Promise<{ id: string }> }
|
||||
|
||||
// GET /api/blog/[id]
|
||||
export async function GET(_request: NextRequest, { params }: Params) {
|
||||
try {
|
||||
const { id } = await params
|
||||
const post = await prisma.blogPost.findUnique({ where: { id } })
|
||||
if (!post) return NextResponse.json({ error: 'Non trouvé' }, { status: 404 })
|
||||
return NextResponse.json(post)
|
||||
} catch (error) {
|
||||
console.error('GET /api/blog/[id] error:', error)
|
||||
return NextResponse.json({ error: 'Erreur serveur' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
||||
// PATCH /api/blog/[id]
|
||||
export async function PATCH(request: NextRequest, { params }: Params) {
|
||||
try {
|
||||
const { id } = await params
|
||||
const body = await request.json()
|
||||
const post = await prisma.blogPost.update({ where: { id }, data: body })
|
||||
return NextResponse.json(post)
|
||||
} catch (error) {
|
||||
console.error('PATCH /api/blog/[id] error:', error)
|
||||
return NextResponse.json({ error: 'Erreur lors de la mise à jour' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
||||
// DELETE /api/blog/[id]
|
||||
export async function DELETE(_request: NextRequest, { params }: Params) {
|
||||
try {
|
||||
const { id } = await params
|
||||
await prisma.blogPost.delete({ where: { id } })
|
||||
return NextResponse.json({ success: true })
|
||||
} catch (error) {
|
||||
console.error('DELETE /api/blog/[id] error:', error)
|
||||
return NextResponse.json({ error: 'Erreur lors de la suppression' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
27
app/api/blog/route.ts
Normal file
27
app/api/blog/route.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import prisma from '../../../lib/prisma'
|
||||
|
||||
// GET /api/blog
|
||||
export async function GET() {
|
||||
try {
|
||||
const posts = await prisma.blogPost.findMany({
|
||||
orderBy: { date: 'desc' },
|
||||
})
|
||||
return NextResponse.json(posts)
|
||||
} catch (error) {
|
||||
console.error('GET /api/blog error:', error)
|
||||
return NextResponse.json({ error: 'Erreur serveur' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
||||
// POST /api/blog
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const body = await request.json()
|
||||
const post = await prisma.blogPost.create({ data: body })
|
||||
return NextResponse.json(post, { status: 201 })
|
||||
} catch (error) {
|
||||
console.error('POST /api/blog error:', error)
|
||||
return NextResponse.json({ error: 'Erreur lors de la création' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
49
app/api/businesses/[id]/route.ts
Normal file
49
app/api/businesses/[id]/route.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import prisma from '../../../../lib/prisma'
|
||||
|
||||
type Params = { params: Promise<{ id: string }> }
|
||||
|
||||
// GET /api/businesses/[id]
|
||||
export async function GET(_request: NextRequest, { params }: Params) {
|
||||
try {
|
||||
const { id } = await params
|
||||
const business = await prisma.business.findUnique({
|
||||
where: { id },
|
||||
include: { owner: true, offers: true },
|
||||
})
|
||||
if (!business) return NextResponse.json({ error: 'Non trouvé' }, { status: 404 })
|
||||
return NextResponse.json(business)
|
||||
} catch (error) {
|
||||
console.error('GET /api/businesses/[id] error:', error)
|
||||
return NextResponse.json({ error: 'Erreur serveur' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
||||
// PATCH /api/businesses/[id]
|
||||
export async function PATCH(request: NextRequest, { params }: Params) {
|
||||
try {
|
||||
const { id } = await params
|
||||
const body = await request.json()
|
||||
const business = await prisma.business.update({
|
||||
where: { id },
|
||||
data: body,
|
||||
include: { owner: true, offers: true },
|
||||
})
|
||||
return NextResponse.json(business)
|
||||
} catch (error) {
|
||||
console.error('PATCH /api/businesses/[id] error:', error)
|
||||
return NextResponse.json({ error: 'Erreur lors de la mise à jour' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
||||
// DELETE /api/businesses/[id]
|
||||
export async function DELETE(_request: NextRequest, { params }: Params) {
|
||||
try {
|
||||
const { id } = await params
|
||||
await prisma.business.delete({ where: { id } })
|
||||
return NextResponse.json({ success: true })
|
||||
} catch (error) {
|
||||
console.error('DELETE /api/businesses/[id] error:', error)
|
||||
return NextResponse.json({ error: 'Erreur lors de la suppression' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
49
app/api/businesses/route.ts
Normal file
49
app/api/businesses/route.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import prisma from '../../../lib/prisma'
|
||||
|
||||
// GET /api/businesses — List all businesses
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const { searchParams } = new URL(request.url)
|
||||
const category = searchParams.get('category')
|
||||
const q = searchParams.get('q')
|
||||
const featured = searchParams.get('featured')
|
||||
|
||||
const where: Record<string, unknown> = {}
|
||||
if (category && category !== 'All') where.category = category
|
||||
if (featured === 'true') where.isFeatured = true
|
||||
if (q) {
|
||||
where.OR = [
|
||||
{ name: { contains: q, mode: 'insensitive' } },
|
||||
{ description: { contains: q, mode: 'insensitive' } },
|
||||
{ tags: { hasSome: [q] } },
|
||||
]
|
||||
}
|
||||
|
||||
const businesses = await prisma.business.findMany({
|
||||
where,
|
||||
include: { owner: true, offers: true },
|
||||
orderBy: { createdAt: 'desc' },
|
||||
})
|
||||
|
||||
return NextResponse.json(businesses)
|
||||
} catch (error) {
|
||||
console.error('GET /api/businesses error:', error)
|
||||
return NextResponse.json({ error: 'Erreur serveur' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
||||
// POST /api/businesses — Create a business
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const body = await request.json()
|
||||
const business = await prisma.business.create({
|
||||
data: body,
|
||||
include: { owner: true },
|
||||
})
|
||||
return NextResponse.json(business, { status: 201 })
|
||||
} catch (error) {
|
||||
console.error('POST /api/businesses error:', error)
|
||||
return NextResponse.json({ error: 'Erreur lors de la création' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
57
app/api/gemini/route.ts
Normal file
57
app/api/gemini/route.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { GoogleGenAI } from '@google/genai'
|
||||
|
||||
// POST /api/gemini — AI content generation
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const apiKey = process.env.GEMINI_API_KEY
|
||||
if (!apiKey || apiKey === 'PLACEHOLDER_API_KEY') {
|
||||
return NextResponse.json(
|
||||
{ error: 'Clé API Gemini non configurée' },
|
||||
{ status: 503 }
|
||||
)
|
||||
}
|
||||
|
||||
const ai = new GoogleGenAI({ apiKey })
|
||||
const body = await request.json()
|
||||
const { action, name, category, keywords } = body
|
||||
|
||||
if (action === 'description') {
|
||||
const prompt = `
|
||||
Tu es un expert en copywriting marketing pour Afropreunariat.
|
||||
Rédige une description professionnelle, attrayante et optimisée SEO pour une entreprise.
|
||||
|
||||
Nom de l'entreprise : ${name}
|
||||
Secteur : ${category}
|
||||
Mots-clés/Services : ${keywords}
|
||||
|
||||
La description doit faire environ 80-100 mots, être en français, inspirer confiance et professionnalisme.
|
||||
Ne mets pas de guillemets au début ou à la fin.
|
||||
`
|
||||
const response = await ai.models.generateContent({
|
||||
model: 'gemini-2.5-flash',
|
||||
contents: prompt,
|
||||
})
|
||||
return NextResponse.json({ text: response.text || '' })
|
||||
}
|
||||
|
||||
if (action === 'slogans') {
|
||||
const prompt = `Donne-moi 3 idées de slogans courts et percutants pour une entreprise dans le secteur : ${category}. Retourne uniquement une liste JSON de chaînes de caractères.`
|
||||
const response = await ai.models.generateContent({
|
||||
model: 'gemini-2.5-flash',
|
||||
contents: prompt,
|
||||
config: { responseMimeType: 'application/json' },
|
||||
})
|
||||
const json = JSON.parse(response.text || '[]')
|
||||
return NextResponse.json({ slogans: Array.isArray(json) ? json : [] })
|
||||
}
|
||||
|
||||
return NextResponse.json({ error: 'Action inconnue' }, { status: 400 })
|
||||
} catch (error) {
|
||||
console.error('POST /api/gemini error:', error)
|
||||
return NextResponse.json(
|
||||
{ error: 'Erreur lors de la génération IA' },
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
}
|
||||
42
app/api/interviews/[id]/route.ts
Normal file
42
app/api/interviews/[id]/route.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import prisma from '../../../../lib/prisma'
|
||||
|
||||
type Params = { params: Promise<{ id: string }> }
|
||||
|
||||
// GET /api/interviews/[id]
|
||||
export async function GET(_request: NextRequest, { params }: Params) {
|
||||
try {
|
||||
const { id } = await params
|
||||
const interview = await prisma.interview.findUnique({ where: { id } })
|
||||
if (!interview) return NextResponse.json({ error: 'Non trouvé' }, { status: 404 })
|
||||
return NextResponse.json(interview)
|
||||
} catch (error) {
|
||||
console.error('GET /api/interviews/[id] error:', error)
|
||||
return NextResponse.json({ error: 'Erreur serveur' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
||||
// PATCH /api/interviews/[id]
|
||||
export async function PATCH(request: NextRequest, { params }: Params) {
|
||||
try {
|
||||
const { id } = await params
|
||||
const body = await request.json()
|
||||
const interview = await prisma.interview.update({ where: { id }, data: body })
|
||||
return NextResponse.json(interview)
|
||||
} catch (error) {
|
||||
console.error('PATCH /api/interviews/[id] error:', error)
|
||||
return NextResponse.json({ error: 'Erreur lors de la mise à jour' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
||||
// DELETE /api/interviews/[id]
|
||||
export async function DELETE(_request: NextRequest, { params }: Params) {
|
||||
try {
|
||||
const { id } = await params
|
||||
await prisma.interview.delete({ where: { id } })
|
||||
return NextResponse.json({ success: true })
|
||||
} catch (error) {
|
||||
console.error('DELETE /api/interviews/[id] error:', error)
|
||||
return NextResponse.json({ error: 'Erreur lors de la suppression' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
27
app/api/interviews/route.ts
Normal file
27
app/api/interviews/route.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import prisma from '../../../lib/prisma'
|
||||
|
||||
// GET /api/interviews
|
||||
export async function GET() {
|
||||
try {
|
||||
const interviews = await prisma.interview.findMany({
|
||||
orderBy: { date: 'desc' },
|
||||
})
|
||||
return NextResponse.json(interviews)
|
||||
} catch (error) {
|
||||
console.error('GET /api/interviews error:', error)
|
||||
return NextResponse.json({ error: 'Erreur serveur' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
||||
// POST /api/interviews
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const body = await request.json()
|
||||
const interview = await prisma.interview.create({ data: body })
|
||||
return NextResponse.json(interview, { status: 201 })
|
||||
} catch (error) {
|
||||
console.error('POST /api/interviews error:', error)
|
||||
return NextResponse.json({ error: 'Erreur lors de la création' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
49
app/api/offers/[id]/route.ts
Normal file
49
app/api/offers/[id]/route.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import prisma from '../../../../lib/prisma'
|
||||
|
||||
type Params = { params: Promise<{ id: string }> }
|
||||
|
||||
// GET /api/offers/[id]
|
||||
export async function GET(_request: NextRequest, { params }: Params) {
|
||||
try {
|
||||
const { id } = await params
|
||||
const offer = await prisma.offer.findUnique({
|
||||
where: { id },
|
||||
include: { business: true },
|
||||
})
|
||||
if (!offer) return NextResponse.json({ error: 'Non trouvé' }, { status: 404 })
|
||||
return NextResponse.json(offer)
|
||||
} catch (error) {
|
||||
console.error('GET /api/offers/[id] error:', error)
|
||||
return NextResponse.json({ error: 'Erreur serveur' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
||||
// PATCH /api/offers/[id]
|
||||
export async function PATCH(request: NextRequest, { params }: Params) {
|
||||
try {
|
||||
const { id } = await params
|
||||
const body = await request.json()
|
||||
const offer = await prisma.offer.update({
|
||||
where: { id },
|
||||
data: body,
|
||||
include: { business: true },
|
||||
})
|
||||
return NextResponse.json(offer)
|
||||
} catch (error) {
|
||||
console.error('PATCH /api/offers/[id] error:', error)
|
||||
return NextResponse.json({ error: 'Erreur lors de la mise à jour' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
||||
// DELETE /api/offers/[id]
|
||||
export async function DELETE(_request: NextRequest, { params }: Params) {
|
||||
try {
|
||||
const { id } = await params
|
||||
await prisma.offer.delete({ where: { id } })
|
||||
return NextResponse.json({ success: true })
|
||||
} catch (error) {
|
||||
console.error('DELETE /api/offers/[id] error:', error)
|
||||
return NextResponse.json({ error: 'Erreur lors de la suppression' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
38
app/api/offers/route.ts
Normal file
38
app/api/offers/route.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import prisma from '../../../lib/prisma'
|
||||
|
||||
// GET /api/offers — optionally filter by businessId
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const { searchParams } = new URL(request.url)
|
||||
const businessId = searchParams.get('businessId')
|
||||
|
||||
const where: Record<string, unknown> = {}
|
||||
if (businessId) where.businessId = businessId
|
||||
|
||||
const offers = await prisma.offer.findMany({
|
||||
where,
|
||||
include: { business: true },
|
||||
orderBy: { createdAt: 'desc' },
|
||||
})
|
||||
return NextResponse.json(offers)
|
||||
} catch (error) {
|
||||
console.error('GET /api/offers error:', error)
|
||||
return NextResponse.json({ error: 'Erreur serveur' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
||||
// POST /api/offers
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const body = await request.json()
|
||||
const offer = await prisma.offer.create({
|
||||
data: body,
|
||||
include: { business: true },
|
||||
})
|
||||
return NextResponse.json(offer, { status: 201 })
|
||||
} catch (error) {
|
||||
console.error('POST /api/offers error:', error)
|
||||
return NextResponse.json({ error: 'Erreur lors de la création' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
28
app/api/users/route.ts
Normal file
28
app/api/users/route.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import prisma from '../../../lib/prisma'
|
||||
|
||||
// GET /api/users
|
||||
export async function GET() {
|
||||
try {
|
||||
const users = await prisma.user.findMany({
|
||||
include: { businesses: true },
|
||||
orderBy: { createdAt: 'desc' },
|
||||
})
|
||||
return NextResponse.json(users)
|
||||
} catch (error) {
|
||||
console.error('GET /api/users error:', error)
|
||||
return NextResponse.json({ error: 'Erreur serveur' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
||||
// POST /api/users
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const body = await request.json()
|
||||
const user = await prisma.user.create({ data: body })
|
||||
return NextResponse.json(user, { status: 201 })
|
||||
} catch (error) {
|
||||
console.error('POST /api/users error:', error)
|
||||
return NextResponse.json({ error: 'Erreur lors de la création' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user