< Summary

Information
Class: Syki.Back.Features.Academic.CreateCourseOffering.CreateCourseOfferingService
Assembly: Back
File(s): /home/runner/work/syki/syki/Back/Features/Academic/CreateCourseOffering/CreateCourseOfferingService.cs
Tag: 22_11348620282
Line coverage
100%
Covered lines: 30
Uncovered lines: 0
Coverable lines: 30
Total lines: 44
Line coverage: 100%
Branch coverage
100%
Covered branches: 10
Total branches: 10
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

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

File(s)

/home/runner/work/syki/syki/Back/Features/Academic/CreateCourseOffering/CreateCourseOfferingService.cs

#LineLine coverage
 1namespace Syki.Back.Features.Academic.CreateCourseOffering;
 2
 2173public class CreateCourseOfferingService(SykiDbContext ctx) : IAcademicService
 4{
 5    public async Task<OneOf<CourseOfferingOut, SykiError>> Create(Guid institutionId, CreateCourseOfferingIn data)
 6    {
 2177        var campusOk = await ctx.Campi
 2178            .AnyAsync(c => c.InstitutionId == institutionId && c.Id == data.CampusId);
 2199        if (!campusOk) return new CampusNotFound();
 10
 21511        var courseOk = await ctx.Courses
 21512            .AnyAsync(c => c.InstitutionId == institutionId && c.Id == data.CourseId);
 21713        if (!courseOk) return new CourseNotFound();
 14
 21315        var courseCurriculumOk = await ctx.CourseCurriculums
 21316            .AnyAsync(g => g.InstitutionId == institutionId && g.Id == data.CourseCurriculumId && g.CourseId == data.Cou
 21517        if (!courseCurriculumOk) return new CourseCurriculumNotFound();
 18
 21119        var periodExists = await ctx.AcademicPeriodExists(institutionId, data.Period);
 21320        if (!periodExists) return new AcademicPeriodNotFound();
 21
 21022        if (!data.Shift.IsValid()) return new InvalidShift();
 23
 20824        var courseOffering = new CourseOffering(
 20825            institutionId,
 20826            data.CampusId,
 20827            data.CourseId,
 20828            data.CourseCurriculumId,
 20829            data.Period!,
 20830            data.Shift
 20831        );
 32
 20833        ctx.CourseOfferings.Add(courseOffering);
 20834        await ctx.SaveChangesAsync();
 35
 20836        courseOffering = await ctx.CourseOfferings.AsNoTracking()
 20837            .Include(x => x.Campus)
 20838            .Include(x => x.Course)
 20839            .Include(x => x.CourseCurriculum)
 20840            .FirstAsync(x => x.Id == courseOffering.Id);
 41
 20842        return courseOffering.ToOut();
 21743    }
 44}