88using HwProj . Models ;
99using HwProj . Models . CoursesService . ViewModels ;
1010using HwProj . NotificationService . Events . CoursesService ;
11- using HwProj . CoursesService . API . Repositories . Groups ;
12- using Microsoft . EntityFrameworkCore ;
1311
1412namespace HwProj . CoursesService . API . Services
1513{
@@ -18,16 +16,16 @@ public class HomeworksService : IHomeworksService
1816 private readonly IHomeworksRepository _homeworksRepository ;
1917 private readonly IEventBus _eventBus ;
2018 private readonly ICoursesRepository _coursesRepository ;
21- private readonly IGroupMatesRepository _groupMatesRepository ;
19+ private readonly IGroupsService _groupsService ;
2220 private readonly ICourseFilterService _courseFilterService ;
2321
2422 public HomeworksService ( IHomeworksRepository homeworksRepository , IEventBus eventBus , ICoursesRepository coursesRepository ,
25- IGroupMatesRepository groupMatesRepository , IGroupsService groupsService , ICourseFilterService courseFilterService )
23+ IGroupsService groupsService , ICourseFilterService courseFilterService )
2624 {
2725 _homeworksRepository = homeworksRepository ;
2826 _eventBus = eventBus ;
2927 _coursesRepository = coursesRepository ;
30- _groupMatesRepository = groupMatesRepository ;
28+ _groupsService = groupsService ;
3129 _courseFilterService = courseFilterService ;
3230 }
3331
@@ -44,7 +42,9 @@ public async Task<Homework> AddHomeworkAsync(long courseId, CreateHomeworkViewMo
4442
4543 if ( homework . GroupId != null )
4644 {
47- var groupMates = await _groupMatesRepository . FindAll ( gm => gm . GroupId == homework . GroupId ) . ToArrayAsync ( ) ;
45+ var group = ( await _groupsService . GetGroupsAsync ( new [ ] { homework . GroupId . Value } ) ) . FirstOrDefault ( ) ;
46+ var groupMates = group ? . GroupMates . ToArray ( ) ?? Array . Empty < GroupMate > ( ) ;
47+
4848 await _courseFilterService . UpdateGroupFilters ( courseId , homework . Id , groupMates ) ;
4949 notificationStudentIds = groupMates . Select ( gm => gm . StudentId ) . ToArray ( ) ;
5050 }
@@ -103,9 +103,10 @@ public async Task<Homework> UpdateHomeworkAsync(long homeworkId, CreateHomeworkV
103103
104104 if ( update . GroupId != null )
105105 {
106- var groupMates = await _groupMatesRepository . FindAll ( gm => gm . GroupId == update . GroupId ) . ToArrayAsync ( ) ;
107- await _courseFilterService . UpdateGroupFilters ( course . Id , homework . Id , groupMates ) ;
106+ var group = ( await _groupsService . GetGroupsAsync ( new [ ] { update . GroupId . Value } ) ) . FirstOrDefault ( ) ;
107+ var groupMates = group ? . GroupMates . ToArray ( ) ?? Array . Empty < GroupMate > ( ) ;
108108
109+ await _courseFilterService . UpdateGroupFilters ( course . Id , homework . Id , groupMates ) ;
109110 notificationStudentIds = groupMates . Select ( gm => gm . StudentId ) . ToArray ( ) ;
110111 }
111112
0 commit comments