CompetenceTrack v8 - Complete UI/UX redesign, Digital Notebooks, Drawing Canvas, Demo Data Cleanup

Features:
- Complete UI/UX redesign for tablet/stylus optimization
- Digital Notebook system (lined, grid, blank, dotted, music, calligraphy)
- Drawing Canvas with stylus/pen support, pressure sensitivity
- Art class mode with tutorial guides and shape templates
- Demo data one-click cleanup for production transition
- Subject-specific notebook filtering
- Environmental messaging (Papier sparen, Umwelt schützen)
- 44px minimum touch targets for tablet
- No emojis - Lucide icons throughout
- 700+ i18n keys (German/English)
- Notebook types: lined, grid, blank, dotted, music, calligraphy
- Drawing tools: pencil, pen, line, rectangle, circle, eraser
- Undo/redo, color picker, stroke width, export PNG
- Archive/unarchive notebooks
- White backgrounds throughout
- Emerald accent color theme

Backend:
- Notebook CRUD API routes
- Drawing CRUD API routes
- Demo data cleanup API
- Prisma schema with Notebook, NotebookPage, Drawing models
- isDemo flags on all new models
This commit is contained in:
Mustafa Cetin committed 2026-07-29 06:39:40 +00:00
1 parent 456cdf9714
commit 04034dca62
22 files changed
+4716 -53

No files matched your search

