Skip to content

Commit 42aad30

Browse files
committed
refactor
1 parent ca0bf09 commit 42aad30

1 file changed

Lines changed: 0 additions & 53 deletions

File tree

HwProj.APIGateway/HwProj.APIGateway.API/Controllers/CoursesController.cs

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System.Collections.Generic;
22
using System.Linq;
3-
using System;
43
using System.Net;
54
using System.Threading.Tasks;
65
using AutoMapper;
@@ -282,58 +281,6 @@ public async Task<IActionResult> GetMentorWorkspace(long courseId, string mentor
282281
return Ok(workspace);
283282
}
284283

285-
private async Task<WorkspaceViewModel> CourseToMentorWorkspaceViewModel(CourseDTO course, CourseDTO mentorCourseView)
286-
{
287-
var courseGroups = (course.Groups ?? Array.Empty<GroupViewModel>())
288-
.Where(g => !string.IsNullOrWhiteSpace(g.Name))
289-
.ToArray();
290-
291-
var filteredGroups = (mentorCourseView.Groups ?? Array.Empty<GroupViewModel>())
292-
.Where(g => !string.IsNullOrWhiteSpace(g.Name))
293-
.ToArray();
294-
295-
var selectedGroups = filteredGroups.Length == courseGroups.Length
296-
? Array.Empty<GroupViewModel>()
297-
: filteredGroups;
298-
299-
var selectedGroupsStudentIds = selectedGroups
300-
.SelectMany(g => g.StudentsIds ?? Array.Empty<string>())
301-
.ToHashSet();
302-
303-
var selectedStudentIdsWithoutGroups = (mentorCourseView.CourseMates ?? Array.Empty<CourseMateViewModel>())
304-
.Select(t => t.StudentId)
305-
.Where(studentId => !selectedGroupsStudentIds.Contains(studentId))
306-
.ToArray();
307-
308-
var selectedStudentsData = selectedStudentIdsWithoutGroups.Length == (course.CourseMates?.Length ?? 0)
309-
? Array.Empty<AccountDataDto>()
310-
: await AuthServiceClient.GetAccountsData(selectedStudentIdsWithoutGroups);
311-
312-
var selectedStudents = selectedStudentsData
313-
.Where(x => x != null)
314-
.OrderBy(x => x.Surname)
315-
.ThenBy(x => x.Name)
316-
.ToArray();
317-
318-
var availableHomeworks = selectedGroups.Any()
319-
? (course.Homeworks ?? Array.Empty<HomeworkViewModel>())
320-
.Where(h => h.GroupId == null || selectedGroups.Any(g => g.Id == h.GroupId))
321-
.ToArray()
322-
: course.Homeworks ?? Array.Empty<HomeworkViewModel>();
323-
324-
var filteredHomeworks = mentorCourseView.Homeworks ?? Array.Empty<HomeworkViewModel>();
325-
var selectedHomeworks = filteredHomeworks.Length == availableHomeworks.Length
326-
? Array.Empty<HomeworkViewModel>()
327-
: filteredHomeworks;
328-
329-
return new WorkspaceViewModel
330-
{
331-
Homeworks = selectedHomeworks,
332-
Students = selectedStudents,
333-
Groups = selectedGroups,
334-
};
335-
}
336-
337284
private async Task<CourseViewModel> ToCourseViewModel(CourseDTO course)
338285
{
339286
var studentIds = course.CourseMates.Select(t => t.StudentId).ToArray();

0 commit comments

Comments
 (0)