diff --git a/internal/services/practicecontent/service.go b/internal/services/practicecontent/service.go index 041df72f..4cf2bc40 100644 --- a/internal/services/practicecontent/service.go +++ b/internal/services/practicecontent/service.go @@ -162,15 +162,20 @@ func (s *Service) loadQuestionsInSet(ctx context.Context, questionSetID int64) ( if err != nil { return nil, nil, err } + // Keep set membership aligned with questions that still exist. Orphaned + // question_set_items (deleted questions) must not fail the whole practice GET — + // admin editors need to open and repair those shells. + keptItems := make([]domain.QuestionSetItemWithQuestion, 0, len(items)) questions := make([]domain.QuestionWithDetails, 0, len(items)) for _, item := range items { q, ok := byID[item.QuestionID] if !ok { - return nil, nil, pgx.ErrNoRows + continue } + keptItems = append(keptItems, item) questions = append(questions, q) } - return items, questions, nil + return keptItems, questions, nil } func (s *Service) loadPracticeFullContent(ctx context.Context, questionSetID int64) (domain.QuestionSet, []domain.QuestionWithDetails, error) { diff --git a/internal/web_server/handlers/practice_full_update_handler.go b/internal/web_server/handlers/practice_full_update_handler.go index 44b3e5d0..7c1dcc89 100644 --- a/internal/web_server/handlers/practice_full_update_handler.go +++ b/internal/web_server/handlers/practice_full_update_handler.go @@ -10,6 +10,7 @@ import ( "strconv" "github.com/gofiber/fiber/v2" + "github.com/jackc/pgx/v5" ) func fullPracticeQuestionResponses( @@ -97,6 +98,8 @@ func mapPracticeFullError(err error, action string) (int, string) { return fiber.StatusNotFound, "Question set not found" case errors.Is(err, practicecontent.ErrQuestionNotFound): return fiber.StatusNotFound, "Question not found" + case errors.Is(err, pgx.ErrNoRows): + return fiber.StatusNotFound, "Practice content not found" case errors.Is(err, domain.ErrPersonaNotFound): return fiber.StatusNotFound, "Persona not found" case errors.Is(err, practicecontent.ErrInvalidQuestionItem):