|
1 | 1 | using System.Collections.Generic; |
2 | 2 | using System.Linq; |
3 | | -using System; |
4 | 3 | using System.Net; |
5 | 4 | using System.Threading.Tasks; |
6 | 5 | using AutoMapper; |
@@ -270,64 +269,15 @@ public async Task<IActionResult> GetMentorWorkspace(long courseId, string mentor |
270 | 269 | if (!mentorCourseView.Succeeded) |
271 | 270 | return BadRequest(mentorCourseView.Errors[0]); |
272 | 271 |
|
273 | | - var courseResult = await _coursesClient.GetCourseDataRaw(courseId); |
274 | | - if (!courseResult.Succeeded) |
275 | | - return BadRequest(courseResult.Errors[0]); |
| 272 | + var studentIds = mentorCourseView.Value.CourseMates.Select(t => t.StudentId).ToArray(); |
| 273 | + var students = await AuthServiceClient.GetAccountsData(studentIds); |
276 | 274 |
|
277 | | - var workspace = await CourseToMentorWorkspaceViewModel(courseResult.Value, mentorCourseView.Value); |
278 | | - return Ok(workspace); |
279 | | - } |
280 | | - |
281 | | - private async Task<WorkspaceViewModel> CourseToMentorWorkspaceViewModel(CourseDTO course, CourseDTO mentorCourseView) |
282 | | - { |
283 | | - var courseGroups = (course.Groups ?? Array.Empty<GroupViewModel>()) |
284 | | - .Where(g => !string.IsNullOrWhiteSpace(g.Name)) |
285 | | - .ToArray(); |
286 | | - |
287 | | - var filteredGroups = (mentorCourseView.Groups ?? Array.Empty<GroupViewModel>()) |
288 | | - .Where(g => !string.IsNullOrWhiteSpace(g.Name)) |
289 | | - .ToArray(); |
290 | | - |
291 | | - var selectedGroups = filteredGroups.Length == courseGroups.Length |
292 | | - ? Array.Empty<GroupViewModel>() |
293 | | - : filteredGroups; |
294 | | - |
295 | | - var selectedGroupsStudentIds = selectedGroups |
296 | | - .SelectMany(g => g.StudentsIds ?? Array.Empty<string>()) |
297 | | - .ToHashSet(); |
298 | | - |
299 | | - var selectedStudentIdsWithoutGroups = (mentorCourseView.CourseMates ?? Array.Empty<CourseMateViewModel>()) |
300 | | - .Select(t => t.StudentId) |
301 | | - .Where(studentId => !selectedGroupsStudentIds.Contains(studentId)) |
302 | | - .ToArray(); |
303 | | - |
304 | | - var selectedStudentsData = selectedStudentIdsWithoutGroups.Length == (course.CourseMates?.Length ?? 0) |
305 | | - ? Array.Empty<AccountDataDto>() |
306 | | - : await AuthServiceClient.GetAccountsData(selectedStudentIdsWithoutGroups); |
307 | | - |
308 | | - var selectedStudents = selectedStudentsData |
309 | | - .Where(x => x != null) |
310 | | - .OrderBy(x => x.Surname) |
311 | | - .ThenBy(x => x.Name) |
312 | | - .ToArray(); |
313 | | - |
314 | | - var availableHomeworks = selectedGroups.Any() |
315 | | - ? (course.Homeworks ?? Array.Empty<HomeworkViewModel>()) |
316 | | - .Where(h => h.GroupId == null || selectedGroups.Any(g => g.Id == h.GroupId)) |
317 | | - .ToArray() |
318 | | - : course.Homeworks ?? Array.Empty<HomeworkViewModel>(); |
319 | | - |
320 | | - var filteredHomeworks = mentorCourseView.Homeworks ?? Array.Empty<HomeworkViewModel>(); |
321 | | - var selectedHomeworks = filteredHomeworks.Length == availableHomeworks.Length |
322 | | - ? Array.Empty<HomeworkViewModel>() |
323 | | - : filteredHomeworks; |
324 | | - |
325 | | - return new WorkspaceViewModel |
| 275 | + return Ok(new WorkspaceViewModel |
326 | 276 | { |
327 | | - Homeworks = selectedHomeworks, |
328 | | - Students = selectedStudents, |
329 | | - Groups = selectedGroups, |
330 | | - }; |
| 277 | + Homeworks = mentorCourseView.Value.Homeworks, |
| 278 | + Students = students.OrderBy(x => x.Surname).ThenBy(x => x.Name).ToArray(), |
| 279 | + Groups = mentorCourseView.Value.Groups, |
| 280 | + }); |
331 | 281 | } |
332 | 282 |
|
333 | 283 | private async Task<CourseViewModel> ToCourseViewModel(CourseDTO course) |
|
0 commit comments