Skip to content

Commit 5626bdb

Browse files
authored
Merge pull request #23 from quizfreely/feat/practice-test-multi-studyset-10523823744295046263
Support Multi-Studyset Practice Tests via Term Mappings
2 parents fd6dfde + 855a0a5 commit 5626bdb

5 files changed

Lines changed: 196 additions & 95 deletions

File tree

graph/loader/loader.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -522,28 +522,34 @@ func (dr *dataReader) getPracticeTestsByStudysetIDs(ctx context.Context, studyse
522522
type dbPracticeTest struct {
523523
ID *string `db:"id"`
524524
Timestamp *string `db:"timestamp"`
525-
StudysetID *string `db:"studyset_id"`
526525
QuestionsCorrect *int32 `db:"questions_correct"`
527526
QuestionsTotal *int32 `db:"questions_total"`
528527
Questions []*model.Question `db:"questions"`
528+
StudysetID *string `db:"studyset_id"`
529529
}
530530
var dbPracticeTests []*dbPracticeTest
531531

532532
err := pgxscan.Select(
533533
ctx,
534534
dr.db,
535535
&dbPracticeTests,
536-
`SELECT pt.id,
536+
`SELECT DISTINCT ON (input.og_order, pt.id)
537+
pt.id,
537538
to_char(pt.timestamp, 'YYYY-MM-DD"T"HH24:MI:SS.MSTZH:TZM') as timestamp,
538-
pt.studyset_id,
539539
pt.questions_correct,
540540
pt.questions_total,
541-
pt.questions
541+
pt.questions,
542+
input.studyset_id
542543
FROM unnest($1::uuid[]) WITH ORDINALITY AS input(studyset_id, og_order)
543-
LEFT JOIN practice_tests pt
544-
ON pt.studyset_id = input.studyset_id
545-
AND pt.user_id = $2
546-
ORDER BY input.og_order ASC, pt.timestamp DESC`,
544+
JOIN (
545+
SELECT practice_test_id, term_id FROM practice_test_question_terms
546+
UNION
547+
SELECT practice_test_id, term_id FROM practice_test_distractor_terms
548+
) mapping ON TRUE
549+
JOIN terms t ON mapping.term_id = t.id AND t.studyset_id = input.studyset_id
550+
JOIN practice_tests pt ON pt.id = mapping.practice_test_id
551+
WHERE pt.user_id = $2
552+
ORDER BY input.og_order ASC, pt.id, pt.timestamp DESC`,
547553
studysetIDs,
548554
authedUser.ID,
549555
)
@@ -556,7 +562,6 @@ ORDER BY input.og_order ASC, pt.timestamp DESC`,
556562
if pt.ID != nil && pt.StudysetID != nil {
557563
grouped[*pt.StudysetID] = append(grouped[*pt.StudysetID], &model.PracticeTest{
558564
ID: pt.ID,
559-
StudysetID: pt.StudysetID,
560565
Timestamp: pt.Timestamp,
561566
QuestionsCorrect: pt.QuestionsCorrect,
562567
QuestionsTotal: pt.QuestionsTotal,
@@ -659,7 +664,6 @@ func (dr *dataReader) getPracticeTestsByTermIDs(ctx context.Context, termIDs []s
659664
type dbPracticeTest struct {
660665
ID *string `db:"id"`
661666
Timestamp *string `db:"timestamp"`
662-
StudysetID *string `db:"studyset_id"`
663667
QuestionsCorrect *int32 `db:"questions_correct"`
664668
QuestionsTotal *int32 `db:"questions_total"`
665669
Questions []*model.Question `db:"questions"`
@@ -673,7 +677,6 @@ func (dr *dataReader) getPracticeTestsByTermIDs(ctx context.Context, termIDs []s
673677
&dbPracticeTests,
674678
`SELECT pt.id,
675679
to_char(pt.timestamp, 'YYYY-MM-DD"T"HH24:MI:SS.MSTZH:TZM') as timestamp,
676-
pt.studyset_id,
677680
pt.questions_correct,
678681
pt.questions_total,
679682
pt.questions,
@@ -708,7 +711,6 @@ ORDER BY input.og_order ASC, pt.timestamp DESC`,
708711
if !exists {
709712
grouped[*pt.TermID] = append(grouped[*pt.TermID], &model.PracticeTest{
710713
ID: pt.ID,
711-
StudysetID: pt.StudysetID,
712714
Timestamp: pt.Timestamp,
713715
QuestionsCorrect: pt.QuestionsCorrect,
714716
QuestionsTotal: pt.QuestionsTotal,

graph/model/practice_test_model.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ package model
44

55
type PracticeTest struct {
66
ID *string `json:"id,omitempty" db:"id"`
7-
StudysetID *string `json:"studysetId,omitempty" db:"studyset_id"`
87
Timestamp *string `json:"timestamp,omitempty" db:"timestamp"`
98
QuestionsCorrect *int32 `json:"questionsCorrect,omitempty" db:"questions_correct"`
109
QuestionsTotal *int32 `json:"questionsTotal,omitempty" db:"questions_total"`

graph/resolver/mutation.resolvers.go

Lines changed: 63 additions & 57 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

graph/resolver/query.resolvers.go

Lines changed: 20 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)