Skip to content

Commit

Permalink
Made adding course to group
Browse files Browse the repository at this point in the history
  • Loading branch information
IlyaM1 committed Jan 6, 2024
1 parent decfe1e commit 5f0d825
Show file tree
Hide file tree
Showing 3 changed files with 31 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 @@ -63,6 +63,14 @@ public async Task<BaseIdDto> CreateGroup([FromBody] GroupCreateDto createGroupDt
return new BaseIdDto { Id = id };
}

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

[HttpDelete]
[Route("{id}")]
public async Task DeleteGroupById([FromRoute] int id)
Expand Down
5 changes: 5 additions & 0 deletions Courses/Dto/GroupDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,9 @@ public override GroupModel UpdateEntity(GroupModel entityToUpdate)

return entityToUpdate;
}
}

public class GroupAddCourseToGroupDto
{
public int CourseId { get; set; }
}
18 changes: 18 additions & 0 deletions Courses/Logic/GroupService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using Backend.Courses.Dal.Models;
using Backend.Courses.Dto;

using Microsoft.AspNetCore.Mvc;

namespace Backend.Courses.Logic;

public class GroupService
Expand All @@ -13,6 +15,7 @@ public class GroupService
private IStudentRepo _studentRepo;
private ITeacherRepo _teacherRepo;
private IAccountRepo _accountRepo;
private IGroupCoursesRepo _groupCoursesRepo;

private IHttpContextAccessor _httpContextAccessor;

Expand All @@ -22,13 +25,15 @@ public GroupService(
IStudentRepo studentRepo,
ITeacherRepo teacherRepo,
IAccountRepo accountRepo,
IGroupCoursesRepo groupCoursesRepo,
IHttpContextAccessor httpContextAccessor)
{
_groupRepo = groupRepo;
_studentGroupsRepo = studentGroupsRepo;
_studentRepo = studentRepo;
_teacherRepo = teacherRepo;
_accountRepo = accountRepo;
_groupCoursesRepo = groupCoursesRepo;

_httpContextAccessor = httpContextAccessor;
}
Expand Down Expand Up @@ -104,6 +109,19 @@ public async Task<int> CreateGroupAsync(GroupCreateDto createGroupDto)
return id;
}

public async Task AddCourseToGroupAsync(int groupId, GroupAddCourseToGroupDto groupAddCourseToGroupDto)
{
var courseId = groupAddCourseToGroupDto.CourseId;

var groupCourseModel = new GroupCoursesModel()
{
CourseId = courseId,
GroupId = groupId,
};

var id = await _groupCoursesRepo.CreateEntityAsync(groupCourseModel);
}

public async Task DeleteGroupByIdAsync(int id)
{
await _groupRepo.DeleteEntityByIdAsync(id);
Expand Down

0 comments on commit 5f0d825

Please sign in to comment.