feat(flashcards): révision SM-2, génération IA et page /revision
Livre US-FLASHCARDS avec decks, session de révision, stats et migration Prisma. Finalise le Web Clipper (i18n 15 langues) et corrige les erreurs ESLint bloquant la CI. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
37
memento-note/app/api/flashcards/decks/[id]/route.ts
Normal file
37
memento-note/app/api/flashcards/decks/[id]/route.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { auth } from '@/auth'
|
||||
import { getDeckDetail } from '@/lib/flashcards/deck-queries'
|
||||
|
||||
export async function GET(
|
||||
_request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> },
|
||||
) {
|
||||
try {
|
||||
const session = await auth()
|
||||
if (!session?.user?.id) {
|
||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
||||
}
|
||||
|
||||
const { id } = await params
|
||||
const deck = await getDeckDetail(session.user.id, id)
|
||||
if (!deck) {
|
||||
return NextResponse.json({ error: 'Deck not found' }, { status: 404 })
|
||||
}
|
||||
|
||||
const now = new Date()
|
||||
const dueCount = deck.cards.filter((c) => c.due).length
|
||||
const masteredCount = deck.cards.filter((c) => c.mastered).length
|
||||
|
||||
return NextResponse.json({
|
||||
deck,
|
||||
stats: {
|
||||
total: deck.cards.length,
|
||||
due: dueCount,
|
||||
mastered: masteredCount,
|
||||
},
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('[flashcards/decks/[id] GET]', error)
|
||||
return NextResponse.json({ error: 'Failed to load deck' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
51
memento-note/app/api/flashcards/decks/route.ts
Normal file
51
memento-note/app/api/flashcards/decks/route.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { auth } from '@/auth'
|
||||
import { listDeckSummaries } from '@/lib/flashcards/deck-queries'
|
||||
import { getOrCreateDeckForNotebook } from '@/lib/flashcards/deck-utils'
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
const session = await auth()
|
||||
if (!session?.user?.id) {
|
||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
||||
}
|
||||
|
||||
const decks = await listDeckSummaries(session.user.id)
|
||||
return NextResponse.json({ decks })
|
||||
} catch (error) {
|
||||
console.error('[flashcards/decks GET]', error)
|
||||
return NextResponse.json({ error: 'Failed to load decks' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const session = await auth()
|
||||
if (!session?.user?.id) {
|
||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
||||
}
|
||||
|
||||
const body = await request.json()
|
||||
const name = typeof body.name === 'string' ? body.name.trim() : ''
|
||||
if (!name) {
|
||||
return NextResponse.json({ error: 'Name required' }, { status: 400 })
|
||||
}
|
||||
|
||||
const deck = await getOrCreateDeckForNotebook({
|
||||
userId: session.user.id,
|
||||
notebookId: null,
|
||||
manualName: name,
|
||||
})
|
||||
|
||||
return NextResponse.json({
|
||||
deck: {
|
||||
id: deck.id,
|
||||
name: deck.name,
|
||||
notebookId: deck.notebookId,
|
||||
},
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('[flashcards/decks POST]', error)
|
||||
return NextResponse.json({ error: 'Failed to create deck' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user