chore: update devbook.md to mark completion of layout, UI components, and homepage; update dev.db
This commit is contained in:
71
src/app/api/sessions/route.ts
Normal file
71
src/app/api/sessions/route.ts
Normal file
@@ -0,0 +1,71 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { auth } from '@/lib/auth';
|
||||
import { prisma } from '@/services/database';
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
const session = await auth();
|
||||
|
||||
if (!session?.user?.id) {
|
||||
return NextResponse.json({ error: 'Non autorisé' }, { status: 401 });
|
||||
}
|
||||
|
||||
const sessions = await prisma.session.findMany({
|
||||
where: { userId: session.user.id },
|
||||
include: {
|
||||
_count: {
|
||||
select: {
|
||||
items: true,
|
||||
actions: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
orderBy: { updatedAt: 'desc' },
|
||||
});
|
||||
|
||||
return NextResponse.json(sessions);
|
||||
} catch (error) {
|
||||
console.error('Error fetching sessions:', error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Erreur lors de la récupération des sessions' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const session = await auth();
|
||||
|
||||
if (!session?.user?.id) {
|
||||
return NextResponse.json({ error: 'Non autorisé' }, { status: 401 });
|
||||
}
|
||||
|
||||
const body = await request.json();
|
||||
const { title, collaborator } = body;
|
||||
|
||||
if (!title || !collaborator) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Titre et collaborateur requis' },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
const newSession = await prisma.session.create({
|
||||
data: {
|
||||
title,
|
||||
collaborator,
|
||||
userId: session.user.id,
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json(newSession, { status: 201 });
|
||||
} catch (error) {
|
||||
console.error('Error creating session:', error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Erreur lors de la création de la session' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user