60 lines
1.7 KiB
Go
60 lines
1.7 KiB
Go
package repository
|
|
|
|
import (
|
|
"context"
|
|
|
|
dbgen "Yimaru-Backend/gen/db"
|
|
"Yimaru-Backend/internal/domain"
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
// GetLMSUserProgressSnapshot returns practice-based completed lesson, module, course,
|
|
// and program IDs for a user.
|
|
func (s *Store) GetLMSUserProgressSnapshot(ctx context.Context, userID int64) (domain.LMSUserProgress, error) {
|
|
lessons, err := s.queries.ListLMSCompletedLessonIDsByUser(ctx, userID)
|
|
if err != nil {
|
|
return domain.LMSUserProgress{}, err
|
|
}
|
|
mods, err := s.queries.ListLMSCompletedModuleIDsByUser(ctx, userID)
|
|
if err != nil {
|
|
return domain.LMSUserProgress{}, err
|
|
}
|
|
courses, err := s.queries.ListLMSCompletedCourseIDsByUser(ctx, userID)
|
|
if err != nil {
|
|
return domain.LMSUserProgress{}, err
|
|
}
|
|
programs, err := s.queries.ListLMSCompletedProgramIDsByUser(ctx, userID)
|
|
if err != nil {
|
|
return domain.LMSUserProgress{}, err
|
|
}
|
|
return domain.LMSUserProgress{
|
|
LessonIDs: pgInt8IDsToInt64(lessons),
|
|
ModuleIDs: pgInt8IDsToInt64(mods),
|
|
CourseIDs: pgInt8IDsToInt64(courses),
|
|
ProgramIDs: int64IDsOrEmpty(programs),
|
|
}, nil
|
|
}
|
|
|
|
func pgInt8IDsToInt64(items []pgtype.Int8) []int64 {
|
|
out := make([]int64, 0, len(items))
|
|
for _, item := range items {
|
|
if !item.Valid {
|
|
continue
|
|
}
|
|
out = append(out, item.Int64)
|
|
}
|
|
return out
|
|
}
|
|
|
|
func int64IDsOrEmpty(items []int64) []int64 {
|
|
if items == nil {
|
|
return []int64{}
|
|
}
|
|
return items
|
|
}
|
|
|
|
// ListUserLMSFlatLearningActivity returns flattened LMS activity rows for admin reporting (lesson + practice completions).
|
|
func (s *Store) ListUserLMSFlatLearningActivity(ctx context.Context, userID int64) ([]dbgen.ListUserLMSFlatLearningActivityByUserRow, error) {
|
|
return s.queries.ListUserLMSFlatLearningActivityByUser(ctx, userID)
|
|
}
|