From 14966ded7f60891f208cff6727fb90c4fecf3889 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 9 Jun 2026 16:38:21 +0000 Subject: [PATCH 1/4] Initial plan From 1f8414916f55d54047967b8379bcfbd683b064b6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 9 Jun 2026 16:47:00 +0000 Subject: [PATCH 2/4] feat: add active user controls for exams --- api/admin.go | 38 +- api/auth.go | 11 +- api/exam.go | 49 +- api/exam_test.go | 63 +- api/handlers.go | 26 +- api/handlers_test.go | 71 ++ api/phase3_test.go | 40 + database/analytics.go | 3 +- database/database.go | 725 +++++++++--------- database/exam.go | 12 +- .../004_add_user_is_active.down.sql | 18 + .../migrations/004_add_user_is_active.up.sql | 1 + database/user.go | 27 +- models/models.go | 36 +- static/admin.html | 5 + static/js/admin/exams-page.js | 4 +- static/js/admin/users.js | 8 +- 17 files changed, 721 insertions(+), 416 deletions(-) create mode 100644 database/migrations/004_add_user_is_active.down.sql create mode 100644 database/migrations/004_add_user_is_active.up.sql diff --git a/api/admin.go b/api/admin.go index 47302cf..3e49567 100644 --- a/api/admin.go +++ b/api/admin.go @@ -37,6 +37,10 @@ func (h *Handler) AdminMiddleware(next http.HandlerFunc) http.HandlerFunc { http.Error(w, "Forbidden: Admin access required", http.StatusForbidden) return } + if !user.IsActive { + http.Error(w, "Forbidden: Inactive user", http.StatusForbidden) + return + } next(w, r) } @@ -79,12 +83,42 @@ func (h *Handler) UpdateUserHandler(w http.ResponseWriter, r *http.Request) { return } - var user models.User - if err := json.NewDecoder(r.Body).Decode(&user); err != nil { + var body struct { + Username string `json:"username"` + Email string `json:"email"` + Password string `json:"password"` + IsAdmin bool `json:"is_admin"` + IsActive *bool `json:"is_active"` + Category string `json:"category"` + TotalPoints int `json:"total_points"` + } + if err := json.NewDecoder(r.Body).Decode(&body); err != nil { http.Error(w, err.Error(), http.StatusBadRequest) return } + existing, err := h.db.GetUser(id) + if err != nil { + if err == database.ErrNotFound { + http.Error(w, "User not found", http.StatusNotFound) + return + } + h.logger.WithContext(r.Context()).WithError(err).Error("Failed to get user for update") + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + user := *existing + user.Username = body.Username + user.Email = body.Email + user.Password = body.Password + user.IsAdmin = body.IsAdmin + user.Category = body.Category + user.TotalPoints = body.TotalPoints + if body.IsActive != nil { + user.IsActive = *body.IsActive + } + // Hash password if provided if user.Password != "" { hashedPassword, err := hashPassword(user.Password) diff --git a/api/auth.go b/api/auth.go index 847644b..9d4d2aa 100644 --- a/api/auth.go +++ b/api/auth.go @@ -86,6 +86,8 @@ func (h *Handler) RegisterHandler(w http.ResponseWriter, r *http.Request) { Email: req.Email, Password: hashedPassword, IsAdmin: false, + IsActive: true, + IsActiveSet: true, TotalPoints: 0, CreatedAt: time.Now(), } @@ -93,8 +95,8 @@ func (h *Handler) RegisterHandler(w http.ResponseWriter, r *http.Request) { // Try to create the user in SQLite database if sqlDB, ok := h.db.(*database.SQLiteDB); ok { result, err := sqlDB.DB().Exec( - "INSERT INTO users (username, email, password, is_admin, total_points, created_at) VALUES (?, ?, ?, ?, ?, ?)", - user.Username, user.Email, user.Password, user.IsAdmin, user.TotalPoints, user.CreatedAt, + "INSERT INTO users (username, email, password, is_admin, is_active, total_points, created_at) VALUES (?, ?, ?, ?, ?, ?, ?)", + user.Username, user.Email, user.Password, user.IsAdmin, user.IsActive, user.TotalPoints, user.CreatedAt, ) if err != nil { h.logger.WithContext(r.Context()).WithFields(map[string]interface{}{ @@ -192,6 +194,11 @@ func (h *Handler) LoginHandler(w http.ResponseWriter, r *http.Request) { http.Error(w, "Invalid username or password", http.StatusUnauthorized) return } + if !user.IsActive { + h.logger.LogAuthentication(r.Context(), req.Username, false, "inactive user") + http.Error(w, "Account is inactive", http.StatusUnauthorized) + return + } // Log successful authentication h.logger.LogAuthentication(r.Context(), req.Username, true, "") diff --git a/api/exam.go b/api/exam.go index cae24e1..09f45a0 100644 --- a/api/exam.go +++ b/api/exam.go @@ -279,24 +279,39 @@ func (h *Handler) StartExamHandler(w http.ResponseWriter, r *http.Request) { return } - // Verify the exam is assigned to this user - assignedExams, err := h.db.GetAssignedExamsForUser(userID) + user, err := h.db.GetUser(userID) if err != nil { + if err == database.ErrNotFound { + http.Error(w, "User not found", http.StatusNotFound) + return + } http.Error(w, err.Error(), http.StatusInternalServerError) return } - assigned := false - for _, ae := range assignedExams { - if ae.ExamID == exam.ID { - assigned = true - break - } - } - if !assigned { - http.Error(w, "Exam not assigned to this user", http.StatusForbidden) + if !user.IsActive { + http.Error(w, "User account is inactive", http.StatusForbidden) return } + if !user.IsAdmin { + assignedExams, err := h.db.GetAssignedExamsForUser(userID) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + assigned := false + for _, ae := range assignedExams { + if ae.ExamID == exam.ID { + assigned = true + break + } + } + if !assigned { + http.Error(w, "Exam not assigned to this user", http.StatusForbidden) + return + } + } + // Build question list with answers type examAnswer struct { ID int `json:"id"` @@ -400,12 +415,12 @@ func (h *Handler) SubmitExamHandler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") json.NewEncoder(w).Encode(map[string]interface{}{ - "attempt_id": attempt.ID, - "exam_id": attempt.ExamID, - "score": attempt.Score, - "correct_answers": attempt.CorrectAnswers, - "total_questions": attempt.TotalQuestions, - "completed_at": attempt.CompletedAt, + "attempt_id": attempt.ID, + "exam_id": attempt.ExamID, + "score": attempt.Score, + "correct_answers": attempt.CorrectAnswers, + "total_questions": attempt.TotalQuestions, + "completed_at": attempt.CompletedAt, "question_results": attempt.QuestionResults, }) } diff --git a/api/exam_test.go b/api/exam_test.go index 8f28877..e5fb45b 100644 --- a/api/exam_test.go +++ b/api/exam_test.go @@ -32,7 +32,7 @@ func setupExamDB(t *testing.T) (*database.InMemoryDB, *models.User, *models.User q := &models.Question{ TopicID: topic.ID, QuestionText: fmt.Sprintf("Question %d?", i), - Difficulty: i % 3 + 1, // cycles through 2,3,1 + Difficulty: i%3 + 1, // cycles through 2,3,1 Tags: []string{"java"}, TopicQuestionID: fmt.Sprintf("%d.%d", topic.ID, i), IsActive: true, @@ -167,6 +167,44 @@ func TestAssignExamToStudentsHandler(t *testing.T) { } } +func TestAssignExamToStudentsHandler_InactiveStudentRejected(t *testing.T) { + db, admin, student := setupExamDB(t) + handler := NewHandler(db) + + student.IsActive = false + if err := db.UpdateUser(student); err != nil { + t.Fatalf("failed to deactivate student: %v", err) + } + + exam := &models.Exam{ + Name: "Assigned Exam", Categories: []string{"java"}, DifficultyLevels: []int{1}, + QuestionIDs: []int{1}, QuestionCount: 1, AccessToken: "inactive-token", + CreatedBy: admin.ID, CreatedAt: time.Now(), + } + db.CreateExam(exam) + + body, _ := json.Marshal(map[string]interface{}{ + "user_ids": []int{student.ID}, + }) + + req := httptest.NewRequest(http.MethodPost, fmt.Sprintf("/instructor/exams/assign?exam_id=%d", exam.ID), bytes.NewBuffer(body)) + req.Header.Set("Content-Type", "application/json") + req.Header.Set("X-User-ID", fmt.Sprintf("%d", admin.ID)) + w := httptest.NewRecorder() + + handler.AssignExamToStudentsHandler(w, req) + + if w.Code != http.StatusOK { + t.Fatalf("Expected status 200, got %d: %s", w.Code, w.Body.String()) + } + + var result map[string]interface{} + json.NewDecoder(w.Body).Decode(&result) + if result["assigned"].(float64) != 0 { + t.Errorf("Expected assigned=0, got %v", result["assigned"]) + } +} + func TestGetAssignedExamsHandler(t *testing.T) { db, admin, student := setupExamDB(t) handler := NewHandler(db) @@ -263,6 +301,29 @@ func TestStartExamHandler_NotAssigned(t *testing.T) { } } +func TestStartExamHandler_AllowsAdminPreview(t *testing.T) { + db, admin, student := setupExamDB(t) + handler := NewHandler(db) + + exam := &models.Exam{ + Name: "Preview Exam", Categories: []string{"java"}, DifficultyLevels: []int{1, 2, 3}, + QuestionIDs: []int{1}, QuestionCount: 1, AccessToken: "preview-token", + CreatedBy: admin.ID, CreatedAt: time.Now(), + } + db.CreateExam(exam) + db.AssignExamToUser(exam.ID, student.ID, admin.ID) + + req := httptest.NewRequest(http.MethodPost, + fmt.Sprintf("/exam/start?token=%s&user_id=%d", exam.AccessToken, admin.ID), nil) + w := httptest.NewRecorder() + + handler.StartExamHandler(w, req) + + if w.Code != http.StatusOK { + t.Fatalf("Expected status 200, got %d: %s", w.Code, w.Body.String()) + } +} + func TestSubmitExamHandler(t *testing.T) { db, admin, student := setupExamDB(t) handler := NewHandler(db) diff --git a/api/handlers.go b/api/handlers.go index 0b216af..de12690 100644 --- a/api/handlers.go +++ b/api/handlers.go @@ -46,12 +46,34 @@ func (h *Handler) CreateUserHandler(w http.ResponseWriter, r *http.Request) { return } - var user models.User - if err := json.NewDecoder(r.Body).Decode(&user); err != nil { + var body struct { + Username string `json:"username"` + Email string `json:"email"` + Password string `json:"password"` + IsAdmin bool `json:"is_admin"` + IsActive *bool `json:"is_active"` + Category string `json:"category"` + TotalPoints int `json:"total_points"` + } + if err := json.NewDecoder(r.Body).Decode(&body); err != nil { http.Error(w, err.Error(), http.StatusBadRequest) return } + user := models.User{ + Username: body.Username, + Email: body.Email, + Password: body.Password, + IsAdmin: body.IsAdmin, + IsActive: true, + IsActiveSet: body.IsActive != nil, + Category: body.Category, + TotalPoints: body.TotalPoints, + } + if body.IsActive != nil { + user.IsActive = *body.IsActive + } + // Hash password if provided if user.Password != "" { hashedPassword, err := hashPassword(user.Password) diff --git a/api/handlers_test.go b/api/handlers_test.go index 7760641..820218b 100644 --- a/api/handlers_test.go +++ b/api/handlers_test.go @@ -833,6 +833,77 @@ func TestUpdateUserPasswordHashing(t *testing.T) { } } +func TestInactiveUserCannotLoginAfterAdminUpdate(t *testing.T) { + tmpDir := t.TempDir() + dbPath := tmpDir + "/test_inactive_login.db" + + db, err := database.NewSQLiteDB(dbPath) + if err != nil { + t.Fatalf("Failed to create SQLite database: %v", err) + } + defer db.Close() + + handler := NewHandler(db) + + admin := &models.User{ + Username: "admin", + Email: "admin@example.com", + Password: "ignored", + IsAdmin: true, + IsActive: true, + IsActiveSet: true, + CreatedAt: time.Now(), + } + if err := db.CreateUser(admin); err != nil { + t.Fatalf("failed to create admin: %v", err) + } + + createBody, _ := json.Marshal(models.User{ + Username: "inactive-user", + Email: "inactive@example.com", + Password: "password123", + }) + createReq := httptest.NewRequest(http.MethodPost, "/users", bytes.NewBuffer(createBody)) + createW := httptest.NewRecorder() + handler.CreateUserHandler(createW, createReq) + if createW.Code != http.StatusCreated { + t.Fatalf("Expected status %d, got %d. Body: %s", http.StatusCreated, createW.Code, createW.Body.String()) + } + + var created models.User + if err := json.NewDecoder(createW.Body).Decode(&created); err != nil { + t.Fatalf("failed to decode created user: %v", err) + } + + updateBody, _ := json.Marshal(map[string]interface{}{ + "username": created.Username, + "email": created.Email, + "is_admin": false, + "is_active": false, + "category": created.Category, + "total_points": created.TotalPoints, + }) + updateReq := httptest.NewRequest(http.MethodPut, "/admin/users?id="+strconv.Itoa(created.ID), bytes.NewBuffer(updateBody)) + updateReq.Header.Set("X-User-ID", strconv.Itoa(admin.ID)) + updateW := httptest.NewRecorder() + handler.AdminMiddleware(handler.UpdateUserHandler)(updateW, updateReq) + if updateW.Code != http.StatusOK { + t.Fatalf("Expected status %d, got %d. Body: %s", http.StatusOK, updateW.Code, updateW.Body.String()) + } + + loginBody, _ := json.Marshal(LoginRequest{ + Username: created.Username, + Password: "password123", + }) + loginReq := httptest.NewRequest(http.MethodPost, "/auth/login", bytes.NewBuffer(loginBody)) + loginW := httptest.NewRecorder() + handler.LoginHandler(loginW, loginReq) + + if loginW.Code != http.StatusUnauthorized { + t.Fatalf("Expected status %d, got %d. Body: %s", http.StatusUnauthorized, loginW.Code, loginW.Body.String()) + } +} + // Test: Verify dashboard stats are per-user, not aggregate (GitHub Issue #74) // This test explicitly validates that each user sees only their own stats func TestDashboardStatsArePerUser(t *testing.T) { diff --git a/api/phase3_test.go b/api/phase3_test.go index 258f0e8..bbbb1fa 100644 --- a/api/phase3_test.go +++ b/api/phase3_test.go @@ -826,6 +826,46 @@ func TestListStudents(t *testing.T) { } } +func TestListStudentsFiltersInactiveUsers(t *testing.T) { + db := database.NewInMemoryDB() + handler := NewHandler(db) + + admin := &models.User{Username: "admin", Email: "admin@test.com", IsAdmin: true, CreatedAt: time.Now()} + db.CreateUser(admin) + + activeStudent := &models.User{Username: "active", Email: "active@test.com", CreatedAt: time.Now()} + db.CreateUser(activeStudent) + + inactiveStudent := &models.User{Username: "inactive", Email: "inactive@test.com", CreatedAt: time.Now()} + db.CreateUser(inactiveStudent) + inactiveStudent.IsActive = false + if err := db.UpdateUser(inactiveStudent); err != nil { + t.Fatalf("failed to update inactive student: %v", err) + } + + req := httptest.NewRequest("GET", "/instructor/students", nil) + req.Header.Set("X-User-ID", "1") + w := httptest.NewRecorder() + + handler.AdminMiddleware(handler.ListStudentsHandler)(w, req) + + if w.Code != http.StatusOK { + t.Fatalf("Expected status 200, got %d", w.Code) + } + + var students []*models.StudentProgress + if err := json.NewDecoder(w.Body).Decode(&students); err != nil { + t.Fatalf("failed to decode students: %v", err) + } + + if len(students) != 1 { + t.Fatalf("Expected 1 active student, got %d", len(students)) + } + if students[0].Username != activeStudent.Username { + t.Fatalf("Expected active student %q, got %q", activeStudent.Username, students[0].Username) + } +} + func TestSearchStudents(t *testing.T) { db := database.NewInMemoryDB() handler := NewHandler(db) diff --git a/database/analytics.go b/database/analytics.go index b3cc0f3..1f9bbd3 100644 --- a/database/analytics.go +++ b/database/analytics.go @@ -236,7 +236,7 @@ func (db *SQLiteDB) GetCohortAnalytics() (*models.CohortAnalytics, error) { func (db *SQLiteDB) ListStudentsWithMetrics(searchQuery string, sortBy string, filterCohort string) ([]*models.StudentProgress, error) { // Get all non-admin users - query := "SELECT id FROM users WHERE is_admin = 0" + query := "SELECT id FROM users WHERE is_admin = 0 AND is_active = 1" args := []interface{}{} // Add search filter if provided @@ -562,4 +562,3 @@ func (db *SQLiteDB) UpdateQuestionDifficultyFromAnalytics(questionID int, newDif _, err := db.db.Exec("UPDATE questions SET difficulty = ? WHERE id = ?", newDifficulty, questionID) return err } - diff --git a/database/database.go b/database/database.go index d6a9e49..bf2ee62 100644 --- a/database/database.go +++ b/database/database.go @@ -316,6 +316,9 @@ func (db *InMemoryDB) CreateUser(user *models.User) error { db.mu.Lock() defer db.mu.Unlock() + if !user.IsActiveSet { + user.IsActive = true + } user.ID = db.nextUserID db.nextUserID++ db.users[user.ID] = user @@ -1336,7 +1339,7 @@ func (db *InMemoryDB) ListStudentsWithMetrics(searchQuery string, sortBy string, for _, user := range db.users { // Skip admin users - if user.IsAdmin { + if user.IsAdmin || !user.IsActive { continue } @@ -2559,438 +2562,448 @@ func (db *InMemoryDB) AutoFlagQuestions() error { // AssignedQuiz operations (InMemoryDB) func (db *InMemoryDB) AssignQuizToUser(quizID, userID, assignedBy int) error { -db.mu.Lock() -defer db.mu.Unlock() + db.mu.Lock() + defer db.mu.Unlock() -// Check if already assigned -for _, aq := range db.assignedQuizzes { -if aq.QuizID == quizID && aq.UserID == userID { -return nil // already assigned, idempotent -} -} + // Check if already assigned + for _, aq := range db.assignedQuizzes { + if aq.QuizID == quizID && aq.UserID == userID { + return nil // already assigned, idempotent + } + } -aq := &models.AssignedQuiz{ -ID: db.nextAssignedQuizID, -QuizID: quizID, -UserID: userID, -AssignedAt: time.Now(), -AssignedBy: assignedBy, -} -db.nextAssignedQuizID++ -db.assignedQuizzes[aq.ID] = aq -return nil + aq := &models.AssignedQuiz{ + ID: db.nextAssignedQuizID, + QuizID: quizID, + UserID: userID, + AssignedAt: time.Now(), + AssignedBy: assignedBy, + } + db.nextAssignedQuizID++ + db.assignedQuizzes[aq.ID] = aq + return nil } func (db *InMemoryDB) UnassignQuizFromUser(quizID, userID int) error { -db.mu.Lock() -defer db.mu.Unlock() + db.mu.Lock() + defer db.mu.Unlock() -for id, aq := range db.assignedQuizzes { -if aq.QuizID == quizID && aq.UserID == userID { -delete(db.assignedQuizzes, id) -return nil -} -} -return ErrNotFound + for id, aq := range db.assignedQuizzes { + if aq.QuizID == quizID && aq.UserID == userID { + delete(db.assignedQuizzes, id) + return nil + } + } + return ErrNotFound } func (db *InMemoryDB) GetAssignedQuizzesForUser(userID int) ([]*models.AssignedQuizInfo, error) { -db.mu.RLock() -defer db.mu.RUnlock() - -var result []*models.AssignedQuizInfo -for _, aq := range db.assignedQuizzes { -if aq.UserID != userID { -continue -} + db.mu.RLock() + defer db.mu.RUnlock() -quiz, exists := db.quizzes[aq.QuizID] -if !exists { -continue -} + var result []*models.AssignedQuizInfo + for _, aq := range db.assignedQuizzes { + if aq.UserID != userID { + continue + } -info := &models.AssignedQuizInfo{ -AssignedQuiz: *aq, -QuizName: quiz.Name, -QuizDescription: quiz.Description, -QuizCategory: quiz.Category, -} + quiz, exists := db.quizzes[aq.QuizID] + if !exists { + continue + } -// Find the latest completed quiz attempt for this quiz+user -for _, attempt := range db.quizAttempts { -if attempt.QuizID != nil && *attempt.QuizID == aq.QuizID && attempt.UserID == userID && attempt.CompletedTime != nil { -if info.CompletedAt == nil || attempt.CompletedTime.After(*info.CompletedAt) { -info.CompletedAt = attempt.CompletedTime -ca := attempt.CorrectAnswers -tq := attempt.TotalQuestions -info.CorrectAnswers = &ca -info.TotalQuestions = &tq -if tq > 0 { -score := float64(ca) / float64(tq) * 100.0 -info.Score = &score -} -} -} -} + info := &models.AssignedQuizInfo{ + AssignedQuiz: *aq, + QuizName: quiz.Name, + QuizDescription: quiz.Description, + QuizCategory: quiz.Category, + } + + // Find the latest completed quiz attempt for this quiz+user + for _, attempt := range db.quizAttempts { + if attempt.QuizID != nil && *attempt.QuizID == aq.QuizID && attempt.UserID == userID && attempt.CompletedTime != nil { + if info.CompletedAt == nil || attempt.CompletedTime.After(*info.CompletedAt) { + info.CompletedAt = attempt.CompletedTime + ca := attempt.CorrectAnswers + tq := attempt.TotalQuestions + info.CorrectAnswers = &ca + info.TotalQuestions = &tq + if tq > 0 { + score := float64(ca) / float64(tq) * 100.0 + info.Score = &score + } + } + } + } -result = append(result, info) -} -return result, nil + result = append(result, info) + } + return result, nil } func (db *InMemoryDB) GetAssignedQuizUserIDs(quizID int) ([]int, error) { -db.mu.RLock() -defer db.mu.RUnlock() + db.mu.RLock() + defer db.mu.RUnlock() -var userIDs []int -for _, aq := range db.assignedQuizzes { -if aq.QuizID == quizID { -userIDs = append(userIDs, aq.UserID) -} -} -return userIDs, nil + var userIDs []int + for _, aq := range db.assignedQuizzes { + if aq.QuizID == quizID { + userIDs = append(userIDs, aq.UserID) + } + } + return userIDs, nil } func (db *InMemoryDB) GetAssignedQuizStatus(quizID int) (*models.AssignedQuizStatus, error) { -db.mu.RLock() -defer db.mu.RUnlock() - -quiz, exists := db.quizzes[quizID] -if !exists { -return nil, ErrNotFound -} + db.mu.RLock() + defer db.mu.RUnlock() -status := &models.AssignedQuizStatus{ -QuizID: quiz.ID, -QuizName: quiz.Name, -QuizCategory: quiz.Category, -QuizDescription: quiz.Description, -StudentResults: []models.AssignedQuizStudentResult{}, -} + quiz, exists := db.quizzes[quizID] + if !exists { + return nil, ErrNotFound + } -for _, aq := range db.assignedQuizzes { -if aq.QuizID != quizID { -continue -} + status := &models.AssignedQuizStatus{ + QuizID: quiz.ID, + QuizName: quiz.Name, + QuizCategory: quiz.Category, + QuizDescription: quiz.Description, + StudentResults: []models.AssignedQuizStudentResult{}, + } -user, exists := db.users[aq.UserID] -if !exists { -continue -} + for _, aq := range db.assignedQuizzes { + if aq.QuizID != quizID { + continue + } -r := models.AssignedQuizStudentResult{ -UserID: user.ID, -Username: user.Username, -AssignedAt: aq.AssignedAt, -} + user, exists := db.users[aq.UserID] + if !exists { + continue + } -// Find latest completed attempt -for _, attempt := range db.quizAttempts { -if attempt.QuizID != nil && *attempt.QuizID == quizID && attempt.UserID == aq.UserID && attempt.CompletedTime != nil { -if r.CompletedAt == nil || attempt.CompletedTime.After(*r.CompletedAt) { -r.CompletedAt = attempt.CompletedTime -ca := attempt.CorrectAnswers -tq := attempt.TotalQuestions -r.CorrectAnswers = &ca -r.TotalQuestions = &tq -if tq > 0 { -score := float64(ca) / float64(tq) * 100.0 -r.Score = &score -} -} -} -} + r := models.AssignedQuizStudentResult{ + UserID: user.ID, + Username: user.Username, + AssignedAt: aq.AssignedAt, + } + + // Find latest completed attempt + for _, attempt := range db.quizAttempts { + if attempt.QuizID != nil && *attempt.QuizID == quizID && attempt.UserID == aq.UserID && attempt.CompletedTime != nil { + if r.CompletedAt == nil || attempt.CompletedTime.After(*r.CompletedAt) { + r.CompletedAt = attempt.CompletedTime + ca := attempt.CorrectAnswers + tq := attempt.TotalQuestions + r.CorrectAnswers = &ca + r.TotalQuestions = &tq + if tq > 0 { + score := float64(ca) / float64(tq) * 100.0 + r.Score = &score + } + } + } + } -status.StudentResults = append(status.StudentResults, r) -} + status.StudentResults = append(status.StudentResults, r) + } -return status, nil + return status, nil } func (db *InMemoryDB) ListAssignedQuizzes() ([]*models.AssignedQuiz, error) { -db.mu.RLock() -defer db.mu.RUnlock() + db.mu.RLock() + defer db.mu.RUnlock() -result := make([]*models.AssignedQuiz, 0, len(db.assignedQuizzes)) -for _, aq := range db.assignedQuizzes { -result = append(result, aq) -} -return result, nil + result := make([]*models.AssignedQuiz, 0, len(db.assignedQuizzes)) + for _, aq := range db.assignedQuizzes { + result = append(result, aq) + } + return result, nil } // ---- InMemoryDB implementation of ExamRepository ---- func (db *InMemoryDB) CreateExam(exam *models.Exam) error { -db.mu.Lock() -defer db.mu.Unlock() -exam.ID = db.nextExamID -db.nextExamID++ -cp := *exam -db.exams[cp.ID] = &cp -return nil + db.mu.Lock() + defer db.mu.Unlock() + exam.ID = db.nextExamID + db.nextExamID++ + cp := *exam + db.exams[cp.ID] = &cp + return nil } func (db *InMemoryDB) GetExam(id int) (*models.Exam, error) { -db.mu.RLock() -defer db.mu.RUnlock() -e, ok := db.exams[id] -if !ok { -return nil, ErrNotFound -} -cp := *e -return &cp, nil + db.mu.RLock() + defer db.mu.RUnlock() + e, ok := db.exams[id] + if !ok { + return nil, ErrNotFound + } + cp := *e + return &cp, nil } func (db *InMemoryDB) GetExamByToken(token string) (*models.Exam, error) { -db.mu.RLock() -defer db.mu.RUnlock() -for _, e := range db.exams { -if e.AccessToken == token { -cp := *e -return &cp, nil -} -} -return nil, ErrNotFound + db.mu.RLock() + defer db.mu.RUnlock() + for _, e := range db.exams { + if e.AccessToken == token { + cp := *e + return &cp, nil + } + } + return nil, ErrNotFound } func (db *InMemoryDB) ListExams() ([]*models.Exam, error) { -db.mu.RLock() -defer db.mu.RUnlock() -result := make([]*models.Exam, 0, len(db.exams)) -for _, e := range db.exams { -cp := *e -result = append(result, &cp) -} -return result, nil + db.mu.RLock() + defer db.mu.RUnlock() + result := make([]*models.Exam, 0, len(db.exams)) + for _, e := range db.exams { + cp := *e + result = append(result, &cp) + } + return result, nil } func (db *InMemoryDB) GetQuestionsByCategories(categories []string, difficultyLevels []int, limit int) ([]*models.Question, error) { -db.mu.RLock() -defer db.mu.RUnlock() + db.mu.RLock() + defer db.mu.RUnlock() -catSet := map[string]bool{} -for _, c := range categories { -catSet[c] = true -} + catSet := map[string]bool{} + for _, c := range categories { + catSet[c] = true + } -diffRanges := difficultyRanges(difficultyLevels) + diffRanges := difficultyRanges(difficultyLevels) -inDiff := func(d int) bool { -if len(diffRanges) == 0 { -return true -} -for _, r := range diffRanges { -if d >= r[0] && d <= r[1] { -return true -} -} -return false -} + inDiff := func(d int) bool { + if len(diffRanges) == 0 { + return true + } + for _, r := range diffRanges { + if d >= r[0] && d <= r[1] { + return true + } + } + return false + } -var result []*models.Question -for _, q := range db.questions { -topic, ok := db.topics[q.TopicID] -if !ok || !topic.IsActive { -continue -} -if len(catSet) > 0 && !catSet[topic.Category] && topic.Category != "all" { -continue -} -if !inDiff(q.Difficulty) { -continue -} -cp := *q -result = append(result, &cp) -} + var result []*models.Question + for _, q := range db.questions { + topic, ok := db.topics[q.TopicID] + if !ok || !topic.IsActive { + continue + } + if len(catSet) > 0 && !catSet[topic.Category] && topic.Category != "all" { + continue + } + if !inDiff(q.Difficulty) { + continue + } + cp := *q + result = append(result, &cp) + } -// shuffle -for i := len(result) - 1; i > 0; i-- { -j := i // simple deterministic shuffle for tests -result[i], result[j] = result[j], result[i] -} -if limit > 0 && len(result) > limit { -result = result[:limit] -} -return result, nil + // shuffle + for i := len(result) - 1; i > 0; i-- { + j := i // simple deterministic shuffle for tests + result[i], result[j] = result[j], result[i] + } + if limit > 0 && len(result) > limit { + result = result[:limit] + } + return result, nil } func (db *InMemoryDB) AssignExamToUser(examID, userID, assignedBy int) error { -db.mu.Lock() -defer db.mu.Unlock() -// check for duplicates -for _, a := range db.examAssignments { -if a.ExamID == examID && a.UserID == userID { -return nil // ignore duplicate -} -} -a := &models.ExamAssignment{ -ID: db.nextExamAssignID, -ExamID: examID, -UserID: userID, -AssignedAt: time.Now(), -AssignedBy: assignedBy, -} -db.nextExamAssignID++ -db.examAssignments[a.ID] = a -return nil + db.mu.Lock() + defer db.mu.Unlock() + user, exists := db.users[userID] + if !exists { + return ErrNotFound + } + if user.IsAdmin { + return fmt.Errorf("user is not a student") + } + if !user.IsActive { + return fmt.Errorf("user is inactive") + } + // check for duplicates + for _, a := range db.examAssignments { + if a.ExamID == examID && a.UserID == userID { + return nil // ignore duplicate + } + } + a := &models.ExamAssignment{ + ID: db.nextExamAssignID, + ExamID: examID, + UserID: userID, + AssignedAt: time.Now(), + AssignedBy: assignedBy, + } + db.nextExamAssignID++ + db.examAssignments[a.ID] = a + return nil } func (db *InMemoryDB) GetAssignedExamsForUser(userID int) ([]*models.ExamInfo, error) { -db.mu.RLock() -defer db.mu.RUnlock() + db.mu.RLock() + defer db.mu.RUnlock() -var result []*models.ExamInfo -for _, a := range db.examAssignments { -if a.UserID != userID { -continue -} -exam, ok := db.exams[a.ExamID] -if !ok { -continue -} -info := &models.ExamInfo{ -ExamAssignment: *a, -ExamName: exam.Name, -QuestionCount: exam.QuestionCount, -AccessToken: exam.AccessToken, -} -// Find most recent completed attempt -var bestAttempt *models.ExamAttempt -for _, att := range db.examAttempts { -if att.ExamID == a.ExamID && att.UserID == userID && att.CompletedAt != nil { -if bestAttempt == nil || att.ID > bestAttempt.ID { -bestAttempt = att -} -} -} -if bestAttempt != nil { -info.CompletedAt = bestAttempt.CompletedAt -ca := bestAttempt.CorrectAnswers -info.CorrectAnswers = &ca -tq := bestAttempt.TotalQuestions -info.TotalQuestions = &tq -s := bestAttempt.Score -info.Score = &s -} -result = append(result, info) -} -if result == nil { -result = []*models.ExamInfo{} -} -return result, nil + var result []*models.ExamInfo + for _, a := range db.examAssignments { + if a.UserID != userID { + continue + } + exam, ok := db.exams[a.ExamID] + if !ok { + continue + } + info := &models.ExamInfo{ + ExamAssignment: *a, + ExamName: exam.Name, + QuestionCount: exam.QuestionCount, + AccessToken: exam.AccessToken, + } + // Find most recent completed attempt + var bestAttempt *models.ExamAttempt + for _, att := range db.examAttempts { + if att.ExamID == a.ExamID && att.UserID == userID && att.CompletedAt != nil { + if bestAttempt == nil || att.ID > bestAttempt.ID { + bestAttempt = att + } + } + } + if bestAttempt != nil { + info.CompletedAt = bestAttempt.CompletedAt + ca := bestAttempt.CorrectAnswers + info.CorrectAnswers = &ca + tq := bestAttempt.TotalQuestions + info.TotalQuestions = &tq + s := bestAttempt.Score + info.Score = &s + } + result = append(result, info) + } + if result == nil { + result = []*models.ExamInfo{} + } + return result, nil } func (db *InMemoryDB) CreateExamAttempt(attempt *models.ExamAttempt) error { -db.mu.Lock() -defer db.mu.Unlock() -attempt.ID = db.nextExamAttemptID -db.nextExamAttemptID++ -cp := *attempt -if cp.Answers == nil { -cp.Answers = map[string]int{} -} -if cp.QuestionResults == nil { -cp.QuestionResults = map[string]bool{} -} -db.examAttempts[cp.ID] = &cp -return nil + db.mu.Lock() + defer db.mu.Unlock() + attempt.ID = db.nextExamAttemptID + db.nextExamAttemptID++ + cp := *attempt + if cp.Answers == nil { + cp.Answers = map[string]int{} + } + if cp.QuestionResults == nil { + cp.QuestionResults = map[string]bool{} + } + db.examAttempts[cp.ID] = &cp + return nil } func (db *InMemoryDB) GetExamAttempt(id int) (*models.ExamAttempt, error) { -db.mu.RLock() -defer db.mu.RUnlock() -a, ok := db.examAttempts[id] -if !ok { -return nil, ErrNotFound -} -cp := *a -return &cp, nil + db.mu.RLock() + defer db.mu.RUnlock() + a, ok := db.examAttempts[id] + if !ok { + return nil, ErrNotFound + } + cp := *a + return &cp, nil } func (db *InMemoryDB) SubmitExamAttempt(attemptID int, answers map[string]int) error { -db.mu.Lock() -defer db.mu.Unlock() + db.mu.Lock() + defer db.mu.Unlock() -attempt, ok := db.examAttempts[attemptID] -if !ok { -return ErrNotFound -} -exam, ok := db.exams[attempt.ExamID] -if !ok { -return ErrNotFound -} + attempt, ok := db.examAttempts[attemptID] + if !ok { + return ErrNotFound + } + exam, ok := db.exams[attempt.ExamID] + if !ok { + return ErrNotFound + } -attempt.Answers = answers -attempt.QuestionResults = map[string]bool{} -attempt.CorrectAnswers = 0 -attempt.TotalQuestions = len(exam.QuestionIDs) + attempt.Answers = answers + attempt.QuestionResults = map[string]bool{} + attempt.CorrectAnswers = 0 + attempt.TotalQuestions = len(exam.QuestionIDs) -for _, qid := range exam.QuestionIDs { -key := fmt.Sprintf("%d", qid) -answerID, ok := answers[key] -if !ok { -attempt.QuestionResults[key] = false -continue -} -answer, ok := db.answers[answerID] -if ok && answer.QuestionID == qid && answer.IsCorrect { -attempt.CorrectAnswers++ -attempt.QuestionResults[key] = true -} else { -attempt.QuestionResults[key] = false -} -} + for _, qid := range exam.QuestionIDs { + key := fmt.Sprintf("%d", qid) + answerID, ok := answers[key] + if !ok { + attempt.QuestionResults[key] = false + continue + } + answer, ok := db.answers[answerID] + if ok && answer.QuestionID == qid && answer.IsCorrect { + attempt.CorrectAnswers++ + attempt.QuestionResults[key] = true + } else { + attempt.QuestionResults[key] = false + } + } -if attempt.TotalQuestions > 0 { -attempt.Score = float64(attempt.CorrectAnswers) / float64(attempt.TotalQuestions) * 100 -} -now := time.Now() -attempt.CompletedAt = &now -return nil + if attempt.TotalQuestions > 0 { + attempt.Score = float64(attempt.CorrectAnswers) / float64(attempt.TotalQuestions) * 100 + } + now := time.Now() + attempt.CompletedAt = &now + return nil } func (db *InMemoryDB) GetExamStatus(examID int) (*models.ExamStatus, error) { -db.mu.RLock() -defer db.mu.RUnlock() + db.mu.RLock() + defer db.mu.RUnlock() -exam, ok := db.exams[examID] -if !ok { -return nil, ErrNotFound -} + exam, ok := db.exams[examID] + if !ok { + return nil, ErrNotFound + } -status := &models.ExamStatus{ -ExamID: exam.ID, -ExamName: exam.Name, -QuestionCount: exam.QuestionCount, -StudentResults: []models.ExamStudentResult{}, -} + status := &models.ExamStatus{ + ExamID: exam.ID, + ExamName: exam.Name, + QuestionCount: exam.QuestionCount, + StudentResults: []models.ExamStudentResult{}, + } -for _, a := range db.examAssignments { -if a.ExamID != examID { -continue -} -user, ok := db.users[a.UserID] -if !ok { -continue -} -r := models.ExamStudentResult{ -UserID: a.UserID, -Username: user.Username, -AssignedAt: a.AssignedAt, -} -// Find most recent completed attempt -for _, att := range db.examAttempts { -if att.ExamID == examID && att.UserID == a.UserID && att.CompletedAt != nil { -r.CompletedAt = att.CompletedAt -ca := att.CorrectAnswers -r.CorrectAnswers = &ca -tq := att.TotalQuestions -r.TotalQuestions = &tq -s := att.Score -r.Score = &s -} -} -status.StudentResults = append(status.StudentResults, r) -} -return status, nil + for _, a := range db.examAssignments { + if a.ExamID != examID { + continue + } + user, ok := db.users[a.UserID] + if !ok { + continue + } + r := models.ExamStudentResult{ + UserID: a.UserID, + Username: user.Username, + AssignedAt: a.AssignedAt, + } + // Find most recent completed attempt + for _, att := range db.examAttempts { + if att.ExamID == examID && att.UserID == a.UserID && att.CompletedAt != nil { + r.CompletedAt = att.CompletedAt + ca := att.CorrectAnswers + r.CorrectAnswers = &ca + tq := att.TotalQuestions + r.TotalQuestions = &tq + s := att.Score + r.Score = &s + } + } + status.StudentResults = append(status.StudentResults, r) + } + return status, nil } diff --git a/database/exam.go b/database/exam.go index 379f6e7..67c7ce5 100644 --- a/database/exam.go +++ b/database/exam.go @@ -157,7 +157,17 @@ func (db *SQLiteDB) GetQuestionsByCategories(categories []string, difficultyLeve } func (db *SQLiteDB) AssignExamToUser(examID, userID, assignedBy int) error { - _, err := db.db.Exec( + user, err := db.GetUser(userID) + if err != nil { + return err + } + if user.IsAdmin { + return fmt.Errorf("user is not a student") + } + if !user.IsActive { + return fmt.Errorf("user is inactive") + } + _, err = db.db.Exec( `INSERT OR IGNORE INTO exam_assignments (exam_id, user_id, assigned_by, assigned_at) VALUES (?, ?, ?, ?)`, examID, userID, assignedBy, time.Now(), ) diff --git a/database/migrations/004_add_user_is_active.down.sql b/database/migrations/004_add_user_is_active.down.sql new file mode 100644 index 0000000..cf3bd28 --- /dev/null +++ b/database/migrations/004_add_user_is_active.down.sql @@ -0,0 +1,18 @@ +CREATE TABLE users_rollback ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + username TEXT NOT NULL UNIQUE, + email TEXT NOT NULL UNIQUE, + password TEXT NOT NULL, + is_admin BOOLEAN DEFAULT 0, + category TEXT DEFAULT 'java', + total_points INTEGER DEFAULT 0, + created_at DATETIME DEFAULT CURRENT_TIMESTAMP +); + +INSERT INTO users_rollback (id, username, email, password, is_admin, category, total_points, created_at) +SELECT id, username, email, password, is_admin, category, total_points, created_at +FROM users; + +DROP TABLE users; + +ALTER TABLE users_rollback RENAME TO users; diff --git a/database/migrations/004_add_user_is_active.up.sql b/database/migrations/004_add_user_is_active.up.sql new file mode 100644 index 0000000..69ba03b --- /dev/null +++ b/database/migrations/004_add_user_is_active.up.sql @@ -0,0 +1 @@ +ALTER TABLE users ADD COLUMN is_active BOOLEAN NOT NULL DEFAULT 1; diff --git a/database/user.go b/database/user.go index 940bb7c..637bf17 100644 --- a/database/user.go +++ b/database/user.go @@ -12,10 +12,13 @@ import ( func (db *SQLiteDB) CreateUser(user *models.User) error { // Normalize category to lowercase for storage user.Category = strings.ToLower(user.Category) + if !user.IsActiveSet { + user.IsActive = true + } result, err := db.db.Exec( - "INSERT INTO users (username, email, password, is_admin, category, total_points, created_at) VALUES (?, ?, ?, ?, ?, ?, ?)", - user.Username, user.Email, user.Password, user.IsAdmin, user.Category, user.TotalPoints, user.CreatedAt, + "INSERT INTO users (username, email, password, is_admin, is_active, category, total_points, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", + user.Username, user.Email, user.Password, user.IsAdmin, user.IsActive, user.Category, user.TotalPoints, user.CreatedAt, ) if err != nil { return err @@ -32,9 +35,9 @@ func (db *SQLiteDB) CreateUser(user *models.User) error { func (db *SQLiteDB) GetUser(id int) (*models.User, error) { user := &models.User{} err := db.db.QueryRow( - "SELECT id, username, email, is_admin, category, total_points, created_at FROM users WHERE id = ?", + "SELECT id, username, email, is_admin, is_active, category, total_points, created_at FROM users WHERE id = ?", id, - ).Scan(&user.ID, &user.Username, &user.Email, &user.IsAdmin, &user.Category, &user.TotalPoints, &user.CreatedAt) + ).Scan(&user.ID, &user.Username, &user.Email, &user.IsAdmin, &user.IsActive, &user.Category, &user.TotalPoints, &user.CreatedAt) if err == sql.ErrNoRows { return nil, ErrNotFound } @@ -48,9 +51,9 @@ func (db *SQLiteDB) GetUser(id int) (*models.User, error) { func (db *SQLiteDB) GetUserByUsername(username string) (*models.User, error) { user := &models.User{} err := db.db.QueryRow( - "SELECT id, username, email, password, is_admin, category, total_points, created_at FROM users WHERE username = ?", + "SELECT id, username, email, password, is_admin, is_active, category, total_points, created_at FROM users WHERE username = ?", username, - ).Scan(&user.ID, &user.Username, &user.Email, &user.Password, &user.IsAdmin, &user.Category, &user.TotalPoints, &user.CreatedAt) + ).Scan(&user.ID, &user.Username, &user.Email, &user.Password, &user.IsAdmin, &user.IsActive, &user.Category, &user.TotalPoints, &user.CreatedAt) if err == sql.ErrNoRows { return nil, ErrNotFound } @@ -78,7 +81,7 @@ func (db *SQLiteDB) UpdateUserPoints(id int, points int) error { // ListUsers retrieves all users func (db *SQLiteDB) ListUsers() ([]*models.User, error) { - rows, err := db.db.Query("SELECT id, username, email, is_admin, category, total_points, created_at FROM users") + rows, err := db.db.Query("SELECT id, username, email, is_admin, is_active, category, total_points, created_at FROM users") if err != nil { return nil, err } @@ -87,7 +90,7 @@ func (db *SQLiteDB) ListUsers() ([]*models.User, error) { var users []*models.User for rows.Next() { user := &models.User{} - if err := rows.Scan(&user.ID, &user.Username, &user.Email, &user.IsAdmin, &user.Category, &user.TotalPoints, &user.CreatedAt); err != nil { + if err := rows.Scan(&user.ID, &user.Username, &user.Email, &user.IsAdmin, &user.IsActive, &user.Category, &user.TotalPoints, &user.CreatedAt); err != nil { return nil, err } users = append(users, user) @@ -108,8 +111,8 @@ func (db *SQLiteDB) UpdateUser(user *models.User) error { // If password is provided, update it along with other fields if user.Password != "" { result, err := db.db.Exec( - "UPDATE users SET username = ?, email = ?, password = ?, is_admin = ?, category = ?, total_points = ? WHERE id = ?", - user.Username, user.Email, user.Password, user.IsAdmin, user.Category, user.TotalPoints, user.ID, + "UPDATE users SET username = ?, email = ?, password = ?, is_admin = ?, is_active = ?, category = ?, total_points = ? WHERE id = ?", + user.Username, user.Email, user.Password, user.IsAdmin, user.IsActive, user.Category, user.TotalPoints, user.ID, ) if err != nil { return err @@ -124,8 +127,8 @@ func (db *SQLiteDB) UpdateUser(user *models.User) error { } else { // Don't update password if not provided result, err := db.db.Exec( - "UPDATE users SET username = ?, email = ?, is_admin = ?, category = ?, total_points = ? WHERE id = ?", - user.Username, user.Email, user.IsAdmin, user.Category, user.TotalPoints, user.ID, + "UPDATE users SET username = ?, email = ?, is_admin = ?, is_active = ?, category = ?, total_points = ? WHERE id = ?", + user.Username, user.Email, user.IsAdmin, user.IsActive, user.Category, user.TotalPoints, user.ID, ) if err != nil { return err diff --git a/models/models.go b/models/models.go index f6ec7cd..a23e048 100644 --- a/models/models.go +++ b/models/models.go @@ -9,6 +9,8 @@ type User struct { Email string `json:"email"` Password string `json:"password,omitempty"` // Only used for auth, not returned in API IsAdmin bool `json:"is_admin"` + IsActive bool `json:"is_active"` + IsActiveSet bool `json:"-"` Category string `json:"category"` // "java" or "data" - determines accessible topics and resources TotalPoints int `json:"total_points"` CreatedAt time.Time `json:"created_at"` @@ -58,9 +60,9 @@ type QuizAttempt struct { CompletedTime *time.Time `json:"completed_time,omitempty"` TotalQuestions int `json:"total_questions"` CorrectAnswers int `json:"correct_answers"` - DifficultyAverage float64 `json:"difficulty_average"` // Average difficulty of all questions in quiz (1-7 scale) - Description string `json:"quiz_description"` // Human-readable description (e.g., "Python Basics Quiz") - QuestionIDs []string `json:"question_ids"` // List of topic_question_id + DifficultyAverage float64 `json:"difficulty_average"` // Average difficulty of all questions in quiz (1-7 scale) + Description string `json:"quiz_description"` // Human-readable description (e.g., "Python Basics Quiz") + QuestionIDs []string `json:"question_ids"` // List of topic_question_id QuestionResults map[string]bool `json:"question_results"` // topic_question_id -> correct/incorrect } @@ -121,11 +123,11 @@ type AssignedQuizStudentResult struct { // AssignedQuizStatus represents the instructor status view for an assigned quiz type AssignedQuizStatus struct { - QuizID int `json:"quiz_id"` - QuizName string `json:"quiz_name"` - QuizCategory string `json:"quiz_category"` - QuizDescription string `json:"quiz_description"` - StudentResults []AssignedQuizStudentResult `json:"student_results"` + QuizID int `json:"quiz_id"` + QuizName string `json:"quiz_name"` + QuizCategory string `json:"quiz_category"` + QuizDescription string `json:"quiz_description"` + StudentResults []AssignedQuizStudentResult `json:"student_results"` } // UserQuestionState tracks FSRS state for each user-question pair @@ -437,15 +439,15 @@ type FlaggedQuestion struct { // Exam represents a named assigned exam generated from random questions // filtered by category and difficulty level. type Exam struct { - ID int `json:"id"` - Name string `json:"name"` - Categories []string `json:"categories"` // e.g. ["java","python"] - DifficultyLevels []int `json:"difficulty_levels"` // 1=easy,2=medium,3=hard - QuestionIDs []int `json:"question_ids"` // IDs chosen at generation time - QuestionCount int `json:"question_count"` - AccessToken string `json:"access_token"` - CreatedBy int `json:"created_by"` - CreatedAt time.Time `json:"created_at"` + ID int `json:"id"` + Name string `json:"name"` + Categories []string `json:"categories"` // e.g. ["java","python"] + DifficultyLevels []int `json:"difficulty_levels"` // 1=easy,2=medium,3=hard + QuestionIDs []int `json:"question_ids"` // IDs chosen at generation time + QuestionCount int `json:"question_count"` + AccessToken string `json:"access_token"` + CreatedBy int `json:"created_by"` + CreatedAt time.Time `json:"created_at"` } // ExamAssignment represents an exam assigned to a specific student diff --git a/static/admin.html b/static/admin.html index b8e9864..7c40056 100644 --- a/static/admin.html +++ b/static/admin.html @@ -58,6 +58,7 @@