Add lesson content editor, quiz test endpoint, and lesson update API
All checks were successful
CI / go-lint (push) Has been skipped
CI / python-lint (push) Has been skipped
CI / nodejs-lint (push) Has been skipped
CI / test-go-ai-compliance (push) Successful in 36s
CI / test-python-backend-compliance (push) Successful in 31s
CI / test-python-document-crawler (push) Successful in 23s
CI / test-python-dsms-gateway (push) Successful in 21s

- Backend: UpdateLesson handler (PUT /lessons/:id) for editing title, content, quiz questions
- Backend: TestQuiz handler (POST /lessons/:id/quiz-test) for quiz evaluation without enrollment
- Frontend: Content editor with markdown textarea, save, and approve-for-video workflow
- Frontend: Fix quiz endpoint to /lessons/:id/quiz-test

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Benjamin Admin
2026-02-26 17:57:15 +01:00
parent 1698912a27
commit 8acf1d2e12
5 changed files with 311 additions and 12 deletions

View File

@@ -18,6 +18,7 @@ import {
fetchEnrollments,
deleteCourse,
submitQuiz,
updateLesson,
generateVideos,
getVideoStatus
} from '@/lib/sdk/academy/api'
@@ -39,6 +40,11 @@ export default function CourseDetailPage() {
const [isSubmittingQuiz, setIsSubmittingQuiz] = useState(false)
const [videoStatus, setVideoStatus] = useState<any>(null)
const [isGeneratingVideos, setIsGeneratingVideos] = useState(false)
const [isEditing, setIsEditing] = useState(false)
const [editContent, setEditContent] = useState('')
const [editTitle, setEditTitle] = useState('')
const [isSaving, setIsSaving] = useState(false)
const [saveMessage, setSaveMessage] = useState<{ type: 'success' | 'error', text: string } | null>(null)
useEffect(() => {
const loadData = async () => {
@@ -89,6 +95,65 @@ export default function CourseDetailPage() {
}
}
const handleStartEdit = () => {
if (!selectedLesson) return
setEditContent(selectedLesson.contentMarkdown || '')
setEditTitle(selectedLesson.title || '')
setIsEditing(true)
setSaveMessage(null)
}
const handleCancelEdit = () => {
setIsEditing(false)
setSaveMessage(null)
}
const handleSaveLesson = async () => {
if (!selectedLesson) return
setIsSaving(true)
setSaveMessage(null)
try {
await updateLesson(selectedLesson.id, {
title: editTitle,
content_url: editContent,
})
const updatedLesson = { ...selectedLesson, title: editTitle, contentMarkdown: editContent }
setSelectedLesson(updatedLesson)
if (course) {
const updatedLessons = course.lessons.map(l => l.id === updatedLesson.id ? updatedLesson : l)
setCourse({ ...course, lessons: updatedLessons })
}
setIsEditing(false)
setSaveMessage({ type: 'success', text: 'Lektion gespeichert.' })
} catch (error: any) {
setSaveMessage({ type: 'error', text: error.message || 'Fehler beim Speichern.' })
} finally {
setIsSaving(false)
}
}
const handleApproveLesson = async () => {
if (!selectedLesson) return
if (!confirm('Lektion fuer Video-Verarbeitung freigeben? Der Text wird als final markiert.')) return
setIsSaving(true)
setSaveMessage(null)
try {
await updateLesson(selectedLesson.id, {
description: 'approved_for_video',
})
const updatedLesson = { ...selectedLesson }
if (course) {
const updatedLessons = course.lessons.map(l => l.id === updatedLesson.id ? updatedLesson : l)
setCourse({ ...course, lessons: updatedLessons })
}
setSaveMessage({ type: 'success', text: 'Lektion fuer Video-Verarbeitung freigegeben.' })
} catch (error: any) {
setSaveMessage({ type: 'error', text: error.message || 'Fehler bei der Freigabe.' })
} finally {
setIsSaving(false)
}
}
const handleGenerateVideos = async () => {
setIsGeneratingVideos(true)
try {
@@ -285,16 +350,70 @@ export default function CourseDetailPage() {
{selectedLesson ? (
<div className="space-y-6">
<div className="flex items-center justify-between">
<h2 className="text-xl font-semibold text-gray-900">{selectedLesson.title}</h2>
<span className={`px-3 py-1 text-xs rounded-full ${
selectedLesson.type === 'quiz' ? 'bg-yellow-100 text-yellow-700' :
selectedLesson.type === 'video' ? 'bg-blue-100 text-blue-700' :
'bg-gray-100 text-gray-600'
}`}>
{selectedLesson.type === 'quiz' ? 'Quiz' : selectedLesson.type === 'video' ? 'Video' : 'Text'}
</span>
{isEditing ? (
<input
type="text"
value={editTitle}
onChange={e => setEditTitle(e.target.value)}
className="text-xl font-semibold text-gray-900 border border-gray-300 rounded-lg px-3 py-1 flex-1 mr-3"
/>
) : (
<h2 className="text-xl font-semibold text-gray-900">{selectedLesson.title}</h2>
)}
<div className="flex items-center gap-2">
<span className={`px-3 py-1 text-xs rounded-full ${
selectedLesson.type === 'quiz' ? 'bg-yellow-100 text-yellow-700' :
selectedLesson.type === 'video' ? 'bg-blue-100 text-blue-700' :
'bg-gray-100 text-gray-600'
}`}>
{selectedLesson.type === 'quiz' ? 'Quiz' : selectedLesson.type === 'video' ? 'Video' : 'Text'}
</span>
{selectedLesson.type !== 'quiz' && !isEditing && (
<>
<button
onClick={handleStartEdit}
className="px-3 py-1 text-sm bg-gray-100 text-gray-700 rounded-lg hover:bg-gray-200 transition-colors"
>
Bearbeiten
</button>
<button
onClick={handleApproveLesson}
disabled={isSaving}
className="px-3 py-1 text-sm bg-green-600 text-white rounded-lg hover:bg-green-700 transition-colors disabled:opacity-50"
>
Freigeben
</button>
</>
)}
{isEditing && (
<>
<button
onClick={handleCancelEdit}
className="px-3 py-1 text-sm bg-gray-100 text-gray-700 rounded-lg hover:bg-gray-200 transition-colors"
>
Abbrechen
</button>
<button
onClick={handleSaveLesson}
disabled={isSaving}
className="px-3 py-1 text-sm bg-purple-600 text-white rounded-lg hover:bg-purple-700 transition-colors disabled:opacity-50"
>
{isSaving ? 'Speichert...' : 'Speichern'}
</button>
</>
)}
</div>
</div>
{/* Save/Approve Message */}
{saveMessage && (
<div className={`p-3 rounded-lg text-sm ${
saveMessage.type === 'success' ? 'bg-green-50 text-green-700 border border-green-200' : 'bg-red-50 text-red-700 border border-red-200'
}`}>
{saveMessage.text}
</div>
)}
{/* Video Player */}
{selectedLesson.type === 'video' && selectedLesson.videoUrl && (
<div className="aspect-video bg-gray-900 rounded-xl overflow-hidden">
@@ -306,8 +425,23 @@ export default function CourseDetailPage() {
</div>
)}
{/* Text Content */}
{(selectedLesson.type === 'text' || selectedLesson.type === 'video') && selectedLesson.contentMarkdown && (
{/* Text Content - Edit Mode */}
{isEditing && (selectedLesson.type === 'text' || selectedLesson.type === 'video') && (
<div className="space-y-2">
<label className="text-sm text-gray-500">Inhalt (Markdown)</label>
<textarea
value={editContent}
onChange={e => setEditContent(e.target.value)}
rows={20}
className="w-full border border-gray-300 rounded-xl p-4 text-sm font-mono text-gray-800 leading-relaxed resize-y focus:ring-2 focus:ring-purple-500 focus:border-transparent"
placeholder="Markdown-Inhalt der Lektion..."
/>
<p className="text-xs text-gray-400">Unterstuetzt: # Ueberschrift, ## Unterueberschrift, - Aufzaehlung, **fett**</p>
</div>
)}
{/* Text Content - View Mode */}
{!isEditing && (selectedLesson.type === 'text' || selectedLesson.type === 'video') && selectedLesson.contentMarkdown && (
<div className="prose prose-sm max-w-none">
<div className="whitespace-pre-wrap text-gray-700 leading-relaxed">
{selectedLesson.contentMarkdown.split('\n').map((line, i) => {

View File

@@ -321,11 +321,11 @@ export async function generateCertificate(enrollmentId: string): Promise<Certifi
// =============================================================================
/**
* Quiz-Antworten einreichen und auswerten
* Quiz-Antworten einreichen und auswerten (ohne Enrollment)
*/
export async function submitQuiz(lessonId: string, answers: SubmitQuizRequest): Promise<SubmitQuizResponse> {
return fetchWithTimeout<SubmitQuizResponse>(
`${ACADEMY_API_BASE}/lessons/${lessonId}/quiz`,
`${ACADEMY_API_BASE}/lessons/${lessonId}/quiz-test`,
{
method: 'POST',
body: JSON.stringify(answers)
@@ -333,6 +333,25 @@ export async function submitQuiz(lessonId: string, answers: SubmitQuizRequest):
)
}
/**
* Lektion aktualisieren (Content, Titel, Quiz-Fragen)
*/
export async function updateLesson(lessonId: string, update: {
title?: string
description?: string
content_url?: string
duration_minutes?: number
quiz_questions?: Array<{ question: string; options: string[]; correct_index: number; explanation: string }>
}): Promise<{ lesson: any }> {
return fetchWithTimeout(
`${ACADEMY_API_BASE}/lessons/${lessonId}`,
{
method: 'PUT',
body: JSON.stringify(update)
}
)
}
// =============================================================================
// STATISTICS
// =============================================================================