< Summary - Estud

Information
Class: Estud.Back.Features.Classes.ReleaseClassForEnrollment.ReleaseClassForEnrollmentService
Assembly: Back
File(s): /home/runner/work/syki/syki/Back/Features/Classes/ReleaseClassForEnrollment/ReleaseClassForEnrollmentService.cs
Tag: 114_29044117136
Line coverage
0%
Covered lines: 0
Uncovered lines: 13
Coverable lines: 13
Total lines: 24
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 6
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
Release()0%4260%

File(s)

/home/runner/work/syki/syki/Back/Features/Classes/ReleaseClassForEnrollment/ReleaseClassForEnrollmentService.cs

#LineLine coverage
 1namespace Estud.Back.Features.Classes.ReleaseClassForEnrollment;
 2
 03public class ReleaseClassForEnrollmentService(EstudDbContext ctx) : IEstudService
 4{
 5    public async Task<OneOf<EstudSuccess, EstudError>> Release(int id)
 6    {
 07        var institutionId = ctx.RequestUser.InstitutionId;
 8
 09        var @class = await ctx.Classes.FirstOrDefaultAsync(c => c.Id == id && c.InstitutionId == institutionId);
 010        if (@class == null) return ClassNotFound.I;
 11
 012        var today = DateTime.UtcNow.ToDateOnly();
 013        var hasCurrentEnrollmentPeriod = await ctx.EnrollmentPeriods
 014            .AnyAsync(p => p.InstitutionId == institutionId && p.StartAt <= today && today <= p.EndAt);
 015        if (!hasCurrentEnrollmentPeriod) return NoCurrentEnrollmentPeriod.I;
 16
 017        if (@class.Status != ClassStatus.OnPreEnrollment) return ClassMustBeOnPreEnrollment.I;
 18
 019        @class.Status = ClassStatus.OnEnrollment;
 020        await ctx.SaveChangesAsync();
 21
 022        return EstudSuccess.I;
 023    }
 24}