@@ -0,0 +1,145 @@
import { NextResponse } from 'next/server';
import { z } from 'zod';
import { db } from '@/lib/db';
import { getSession } from '@/lib/auth';
// ── PUT: Update a page ──
const updatePageSchema = z.object({
textContent: z.string().optional().nullable(),
drawingData: z.string().optional().nullable(),
background: z
.enum(['lined', 'grid', 'blank', 'dotted', 'music'])
.optional(),
isBookmark: z.boolean().optional(),
title: z.string().optional().nullable(),
});
export async function PUT(
request: Request,
{ params }: { params: Promise<{ id: string; pageId: string }> }
) {
try {
const session = await getSession();
if (!session?.user) {
return NextResponse.json({ error: 'Not authenticated' }, { status: 401 });
}
const { id, pageId } = await params;
const page = await db.notebookPage.findUnique({
where: { id: pageId },
include: { notebook: true },
});
if (!page || page.notebookId !== id) {
return NextResponse.json({ error: 'Page not found' }, { status: 404 });
}
if (page.notebook.deletedAt) {
return NextResponse.json(
{ error: 'Notebook has been deleted' },
{ status: 400 }
);
}
if (page.notebook.ownerId !== session.user.id) {
return NextResponse.json({ error: 'Access denied' }, { status: 403 });
}
const body = await request.json();
const parsed = updatePageSchema.safeParse(body);
if (!parsed.success) {
return NextResponse.json(
{ error: 'Validation failed', details: parsed.error.issues },
{ status: 400 }
);
}
const updatedPage = await db.notebookPage.update({
where: { id: pageId },
data: parsed.data,
});
// Audit log
await db.auditLog.create({
data: {
userId: session.user.id,
schoolId: page.notebook.schoolId,
action: 'UPDATE',
entityType: 'NotebookPage',
entityId: pageId,
metadata: JSON.stringify({
notebookId: id,
pageNumber: page.pageNumber,
updatedFields: Object.keys(parsed.data),
}),
},
});
return NextResponse.json(updatedPage);
} catch (error) {
console.error('Notebook page update error:', error);
return NextResponse.json(
{ error: 'Internal server error' },
{ status: 500 }
);
}
}
// ── DELETE: Delete a page ──
export async function DELETE(
request: Request,
{ params }: { params: Promise<{ id: string; pageId: string }> }
) {
try {
const session = await getSession();
if (!session?.user) {
return NextResponse.json({ error: 'Not authenticated' }, { status: 401 });
}
const { id, pageId } = await params;
const page = await db.notebookPage.findUnique({
where: { id: pageId },
include: { notebook: true },
});
if (!page || page.notebookId !== id) {
return NextResponse.json({ error: 'Page not found' }, { status: 404 });
}
if (page.notebook.ownerId !== session.user.id) {
return NextResponse.json({ error: 'Access denied' }, { status: 403 });
}
await db.notebookPage.delete({
where: { id: pageId },
});
// Audit log
await db.auditLog.create({
data: {
userId: session.user.id,
schoolId: page.notebook.schoolId,
action: 'DELETE',
entityType: 'NotebookPage',
entityId: pageId,
metadata: JSON.stringify({
notebookId: id,
pageNumber: page.pageNumber,
}),
},
});
return NextResponse.json({
message: 'Page deleted',
id: pageId,
});
} catch (error) {
console.error('Notebook page delete error:', error);
return NextResponse.json(
{ error: 'Internal server error' },
{ status: 500 }
);
}
}
+157
View File
@@ -0,0 +1,157 @@
import { NextResponse } from 'next/server';
import { z } from 'zod';
import { db } from '@/lib/db';
import { getSession } from '@/lib/auth';
// ── GET: List pages in a notebook ──
export async function GET(
request: Request,
{ params }: { params: Promise<{ id: string }> }
) {
try {
const session = await getSession();
if (!session?.user) {
return NextResponse.json({ error: 'Not authenticated' }, { status: 401 });
}
const { id } = await params;
const notebook = await db.notebook.findUnique({
where: { id, deletedAt: null },
});
if (!notebook) {
return NextResponse.json(
{ error: 'Notebook not found' },
{ status: 404 }
);
}
// Access check
if (
notebook.ownerId !== session.user.id &&
!(notebook.isPublic && notebook.schoolId === session.user.schoolId)
) {
return NextResponse.json({ error: 'Access denied' }, { status: 403 });
}
const pages = await db.notebookPage.findMany({
where: { notebookId: id },
orderBy: { pageNumber: 'asc' },
});
return NextResponse.json(pages);
} catch (error) {
console.error('Notebook pages list error:', error);
return NextResponse.json(
{ error: 'Internal server error' },
{ status: 500 }
);
}
}
// ── POST: Add a new page to a notebook ──
const createPageSchema = z.object({
pageNumber: z.number().int().optional(),
contentType: z.enum(['text', 'drawing', 'mixed']).default('text'),
textContent: z.string().optional().nullable(),
drawingData: z.string().optional().nullable(),
background: z
.enum(['lined', 'grid', 'blank', 'dotted', 'music'])
.default('lined'),
title: z.string().optional().nullable(),
});
export async function POST(
request: Request,
{ params }: { params: Promise<{ id: string }> }
) {
try {
const session = await getSession();
if (!session?.user) {
return NextResponse.json({ error: 'Not authenticated' }, { status: 401 });
}
const { id } = await params;
const notebook = await db.notebook.findUnique({
where: { id, deletedAt: null },
});
if (!notebook) {
return NextResponse.json(
{ error: 'Notebook not found' },
{ status: 404 }
);
}
if (notebook.ownerId !== session.user.id) {
return NextResponse.json({ error: 'Access denied' }, { status: 403 });
}
const body = await request.json();
const parsed = createPageSchema.safeParse(body);
if (!parsed.success) {
return NextResponse.json(
{ error: 'Validation failed', details: parsed.error.issues },
{ status: 400 }
);
}
// Auto-increment pageNumber if not provided
let pageNumber = parsed.data.pageNumber;
if (!pageNumber) {
const maxPage = await db.notebookPage.findFirst({
where: { notebookId: id },
orderBy: { pageNumber: 'desc' },
select: { pageNumber: true },
});
pageNumber = maxPage ? maxPage.pageNumber + 1 : 1;
}
// Use notebook's notebookType as default background if not specified differently
const background =
parsed.data.background ||
(['lined', 'grid', 'blank', 'dotted', 'music'].includes(
notebook.notebookType
)
? notebook.notebookType
: 'lined');
const page = await db.notebookPage.create({
data: {
notebookId: id,
pageNumber,
title: parsed.data.title,
contentType: parsed.data.contentType,
textContent: parsed.data.textContent,
drawingData: parsed.data.drawingData,
background,
},
});
// Audit log
await db.auditLog.create({
data: {
userId: session.user.id,
schoolId: notebook.schoolId,
action: 'CREATE',
entityType: 'NotebookPage',
entityId: page.id,
metadata: JSON.stringify({
notebookId: id,
pageNumber,
contentType: parsed.data.contentType,
}),
},
});
return NextResponse.json(page, { status: 201 });
} catch (error) {
console.error('Notebook page create error:', error);
return NextResponse.json(
{ error: 'Internal server error' },
{ status: 500 }
);
}
}
+194
View File
@@ -0,0 +1,194 @@
import { NextResponse } from 'next/server';
import { z } from 'zod';
import { db } from '@/lib/db';
import { getSession } from '@/lib/auth';
// ── GET: Get a single notebook with its pages ──
export async function GET(
request: Request,
{ params }: { params: Promise<{ id: string }> }
) {
try {
const session = await getSession();
if (!session?.user) {
return NextResponse.json({ error: 'Not authenticated' }, { status: 401 });
}
const { id } = await params;
const notebook = await db.notebook.findUnique({
where: { id, deletedAt: null },
include: {
subject: { select: { id: true, name: true } },
classGroup: { select: { id: true, name: true } },
pages: {
orderBy: { pageNumber: 'asc' },
},
owner: { select: { id: true, firstName: true, lastName: true } },
},
});
if (!notebook) {
return NextResponse.json(
{ error: 'Notebook not found' },
{ status: 404 }
);
}
// Access check: owner or public notebook in the same school
if (
notebook.ownerId !== session.user.id &&
!(notebook.isPublic && notebook.schoolId === session.user.schoolId)
) {
return NextResponse.json({ error: 'Access denied' }, { status: 403 });
}
return NextResponse.json(notebook);
} catch (error) {
console.error('Notebook get error:', error);
return NextResponse.json(
{ error: 'Internal server error' },
{ status: 500 }
);
}
}
// ── PUT: Update notebook ──
const updateNotebookSchema = z.object({
title: z.string().min(1).max(200).optional(),
description: z.string().max(1000).optional().nullable(),
notebookType: z
.enum(['lined', 'grid', 'blank', 'dotted', 'music', 'calligraphy'])
.optional(),
color: z.string().optional(),
icon: z.string().optional().nullable(),
isArchived: z.boolean().optional(),
isPublic: z.boolean().optional(),
sortOrder: z.number().int().optional(),
});
export async function PUT(
request: Request,
{ params }: { params: Promise<{ id: string }> }
) {
try {
const session = await getSession();
if (!session?.user) {
return NextResponse.json({ error: 'Not authenticated' }, { status: 401 });
}
const { id } = await params;
const existing = await db.notebook.findUnique({
where: { id, deletedAt: null },
});
if (!existing) {
return NextResponse.json(
{ error: 'Notebook not found' },
{ status: 404 }
);
}
if (existing.ownerId !== session.user.id) {
return NextResponse.json({ error: 'Access denied' }, { status: 403 });
}
const body = await request.json();
const parsed = updateNotebookSchema.safeParse(body);
if (!parsed.success) {
return NextResponse.json(
{ error: 'Validation failed', details: parsed.error.issues },
{ status: 400 }
);
}
const notebook = await db.notebook.update({
where: { id },
data: parsed.data,
include: {
subject: { select: { id: true, name: true } },
classGroup: { select: { id: true, name: true } },
_count: { select: { pages: true } },
},
});
// Audit log
await db.auditLog.create({
data: {
userId: session.user.id,
schoolId: existing.schoolId,
action: 'UPDATE',
entityType: 'Notebook',
entityId: id,
metadata: JSON.stringify({ updatedFields: Object.keys(parsed.data) }),
},
});
return NextResponse.json(notebook);
} catch (error) {
console.error('Notebook update error:', error);
return NextResponse.json(
{ error: 'Internal server error' },
{ status: 500 }
);
}
}
// ── DELETE: Soft delete notebook ──
export async function DELETE(
request: Request,
{ params }: { params: Promise<{ id: string }> }
) {
try {
const session = await getSession();
if (!session?.user) {
return NextResponse.json({ error: 'Not authenticated' }, { status: 401 });
}
const { id } = await params;
const existing = await db.notebook.findUnique({
where: { id, deletedAt: null },
});
if (!existing) {
return NextResponse.json(
{ error: 'Notebook not found' },
{ status: 404 }
);
}
if (existing.ownerId !== session.user.id) {
return NextResponse.json({ error: 'Access denied' }, { status: 403 });
}
const deleted = await db.notebook.update({
where: { id },
data: { deletedAt: new Date() },
});
// Audit log
await db.auditLog.create({
data: {
userId: session.user.id,
schoolId: existing.schoolId,
action: 'DELETE',
entityType: 'Notebook',
entityId: id,
metadata: JSON.stringify({ title: existing.title }),
},
});
return NextResponse.json({
message: 'Notebook deleted',
id: deleted.id,
});
} catch (error) {
console.error('Notebook delete error:', error);
return NextResponse.json(
{ error: 'Internal server error' },
{ status: 500 }
);
}
}
+137
View File
@@ -0,0 +1,137 @@
import { NextResponse } from 'next/server';
import { z } from 'zod';
import { db } from '@/lib/db';
import { getSession } from '@/lib/auth';
// ── GET: List notebooks for the current user ──
export async function GET(request: Request) {
try {
const session = await getSession();
if (!session?.user) {
return NextResponse.json({ error: 'Not authenticated' }, { status: 401 });
}
const { searchParams } = new URL(request.url);
const schoolId = searchParams.get('schoolId');
const subjectId = searchParams.get('subjectId');
const classGroupId = searchParams.get('classGroupId');
const isArchived = searchParams.get('isArchived');
const where: Record<string, unknown> = {
ownerId: session.user.id,
deletedAt: null,
};
if (schoolId) where.schoolId = schoolId;
if (subjectId) where.subjectId = subjectId;
if (classGroupId) where.classGroupId = classGroupId;
if (isArchived !== null && isArchived !== undefined) {
where.isArchived = isArchived === 'true';
}
// Default schoolId from user session
if (!schoolId && session.user.schoolId) {
where.schoolId = session.user.schoolId;
}
const notebooks = await db.notebook.findMany({
where,
include: {
subject: { select: { id: true, name: true } },
classGroup: { select: { id: true, name: true } },
_count: { select: { pages: true } },
},
orderBy: [{ sortOrder: 'asc' }, { createdAt: 'desc' }],
});
return NextResponse.json(notebooks);
} catch (error) {
console.error('Notebooks list error:', error);
return NextResponse.json(
{ error: 'Internal server error' },
{ status: 500 }
);
}
}
// ── POST: Create a new notebook ──
const createNotebookSchema = z.object({
title: z.string().min(1).max(200),
description: z.string().max(1000).optional().nullable(),
notebookType: z
.enum(['lined', 'grid', 'blank', 'dotted', 'music', 'calligraphy'])
.default('lined'),
color: z.string().default('#10b981'),
icon: z.string().optional().nullable(),
subjectId: z.string().optional().nullable(),
classGroupId: z.string().optional().nullable(),
});
export async function POST(request: Request) {
try {
const session = await getSession();
if (!session?.user) {
return NextResponse.json({ error: 'Not authenticated' }, { status: 401 });
}
const body = await request.json();
const parsed = createNotebookSchema.safeParse(body);
if (!parsed.success) {
return NextResponse.json(
{ error: 'Validation failed', details: parsed.error.issues },
{ status: 400 }
);
}
const { title, description, notebookType, color, icon, subjectId, classGroupId } =
parsed.data;
const schoolId = session.user.schoolId;
if (!schoolId) {
return NextResponse.json(
{ error: 'User must belong to a school to create notebooks' },
{ status: 400 }
);
}
const notebook = await db.notebook.create({
data: {
schoolId,
ownerId: session.user.id,
ownerType: 'TEACHER',
title,
description,
notebookType,
color,
icon,
subjectId,
classGroupId,
},
include: {
subject: { select: { id: true, name: true } },
classGroup: { select: { id: true, name: true } },
_count: { select: { pages: true } },
},
});
// Audit log
await db.auditLog.create({
data: {
userId: session.user.id,
schoolId,
action: 'CREATE',
entityType: 'Notebook',
entityId: notebook.id,
metadata: JSON.stringify({ title }),
},
});
return NextResponse.json(notebook, { status: 201 });
} catch (error) {
console.error('Notebook create error:', error);
return NextResponse.json(
{ error: 'Internal server error' },
{ status: 500 }
);
}
}