GET question sets API fix
This commit is contained in:
parent
87bf2ed609
commit
8c116f4a0b
|
|
@ -607,6 +607,19 @@ func (s *Store) GetQuestionSetsByType(ctx context.Context, setType string, limit
|
||||||
UpdatedAt: timePtr(r.UpdatedAt),
|
UpdatedAt: timePtr(r.UpdatedAt),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// COUNT(*) OVER() only appears when at least one row is returned.
|
||||||
|
// For out-of-range offsets, fetch total count explicitly so pagination metadata stays correct.
|
||||||
|
if len(rows) == 0 {
|
||||||
|
err = s.conn.QueryRow(
|
||||||
|
ctx,
|
||||||
|
`SELECT COUNT(*) FROM question_sets WHERE set_type = $1 AND status != 'ARCHIVED'`,
|
||||||
|
setType,
|
||||||
|
).Scan(&totalCount)
|
||||||
|
if err != nil {
|
||||||
|
return nil, 0, err
|
||||||
|
}
|
||||||
|
}
|
||||||
return result, totalCount, nil
|
return result, totalCount, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1120,11 +1120,64 @@ func (h *Handler) GetQuestionsInSet(c *fiber.Ctx) error {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
itemResponses := questionSetItemsToRes(items)
|
questionResponses := make([]questionRes, 0, len(items))
|
||||||
|
for _, item := range items {
|
||||||
|
question, err := h.questionsSvc.GetQuestionWithDetails(c.Context(), item.QuestionID)
|
||||||
|
if err != nil {
|
||||||
|
return c.Status(fiber.StatusInternalServerError).JSON(domain.ErrorResponse{
|
||||||
|
Message: "Failed to get question details",
|
||||||
|
Error: err.Error(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
options := make([]optionRes, 0, len(question.Options))
|
||||||
|
for _, opt := range question.Options {
|
||||||
|
options = append(options, optionRes{
|
||||||
|
ID: opt.ID,
|
||||||
|
OptionText: opt.OptionText,
|
||||||
|
OptionOrder: opt.OptionOrder,
|
||||||
|
IsCorrect: opt.IsCorrect,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
shortAnswers := make([]shortAnswerRes, 0, len(question.ShortAnswers))
|
||||||
|
for _, sa := range question.ShortAnswers {
|
||||||
|
shortAnswers = append(shortAnswers, shortAnswerRes{
|
||||||
|
ID: sa.ID,
|
||||||
|
AcceptableAnswer: sa.AcceptableAnswer,
|
||||||
|
MatchType: sa.MatchType,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
var audioCorrectAnswerText *string
|
||||||
|
if question.AudioAnswer != nil {
|
||||||
|
audioCorrectAnswerText = &question.AudioAnswer.CorrectAnswerText
|
||||||
|
}
|
||||||
|
|
||||||
|
questionResponses = append(questionResponses, questionRes{
|
||||||
|
ID: question.ID,
|
||||||
|
QuestionText: question.QuestionText,
|
||||||
|
QuestionType: question.QuestionType,
|
||||||
|
DifficultyLevel: question.DifficultyLevel,
|
||||||
|
Points: question.Points,
|
||||||
|
Explanation: question.Explanation,
|
||||||
|
Tips: question.Tips,
|
||||||
|
VoicePrompt: question.VoicePrompt,
|
||||||
|
SampleAnswerVoicePrompt: question.SampleAnswerVoicePrompt,
|
||||||
|
ImageURL: question.ImageURL,
|
||||||
|
Status: question.Status,
|
||||||
|
CreatedAt: question.CreatedAt.String(),
|
||||||
|
Options: options,
|
||||||
|
ShortAnswers: shortAnswers,
|
||||||
|
AudioCorrectAnswerText: audioCorrectAnswerText,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return c.JSON(domain.Response{
|
return c.JSON(domain.Response{
|
||||||
Message: "Questions retrieved successfully",
|
Message: "Questions retrieved successfully",
|
||||||
Data: itemResponses,
|
Success: true,
|
||||||
|
StatusCode: fiber.StatusOK,
|
||||||
|
Data: questionResponses,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user