(ctx context.Context, schoolId, studentId, moduleId primitive.ObjectID)
| 142 | } |
| 143 | |
| 144 | func (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 | |
| 184 | func (s *StudentsService) GetLesson(ctx context.Context, studentId, lessonId primitive.ObjectID) (domain.Lesson, error) { |
| 185 | if err := s.isLessonAvailable(ctx, studentId, lessonId); err != nil { |
nothing calls this directly
no test coverage detected