package classes import ( "git.golem15.com/golem15/sm-quizzes-plugin/graders" "git.golem15.com/golem15/summercms/modules/backpack" "git.golem15.com/golem15/summercms/modules/conga" "gorm.io/gorm" ) // ForApp builds the service the application runs on db: the scoring and // test grace from its config, the grader registry golem15.quizzes // published at boot, its event bus and its job queue. Each part that is // missing stays nil and the service works without it (no graders, no // events, no jobs). A nil app gives a service with the default grace only. func ForApp(app *backpack.App, db *gorm.DB) *Service { if app == nil { return &Service{DB: db, Grace: DefaultTestGrace} } s := &Service{ DB: db, Scoring: ScoringConfigFrom(app.Config), Grace: TestGraceFrom(app.Config), Events: app.Events, } if reg, ok := app.Lookup[*graders.Registry](); ok { s.Graders = reg } if m, err := conga.From(app); err == nil && m != nil { s.Jobs = m } return s }