< Summary

Information
Class: Syki.Back.Features.Academic.StartClasses.StartClassesService
Assembly: Back
File(s): /home/runner/work/syki/syki/Back/Features/Academic/StartClasses/StartClassesService.cs
Tag: 22_11348620282
Line coverage
100%
Covered lines: 18
Uncovered lines: 0
Coverable lines: 18
Total lines: 32
Line coverage: 100%
Branch coverage
90%
Covered branches: 9
Total branches: 10
Branch coverage: 90%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
Start()90%1010100%

File(s)

/home/runner/work/syki/syki/Back/Features/Academic/StartClasses/StartClassesService.cs

#LineLine coverage
 1namespace Syki.Back.Features.Academic.StartClasses;
 2
 3073public class StartClassesService(SykiDbContext ctx) : IAcademicService
 4{
 5    public async Task<OneOf<SykiSuccess, SykiError>> Start(Guid institutionId, StartClassesIn data)
 6    {
 417        var classes = await ctx.Classes
 418            .Include(x => x.Students)
 419            .Where(c => c.InstitutionId == institutionId && data.Classes.Contains(c.Id))
 4110            .ToListAsync();
 11
 4212        if (classes.Count == 0) return new InvalidClassesList();
 13
 19514        var statusOk = classes.All(x => x.Status == ClassStatus.OnEnrollment);
 4115        if (!statusOk) return new ClassMustHaveOnEnrollmentStatus();
 16
 3917        var today = DateTime.Now.ToDateOnly();
 3918        var periods = await ctx.EnrollmentPeriods.AsNoTracking().Where(x => x.InstitutionId == institutionId).ToListAsyn
 38519        foreach (var @class in classes)
 20        {
 30821            var period = periods.FirstOrDefault(x => x.Id == @class.PeriodId);
 15422            if (period == null) return new EnrollmentPeriodNotFound();
 15523            if (today <= period.EndAt) return new EnrollmentPeriodMustBeFinalized();
 24        }
 25
 19126        classes.ForEach(c => c.Start());
 27
 3828        await ctx.SaveChangesAsync();
 29
 3830        return new SykiSuccess();
 4131    }
 32}