Skip to content

Commit

Permalink
Made getting group courses
Browse files Browse the repository at this point in the history
  • Loading branch information
IlyaM1 committed Jan 8, 2024
1 parent c5d0ed7 commit 037114a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
8 changes: 8 additions & 0 deletions Courses/Api/GroupController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Backend.Auth.Dto;
using Backend.Base.Dto;
using Backend.Courses.Dal.Models;
using Backend.Courses.Dto;
using Backend.Courses.Logic;
using Microsoft.AspNetCore.Mvc;
Expand Down Expand Up @@ -56,6 +57,13 @@ public async Task<GroupStudentsGetAllResponseDto> GetAllStudentsByGroupId([FromR
return await _groupService.GetAllStudentsByGroupIdAsync(groupId);
}

[HttpGet]
[Route(template: "{groupId}/courses")]
public async Task<CourseGetAllDto> GetGroupCourses([FromRoute] int groupId)
{
return await _groupService.GetGroupCourses(groupId);
}

[HttpPost]
public async Task<BaseIdDto> CreateGroup([FromBody] GroupCreateDto createGroupDto)
{
Expand Down
6 changes: 3 additions & 3 deletions Courses/Logic/CourseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private async Task<List<CourseModel>> GetCoursesOfAllGroups(List<GroupModel> gro
return courses;
}

private async Task<CourseGetOneDto> MapCourseToGetOneDto(CourseModel courseModel)
public async Task<CourseGetOneDto> MapCourseToGetOneDto(CourseModel courseModel)
{
//var courseChapters = await GetChaptersByCourseId(courseModel.Id);

Expand All @@ -144,7 +144,7 @@ private async Task<CourseGetOneDto> MapCourseToGetOneDto(CourseModel courseModel
// .ToList();
//}

private CourseGetAllDto MapCoursesToGetAllDto(List<CourseModel> courseModels)
public CourseGetAllDto MapCoursesToGetAllDto(List<CourseModel> courseModels)
{
return new CourseGetAllDto()
{
Expand All @@ -154,7 +154,7 @@ private CourseGetAllDto MapCoursesToGetAllDto(List<CourseModel> courseModels)
};
}

private CourseGetAllDto.CourseDto MapCourseToCourseDtoForGetAllDto(CourseModel courseModel)
public CourseGetAllDto.CourseDto MapCourseToCourseDtoForGetAllDto(CourseModel courseModel)
{
var context = _httpContextAccessor.HttpContext;
var protocolString = context.Request.IsHttps ? "https" : "http";
Expand Down
18 changes: 18 additions & 0 deletions Courses/Logic/GroupService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ public class GroupService
private IStudentRepo _studentRepo;
private ITeacherRepo _teacherRepo;
private IAccountRepo _accountRepo;
private ICourseRepo _courseRepo;
private IGroupCoursesRepo _groupCoursesRepo;

private CourseService _courseService;

private IHttpContextAccessor _httpContextAccessor;

public GroupService(
Expand All @@ -26,6 +29,8 @@ public GroupService(
ITeacherRepo teacherRepo,
IAccountRepo accountRepo,
IGroupCoursesRepo groupCoursesRepo,
ICourseRepo courseRepo,
CourseService courseService,
IHttpContextAccessor httpContextAccessor)
{
_groupRepo = groupRepo;
Expand All @@ -34,6 +39,9 @@ public GroupService(
_teacherRepo = teacherRepo;
_accountRepo = accountRepo;
_groupCoursesRepo = groupCoursesRepo;
_courseRepo = courseRepo;

_courseService = courseService;

_httpContextAccessor = httpContextAccessor;
}
Expand Down Expand Up @@ -143,6 +151,16 @@ public async Task ConnectToGroupAsync(UserAuthInfo authInfo, GroupConnectDto con
await AddStudentToGroupAsync(userId, groupId);
}

public async Task<CourseGetAllDto> GetGroupCourses(int groupId)
{
var courseIds = await _groupCoursesRepo.GetCourseIdsByGroupIdAsync(groupId);
var courses = new List<CourseModel>();
foreach (var courseId in courseIds)
courses.Add(await _courseRepo.GetEntityByIdAsync(courseId));

return _courseService.MapCoursesToGetAllDto(courses);
}

public async Task AddStudentToGroupAsync(int userId, int groupId)
{
if (await IsStudentAlreadyInGroupAsync(userId, groupId))
Expand Down

0 comments on commit 037114a

Please sign in to comment.