fetch practice pagination fix
This commit is contained in:
parent
cd8670d5a6
commit
43f79d34ea
|
|
@ -51,6 +51,7 @@ FROM question_set_items qsi
|
|||
JOIN questions q ON q.id = qsi.question_id
|
||||
LEFT JOIN question_audio_answers qaa ON qaa.question_id = q.id
|
||||
WHERE qsi.set_id = $1
|
||||
AND ($2::VARCHAR IS NULL OR $2 = '' OR q.question_type = $2)
|
||||
AND q.status != 'ARCHIVED'
|
||||
ORDER BY qsi.display_order
|
||||
LIMIT sqlc.narg('limit')::INT
|
||||
|
|
|
|||
|
|
@ -219,16 +219,18 @@ FROM question_set_items qsi
|
|||
JOIN questions q ON q.id = qsi.question_id
|
||||
LEFT JOIN question_audio_answers qaa ON qaa.question_id = q.id
|
||||
WHERE qsi.set_id = $1
|
||||
AND ($2::VARCHAR IS NULL OR $2 = '' OR q.question_type = $2)
|
||||
AND q.status != 'ARCHIVED'
|
||||
ORDER BY qsi.display_order
|
||||
LIMIT $3::INT
|
||||
OFFSET $2::INT
|
||||
LIMIT $4::INT
|
||||
OFFSET $3::INT
|
||||
`
|
||||
|
||||
type GetQuestionSetItemsPaginatedParams struct {
|
||||
SetID int64 `json:"set_id"`
|
||||
Offset pgtype.Int4 `json:"offset"`
|
||||
Limit pgtype.Int4 `json:"limit"`
|
||||
SetID int64 `json:"set_id"`
|
||||
Column2 string `json:"column_2"`
|
||||
Offset pgtype.Int4 `json:"offset"`
|
||||
Limit pgtype.Int4 `json:"limit"`
|
||||
}
|
||||
|
||||
type GetQuestionSetItemsPaginatedRow struct {
|
||||
|
|
@ -251,7 +253,12 @@ type GetQuestionSetItemsPaginatedRow struct {
|
|||
}
|
||||
|
||||
func (q *Queries) GetQuestionSetItemsPaginated(ctx context.Context, arg GetQuestionSetItemsPaginatedParams) ([]GetQuestionSetItemsPaginatedRow, error) {
|
||||
rows, err := q.db.Query(ctx, GetQuestionSetItemsPaginated, arg.SetID, arg.Offset, arg.Limit)
|
||||
rows, err := q.db.Query(ctx, GetQuestionSetItemsPaginated,
|
||||
arg.SetID,
|
||||
arg.Column2,
|
||||
arg.Offset,
|
||||
arg.Limit,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ type QuestionStore interface {
|
|||
// Question Set Items
|
||||
AddQuestionToSet(ctx context.Context, setID, questionID int64, displayOrder *int32) (domain.QuestionSetItem, error)
|
||||
GetQuestionSetItems(ctx context.Context, setID int64) ([]domain.QuestionSetItemWithQuestion, error)
|
||||
GetQuestionSetItemsPaginated(ctx context.Context, setID int64, limit, offset int32) ([]domain.QuestionSetItemWithQuestion, int64, error)
|
||||
GetQuestionSetItemsPaginated(ctx context.Context, setID int64, questionType *string, limit, offset int32) ([]domain.QuestionSetItemWithQuestion, int64, error)
|
||||
GetPublishedQuestionsInSet(ctx context.Context, setID int64) ([]domain.QuestionSetItemWithQuestion, error)
|
||||
RemoveQuestionFromSet(ctx context.Context, setID, questionID int64) error
|
||||
UpdateQuestionOrder(ctx context.Context, setID, questionID int64, displayOrder int32) error
|
||||
|
|
|
|||
|
|
@ -752,11 +752,16 @@ func (s *Store) GetQuestionSetItems(ctx context.Context, setID int64) ([]domain.
|
|||
return result, nil
|
||||
}
|
||||
|
||||
func (s *Store) GetQuestionSetItemsPaginated(ctx context.Context, setID int64, limit, offset int32) ([]domain.QuestionSetItemWithQuestion, int64, error) {
|
||||
func (s *Store) GetQuestionSetItemsPaginated(ctx context.Context, setID int64, questionType *string, limit, offset int32) ([]domain.QuestionSetItemWithQuestion, int64, error) {
|
||||
qType := ""
|
||||
if questionType != nil {
|
||||
qType = *questionType
|
||||
}
|
||||
rows, err := s.queries.GetQuestionSetItemsPaginated(ctx, dbgen.GetQuestionSetItemsPaginatedParams{
|
||||
SetID: setID,
|
||||
Offset: pgtype.Int4{Int32: offset, Valid: true},
|
||||
Limit: pgtype.Int4{Int32: limit, Valid: true},
|
||||
SetID: setID,
|
||||
Column2: qType,
|
||||
Offset: pgtype.Int4{Int32: offset, Valid: true},
|
||||
Limit: pgtype.Int4{Int32: limit, Valid: true},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
|
|
|
|||
|
|
@ -154,8 +154,8 @@ func (s *Service) GetQuestionSetItems(ctx context.Context, setID int64) ([]domai
|
|||
return s.questionStore.GetQuestionSetItems(ctx, setID)
|
||||
}
|
||||
|
||||
func (s *Service) GetQuestionSetItemsPaginated(ctx context.Context, setID int64, limit, offset int32) ([]domain.QuestionSetItemWithQuestion, int64, error) {
|
||||
return s.questionStore.GetQuestionSetItemsPaginated(ctx, setID, limit, offset)
|
||||
func (s *Service) GetQuestionSetItemsPaginated(ctx context.Context, setID int64, questionType *string, limit, offset int32) ([]domain.QuestionSetItemWithQuestion, int64, error) {
|
||||
return s.questionStore.GetQuestionSetItemsPaginated(ctx, setID, questionType, limit, offset)
|
||||
}
|
||||
|
||||
func (s *Service) GetPublishedQuestionsInSet(ctx context.Context, setID int64) ([]domain.QuestionSetItemWithQuestion, error) {
|
||||
|
|
|
|||
|
|
@ -1195,6 +1195,7 @@ func (h *Handler) GetQuestionsInSet(c *fiber.Ctx) error {
|
|||
// @Tags question-set-items
|
||||
// @Produce json
|
||||
// @Param practiceId path int true "Practice(question-set) ID"
|
||||
// @Param question_type query string false "Question type filter (e.g. AUDIO)"
|
||||
// @Param limit query int false "Limit" default(10)
|
||||
// @Param offset query int false "Offset" default(0)
|
||||
// @Success 200 {object} domain.Response
|
||||
|
|
@ -1239,6 +1240,11 @@ func (h *Handler) GetQuestionsByPractice(c *fiber.Ctx) error {
|
|||
|
||||
limit, _ := strconv.Atoi(c.Query("limit", "10"))
|
||||
offset, _ := strconv.Atoi(c.Query("offset", "0"))
|
||||
questionType := strings.TrimSpace(c.Query("question_type"))
|
||||
var qTypePtr *string
|
||||
if questionType != "" {
|
||||
qTypePtr = &questionType
|
||||
}
|
||||
if limit <= 0 {
|
||||
limit = 10
|
||||
}
|
||||
|
|
@ -1249,7 +1255,7 @@ func (h *Handler) GetQuestionsByPractice(c *fiber.Ctx) error {
|
|||
offset = 0
|
||||
}
|
||||
|
||||
items, totalCount, err := h.questionsSvc.GetQuestionSetItemsPaginated(c.Context(), practiceID, int32(limit), int32(offset))
|
||||
items, totalCount, err := h.questionsSvc.GetQuestionSetItemsPaginated(c.Context(), practiceID, qTypePtr, int32(limit), int32(offset))
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(domain.ErrorResponse{
|
||||
Message: "Failed to get practice questions",
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user