Skip to content

Commit

Permalink
Unconnect course from group
Browse files Browse the repository at this point in the history
  • Loading branch information
IlyaM1 committed Jan 8, 2024
1 parent 6c1d8e2 commit 6441870
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Courses/Api/GroupController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ public async Task<IResult> AddCourseToGroup([FromRoute] int groupId, [FromBody]
return Results.Ok();
}

[HttpDelete]
[Route(template: "{groupId}/courses/one")]
public async Task<IResult> DeleteCourseFromGroup([FromRoute] int groupId, [FromBody] GroupAddCourseToGroupDto groupAddCourseToGroupDto)
{
await _groupService.DeleteCourseFromGroup(groupId, groupAddCourseToGroupDto);
return Results.Ok();
}

[HttpPost]
[Route(template: "{groupId}/courses/many")]
public async Task<IResult> AddManyCoursesToGroupAsync([FromRoute] int groupId, [FromBody] GroupAddManyCoursesToGroupDto groupAddManyCoursesToGroupDto)
Expand Down
7 changes: 7 additions & 0 deletions Courses/Logic/GroupService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@ public async Task ConnectToGroupAsync(UserAuthInfo authInfo, GroupConnectDto con
await AddStudentToGroupAsync(userId, groupId);
}

public async Task DeleteCourseFromGroup(int groupId, GroupAddCourseToGroupDto groupAddCourseToGroupDto)
{
var conn = (await _groupCoursesRepo.GetAllEntitiesAsync()).Where(x => x.GroupId == groupId && x.CourseId == groupAddCourseToGroupDto.CourseId).FirstOrDefault();
if (conn is not null)
await _groupCoursesRepo.DeleteEntityByIdAsync(conn.Id);
}

public async Task<CourseGetAllDto> GetGroupCourses(int groupId)
{
var courseIds = await _groupCoursesRepo.GetCourseIdsByGroupIdAsync(groupId);
Expand Down

0 comments on commit 6441870

Please sign in to comment.