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,7 +350,17 @@ export default function CourseDetailPage() {
{selectedLesson ? (
<div className="space-y-6">
<div className="flex items-center justify-between">
{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' :
@@ -293,7 +368,51 @@ export default function CourseDetailPage() {
}`}>
{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 && (
@@ -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
// =============================================================================

View File

@@ -481,6 +481,10 @@ func main() {
// Quiz
academyRoutes.POST("/courses/:id/quiz", academyHandlers.SubmitQuiz)
// Lessons
academyRoutes.PUT("/lessons/:id", academyHandlers.UpdateLesson)
academyRoutes.POST("/lessons/:id/quiz-test", academyHandlers.TestQuiz)
// Statistics
academyRoutes.GET("/stats", academyHandlers.GetStatistics)

View File

@@ -331,6 +331,23 @@ func (s *Store) GetLesson(ctx context.Context, id uuid.UUID) (*Lesson, error) {
return &lesson, nil
}
// UpdateLesson updates a lesson's content, title, and quiz questions
func (s *Store) UpdateLesson(ctx context.Context, lesson *Lesson) error {
quizQuestions, _ := json.Marshal(lesson.QuizQuestions)
_, err := s.pool.Exec(ctx, `
UPDATE academy_lessons SET
title = $2, description = $3, content_url = $4,
duration_minutes = $5, quiz_questions = $6
WHERE id = $1
`,
lesson.ID, lesson.Title, lesson.Description,
lesson.ContentURL, lesson.DurationMinutes, quizQuestions,
)
return err
}
// ============================================================================
// Enrollment Operations
// ============================================================================

View File

@@ -572,6 +572,131 @@ func (h *AcademyHandlers) SubmitQuiz(c *gin.Context) {
c.JSON(http.StatusOK, response)
}
// ============================================================================
// Lesson Update
// ============================================================================
// UpdateLesson updates a lesson's content, title, or quiz questions
// PUT /sdk/v1/academy/lessons/:id
func (h *AcademyHandlers) UpdateLesson(c *gin.Context) {
lessonID, err := uuid.Parse(c.Param("id"))
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid lesson ID"})
return
}
lesson, err := h.store.GetLesson(c.Request.Context(), lessonID)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
if lesson == nil {
c.JSON(http.StatusNotFound, gin.H{"error": "lesson not found"})
return
}
var req struct {
Title *string `json:"title"`
Description *string `json:"description"`
ContentURL *string `json:"content_url"`
DurationMinutes *int `json:"duration_minutes"`
QuizQuestions *[]academy.QuizQuestion `json:"quiz_questions"`
}
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
if req.Title != nil {
lesson.Title = *req.Title
}
if req.Description != nil {
lesson.Description = *req.Description
}
if req.ContentURL != nil {
lesson.ContentURL = *req.ContentURL
}
if req.DurationMinutes != nil {
lesson.DurationMinutes = *req.DurationMinutes
}
if req.QuizQuestions != nil {
lesson.QuizQuestions = *req.QuizQuestions
}
if err := h.store.UpdateLesson(c.Request.Context(), lesson); err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusOK, gin.H{"lesson": lesson})
}
// TestQuiz evaluates quiz answers without requiring an enrollment
// POST /sdk/v1/academy/lessons/:id/quiz-test
func (h *AcademyHandlers) TestQuiz(c *gin.Context) {
lessonID, err := uuid.Parse(c.Param("id"))
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid lesson ID"})
return
}
lesson, err := h.store.GetLesson(c.Request.Context(), lessonID)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
if lesson == nil {
c.JSON(http.StatusNotFound, gin.H{"error": "lesson not found"})
return
}
if len(lesson.QuizQuestions) == 0 {
c.JSON(http.StatusBadRequest, gin.H{"error": "lesson has no quiz questions"})
return
}
var req struct {
Answers []int `json:"answers"`
}
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
if len(req.Answers) != len(lesson.QuizQuestions) {
c.JSON(http.StatusBadRequest, gin.H{"error": "number of answers must match number of questions"})
return
}
correctCount := 0
var results []academy.QuizResult
for i, question := range lesson.QuizQuestions {
correct := req.Answers[i] == question.CorrectIndex
if correct {
correctCount++
}
results = append(results, academy.QuizResult{
Question: question.Question,
Correct: correct,
Explanation: question.Explanation,
})
}
totalQuestions := len(lesson.QuizQuestions)
score := 0
if totalQuestions > 0 {
score = (correctCount * 100) / totalQuestions
}
c.JSON(http.StatusOK, academy.SubmitQuizResponse{
Score: score,
Passed: score >= 70,
CorrectAnswers: correctCount,
TotalQuestions: totalQuestions,
Results: results,
})
}
// ============================================================================
// Statistics
// ============================================================================