< Summary - Syki

Information
Class: Syki.Back.Features.Students.GetStudents.GetStudentsService
Assembly: Back
File(s): /home/runner/work/syki/syki/Back/Features/Students/GetStudents/GetStudentsService.cs
Tag: 56_26538939494
Line coverage
100%
Covered lines: 17
Uncovered lines: 0
Coverable lines: 17
Total lines: 28
Line coverage: 100%
Branch coverage
50%
Covered branches: 1
Total branches: 2
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
Get()100%11100%

File(s)

/home/runner/work/syki/syki/Back/Features/Students/GetStudents/GetStudentsService.cs

#LineLine coverage
 1namespace Syki.Back.Features.Students.GetStudents;
 2
 23public class GetStudentsService(SykiDbContext ctx) : ISykiService
 4{
 5    public async Task<GetStudentsOut> Get()
 6    {
 27        var institutionId = ctx.RequestUser.InstitutionId;
 8
 29        var students = await ctx.Students.AsNoTracking()
 210            .Include(s => s.User)
 211            .Where(s => s.InstitutionId == institutionId)
 212            .OrderBy(s => s.Name)
 213            .ToListAsync();
 14
 615        var studentIds = students.Select(s => s.Id).ToHashSet();
 16
 217        var enrollmentCounts = await ctx.StudentCourseEnrollments.AsNoTracking()
 218            .Where(e => studentIds.Contains(e.StudentId) && e.LeftAt == null)
 219            .GroupBy(e => e.StudentId)
 220            .Select(g => new { StudentId = g.Key, Count = g.Count() })
 221            .ToListAsync();
 22
 623        var result = students.ConvertAll(s => s.ToGetStudentsItemOut());
 624        result.ForEach(s => s.ActiveEnrollments = enrollmentCounts.FirstOrDefault(e => e.StudentId == s.Id)?.Count ?? 0)
 25
 226        return new GetStudentsOut { Total = result.Count, Items = result };
 227    }
 28}