Also replace question options on update so placement grading stays consistent with admin edits, and tune the Postgres pool defaults. Co-authored-by: Cursor <cursoragent@cursor.com>
57 lines
1.5 KiB
Go
57 lines
1.5 KiB
Go
package assessment
|
|
|
|
import (
|
|
"Yimaru-Backend/internal/domain"
|
|
"context"
|
|
)
|
|
|
|
// CreateQuestion creates a question in the unified questions system.
|
|
// Initial assessment questions should be created through the unified questions API
|
|
// and then linked to the initial assessment question set.
|
|
func (s *Service) CreateQuestion(
|
|
ctx context.Context,
|
|
input domain.CreateQuestionInput,
|
|
) (domain.Question, error) {
|
|
return s.questionStore.CreateQuestion(ctx, input)
|
|
}
|
|
|
|
// ListQuestions returns questions from the initial assessment set.
|
|
func (s *Service) ListQuestions(ctx context.Context) ([]domain.QuestionWithDetails, error) {
|
|
// Get the initial assessment set
|
|
set, err := s.questionStore.GetInitialAssessmentSet(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// Get all questions in the set
|
|
items, err := s.questionStore.GetPublishedQuestionsInSet(ctx, set.ID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
ids := make([]int64, 0, len(items))
|
|
for _, item := range items {
|
|
ids = append(ids, item.QuestionID)
|
|
}
|
|
byID, err := s.questionStore.GetQuestionsWithDetailsByIDs(ctx, ids)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
result := make([]domain.QuestionWithDetails, 0, len(items))
|
|
for _, item := range items {
|
|
qwd, ok := byID[item.QuestionID]
|
|
if !ok {
|
|
continue
|
|
}
|
|
result = append(result, qwd)
|
|
}
|
|
|
|
return result, nil
|
|
}
|
|
|
|
// GetQuestionByID returns a question with full details.
|
|
func (s *Service) GetQuestionByID(ctx context.Context, id int64) (domain.QuestionWithDetails, error) {
|
|
return s.questionStore.GetQuestionWithDetails(ctx, id)
|
|
}
|