Add migration 000109, require parent context on complete, and update progress queries and LMS rollups. Co-authored-by: Cursor <cursoragent@cursor.com>
62 lines
1.7 KiB
Go
62 lines
1.7 KiB
Go
package repository
|
|
|
|
import (
|
|
"context"
|
|
|
|
dbgen "Yimaru-Backend/gen/db"
|
|
"Yimaru-Backend/internal/domain"
|
|
|
|
"github.com/jackc/pgx/v5"
|
|
)
|
|
|
|
func (s *Store) ExamPrepGetPreviousCatalogCourse(ctx context.Context, catalogCourseID int64) (int64, error) {
|
|
row, err := s.queries.GetPreviousExamPrepCatalogCourse(ctx, catalogCourseID)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return row.ID, nil
|
|
}
|
|
|
|
func (s *Store) ExamPrepGetPreviousUnitInCatalogCourse(ctx context.Context, unitID int64) (int64, error) {
|
|
row, err := s.queries.GetPreviousExamPrepUnitInCatalogCourse(ctx, unitID)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return row.ID, nil
|
|
}
|
|
|
|
func (s *Store) ExamPrepGetPreviousModuleInUnit(ctx context.Context, moduleID int64) (int64, error) {
|
|
row, err := s.queries.GetPreviousExamPrepModuleInUnit(ctx, moduleID)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return row.ID, nil
|
|
}
|
|
|
|
func (s *Store) ExamPrepGetPreviousLessonInModule(ctx context.Context, lessonID int64) (int64, error) {
|
|
row, err := s.queries.GetPreviousExamPrepLessonInModule(ctx, lessonID)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return row.ID, nil
|
|
}
|
|
|
|
func (s *Store) GetFirstIncompletePreviousExamPrepPractice(ctx context.Context, userID, questionSetID int64, parentKind string, parentID int64) (*domain.PracticeAccessBlock, error) {
|
|
row, err := s.queries.GetFirstIncompletePreviousExamPrepPractice(ctx, dbgen.GetFirstIncompletePreviousExamPrepPracticeParams{
|
|
UserID: userID,
|
|
QuestionSetID: questionSetID,
|
|
ParentKind: parentKind,
|
|
ParentID: parentID,
|
|
})
|
|
if err != nil {
|
|
if err == pgx.ErrNoRows {
|
|
return nil, nil
|
|
}
|
|
return nil, err
|
|
}
|
|
return &domain.PracticeAccessBlock{
|
|
QuestionSetID: row.QuestionSetID,
|
|
Title: row.Title,
|
|
}, nil
|
|
}
|