< Summary - Syki

Information
Class: Syki.Back.Features.Cross.SeedInstitutionData.SeedInstitutionEnrollmentsCommandHandler
Assembly: Back
File(s): /home/runner/work/syki/syki/Back/Features/Cross/SeedInstitutionData/SeedInstitutionEnrollmentsCommand.cs
Tag: 4_16869239191
Line coverage
0%
Covered lines: 0
Uncovered lines: 30
Coverable lines: 30
Total lines: 54
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 2
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%
Handle()0%620%

File(s)

/home/runner/work/syki/syki/Back/Features/Cross/SeedInstitutionData/SeedInstitutionEnrollmentsCommand.cs

#LineLine coverage
 1using Syki.Back.Features.Academic.StartClasses;
 2using Syki.Back.Features.Student.CreateStudentEnrollment;
 3using Syki.Back.Features.Academic.UpdateEnrollmentPeriod;
 4using Syki.Back.Features.Academic.CreateEnrollmentPeriod;
 5using Syki.Back.Features.Academic.ReleaseClassesForEnrollment;
 6
 7namespace Syki.Back.Features.Cross.SeedInstitutionData;
 8
 9[CommandDescription("Realizar seed de matrículas da instituição")]
 10public record SeedInstitutionEnrollmentsCommand(Guid InstitutionId, Guid AdsCourseCurriculumId) : ICommand;
 11
 012public class SeedInstitutionEnrollmentsCommandHandler(
 013    SykiDbContext ctx,
 014    StartClassesService startClassesService,
 015    CreateEnrollmentPeriodService createEnrollmentPeriodService,
 016    UpdateEnrollmentPeriodService updateEnrollmentPeriodService,
 017    CreateStudentEnrollmentService createStudentEnrollmentService,
 018    ReleaseClassesForEnrollmentService releaseClassesForEnrollmentService) : ICommandHandler<SeedInstitutionEnrollmentsC
 19{
 20    public async Task Handle(CommandId commandId, SeedInstitutionEnrollmentsCommand command)
 21    {
 022        var id = command.InstitutionId;
 023        var today = DateTime.UtcNow.ToDateOnly();
 024        var academicPeriod = $"{today.Year}.1";
 025        var firstDay = new DateTime(today.Year, 1, 1).ToDateOnly();
 026        var lastDay = new DateTime(today.Year, 12, 31).ToDateOnly();
 27
 028        await createEnrollmentPeriodService.CreateWithThrowOnError(id, new()
 029        {
 030            Id = academicPeriod,
 031            StartAt = firstDay,
 032            EndAt = lastDay,
 033        });
 34
 035        var classes = await ctx.Classes.Where(x => x.InstitutionId == id).Select(x => x.Id).ToListAsync();
 036        await releaseClassesForEnrollmentService.ReleaseWithThrowOnError(id, new() { Classes = classes });
 37
 038        var adsCourseOfferingId = await ctx.CourseOfferings
 039            .Where(x => x.InstitutionId == id && x.CourseCurriculumId == command.AdsCourseCurriculumId)
 040            .Select(x => x.Id).FirstAsync();
 41
 042        var students = await ctx.Students.Where(x => x.CourseOfferingId == adsCourseOfferingId).Select(x => new { x.Id }
 043        foreach (var student in students)
 44        {
 045            await createStudentEnrollmentService.CreateWithThrowOnError(id, student.Id, command.AdsCourseCurriculumId, n
 46        }
 47
 048        await updateEnrollmentPeriodService.UpdateWithThrowOnError(id, academicPeriod, new() { StartAt = new DateTime(to
 49
 050        await startClassesService.StartWithThrowOnError(id, new() { Classes = classes });
 51
 052        ctx.AddCommand(id, new SeedInstitutionLessonAttendancesCommand(id), parentId: commandId);
 053    }
 54}