< Summary - Syki

Information
Class: Syki.Back.Features.Students.EnrollStudentInCourseOffering.EnrollStudentInCourseOfferingService
Assembly: Back
File(s): /home/runner/work/syki/syki/Back/Features/Students/EnrollStudentInCourseOffering/EnrollStudentInCourseOfferingService.cs
Tag: 97_27801654829
Line coverage
0%
Covered lines: 0
Uncovered lines: 14
Coverable lines: 14
Total lines: 27
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%
Enroll()0%4260%

File(s)

/home/runner/work/syki/syki/Back/Features/Students/EnrollStudentInCourseOffering/EnrollStudentInCourseOfferingService.cs

#LineLine coverage
 1using Syki.Back.Domain.Students;
 2
 3namespace Syki.Back.Features.Students.EnrollStudentInCourseOffering;
 4
 05public class EnrollStudentInCourseOfferingService(SykiDbContext ctx) : ISykiService
 6{
 7    public async Task<OneOf<EnrollStudentInCourseOfferingOut, SykiError>> Enroll(int studentId, EnrollStudentInCourseOff
 8    {
 09        var institutionId = ctx.RequestUser.InstitutionId;
 10
 011        var student = await ctx.Students.FirstOrDefaultAsync(s => s.Id == studentId && s.InstitutionId == institutionId)
 012        if (student == null) return StudentNotFound.I;
 13
 014        var offering = await ctx.CourseOfferings.FirstOrDefaultAsync(o => o.Id == data.CourseOfferingId && o.Institution
 015        if (offering == null) return CourseOfferingNotFound.I;
 16
 017        var alreadyEnrolled = await ctx.StudentCourseEnrollments
 018            .AnyAsync(e => e.StudentId == studentId && e.CourseOfferingId == data.CourseOfferingId);
 019        if (alreadyEnrolled) return StudentAlreadyEnrolledInCourseOffering.I;
 20
 021        var enrollment = new StudentCourseEnrollment(studentId, data.CourseOfferingId);
 022        ctx.Add(enrollment);
 023        await ctx.SaveChangesAsync();
 24
 025        return new EnrollStudentInCourseOfferingOut { Id = enrollment.Id };
 026    }
 27}