Count only children that have published practices at module and above for LMS and exam prep; keep lesson at 100% after one practice and module at 100% after direct module practice. Co-authored-by: Cursor <cursoragent@cursor.com>
87 lines
3.5 KiB
Go
87 lines
3.5 KiB
Go
package repository
|
|
|
|
import (
|
|
"context"
|
|
|
|
dbgen "Yimaru-Backend/gen/db"
|
|
)
|
|
|
|
// ExamPrepCountPublishedPracticesInLesson returns published practices attached to an exam-prep lesson.
|
|
func (s *Store) ExamPrepCountPublishedPracticesInLesson(ctx context.Context, lessonID int64) (int32, error) {
|
|
return s.queries.CountPublishedExamPrepPracticesInLesson(ctx, lessonID)
|
|
}
|
|
|
|
// ExamPrepCountPublishedPracticesInModule returns published practices under an exam-prep module (via lessons).
|
|
func (s *Store) ExamPrepCountPublishedPracticesInModule(ctx context.Context, moduleID int64) (int32, error) {
|
|
return s.queries.CountPublishedExamPrepPracticesInModule(ctx, moduleID)
|
|
}
|
|
|
|
// ExamPrepCountPublishedPracticesInUnit returns published practices under an exam-prep unit.
|
|
func (s *Store) ExamPrepCountPublishedPracticesInUnit(ctx context.Context, unitID int64) (int32, error) {
|
|
return s.queries.CountPublishedExamPrepPracticesInUnit(ctx, unitID)
|
|
}
|
|
|
|
// ExamPrepUserPracticeProgressInLesson returns published practice completion counts scoped to an exam-prep lesson.
|
|
func (s *Store) ExamPrepUserPracticeProgressInLesson(ctx context.Context, userID, lessonID int64) (completed, total int32, err error) {
|
|
total, err = s.queries.CountPublishedExamPrepPracticesInLesson(ctx, lessonID)
|
|
if err != nil {
|
|
return 0, 0, err
|
|
}
|
|
completed, err = s.queries.CountUserCompletedPublishedExamPrepPracticesInLesson(ctx, dbgen.CountUserCompletedPublishedExamPrepPracticesInLessonParams{
|
|
UnitModuleLessonID: lessonID,
|
|
UserID: userID,
|
|
})
|
|
if err != nil {
|
|
return 0, 0, err
|
|
}
|
|
return completed, total, nil
|
|
}
|
|
|
|
// ExamPrepUserPracticeProgressInModule returns published practice completion counts in an exam-prep module.
|
|
func (s *Store) ExamPrepUserPracticeProgressInModule(ctx context.Context, userID, moduleID int64) (completed, total int32, err error) {
|
|
total, err = s.queries.CountPublishedExamPrepPracticesInModule(ctx, moduleID)
|
|
if err != nil {
|
|
return 0, 0, err
|
|
}
|
|
completed, err = s.queries.CountUserCompletedPublishedExamPrepPracticesInModule(ctx, dbgen.CountUserCompletedPublishedExamPrepPracticesInModuleParams{
|
|
UnitModuleID: moduleID,
|
|
UserID: userID,
|
|
})
|
|
if err != nil {
|
|
return 0, 0, err
|
|
}
|
|
return completed, total, nil
|
|
}
|
|
|
|
// ExamPrepUserPracticeProgressInUnit returns published practice completion counts in an exam-prep unit.
|
|
func (s *Store) ExamPrepUserPracticeProgressInUnit(ctx context.Context, userID, unitID int64) (completed, total int32, err error) {
|
|
total, err = s.queries.CountPublishedExamPrepPracticesInUnit(ctx, unitID)
|
|
if err != nil {
|
|
return 0, 0, err
|
|
}
|
|
completed, err = s.queries.CountUserCompletedPublishedExamPrepPracticesInUnit(ctx, dbgen.CountUserCompletedPublishedExamPrepPracticesInUnitParams{
|
|
UnitID: unitID,
|
|
UserID: userID,
|
|
})
|
|
if err != nil {
|
|
return 0, 0, err
|
|
}
|
|
return completed, total, nil
|
|
}
|
|
|
|
// ExamPrepUserPracticeProgressInCatalogCourse returns published practice completion counts in a catalog course.
|
|
func (s *Store) ExamPrepUserPracticeProgressInCatalogCourse(ctx context.Context, userID, catalogCourseID int64) (completed, total int32, err error) {
|
|
total, err = s.queries.CountPublishedExamPrepPracticesInCatalogCourse(ctx, catalogCourseID)
|
|
if err != nil {
|
|
return 0, 0, err
|
|
}
|
|
completed, err = s.queries.CountUserCompletedPublishedExamPrepPracticesInCatalogCourse(ctx, dbgen.CountUserCompletedPublishedExamPrepPracticesInCatalogCourseParams{
|
|
CatalogCourseID: catalogCourseID,
|
|
UserID: userID,
|
|
})
|
|
if err != nil {
|
|
return 0, 0, err
|
|
}
|
|
return completed, total, nil
|
|
}
|