MCPcopy Create free account
hub / github.com/Creatly/creatly-backend / GetModuleContent

Method GetModuleContent

internal/service/students.go:144–182  ·  view source on GitHub ↗
(ctx context.Context, schoolId, studentId, moduleId primitive.ObjectID)

Source from the content-addressed store, hash-verified

142}
143
144func (s *StudentsService) GetModuleContent(ctx context.Context, schoolId, studentId, moduleId primitive.ObjectID) (domain.ModuleContent, error) {
145 // Get module with lessons content, check if it is available for student
146 module, err := s.modulesService.GetWithContent(ctx, moduleId)
147 if err != nil {
148 return domain.ModuleContent{}, err
149 }
150
151 student, err := s.repo.GetById(ctx, schoolId, studentId)
152 if err != nil {
153 return domain.ModuleContent{}, err
154 }
155
156 if student.IsModuleAvailable(module) {
157 return domain.ModuleContent{
158 Lessons: module.Lessons,
159 Survey: module.Survey,
160 }, nil
161 }
162
163 // Find module offers
164 offers, err := s.offersService.GetByModule(ctx, schoolId, module.ID)
165 if err != nil {
166 return domain.ModuleContent{}, err
167 }
168
169 if len(offers) != 0 {
170 return domain.ModuleContent{}, domain.ErrModuleIsNotAvailable
171 }
172
173 // If module has no offers - it's free and available to everyone
174 if err := s.repo.GiveAccessToModule(ctx, studentId, moduleId); err != nil {
175 return domain.ModuleContent{}, err
176 }
177
178 return domain.ModuleContent{
179 Lessons: module.Lessons,
180 Survey: module.Survey,
181 }, nil
182}
183
184func (s *StudentsService) GetLesson(ctx context.Context, studentId, lessonId primitive.ObjectID) (domain.Lesson, error) {
185 if err := s.isLessonAvailable(ctx, studentId, lessonId); err != nil {

Callers

nothing calls this directly

Calls 5

IsModuleAvailableMethod · 0.80
GetWithContentMethod · 0.65
GetByIdMethod · 0.65
GetByModuleMethod · 0.65
GiveAccessToModuleMethod · 0.65

Tested by

no test coverage detected