< Summary - Estud

Information
Class: Estud.Back.Features.Students.CreateStudent.CreateStudentService
Assembly: Back
File(s): /home/runner/work/syki/syki/Back/Features/Students/CreateStudent/CreateStudentService.cs
Tag: 114_29044117136
Line coverage
100%
Covered lines: 18
Uncovered lines: 0
Coverable lines: 18
Total lines: 36
Line coverage: 100%
Branch coverage
75%
Covered branches: 3
Total branches: 4
Branch coverage: 75%
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()83.33%66100%

File(s)

/home/runner/work/syki/syki/Back/Features/Students/CreateStudent/CreateStudentService.cs

#LineLine coverage
 1using Estud.Back.Domain.Identity;
 2using Estud.Back.Domain.Students;
 3using Estud.Back.Domain.Webhooks;
 4
 5namespace Estud.Back.Features.Students.CreateStudent;
 6
 367public class CreateStudentService(EstudDbContext ctx, UserManager<EstudUser> userManager) : IEstudService
 8{
 9    public async Task<OneOf<CreateStudentOut, EstudError>> Create(CreateStudentIn data)
 10    {
 3611        var email = data.Email.ToLowerInvariant();
 3612        var emailUsed = await ctx.Users.AnyAsync(u => u.Email == email);
 3813        if (emailUsed) return EmailAlreadyUsed.I;
 14
 3415        var studentRole = await ctx.GetStudentRole();
 3416        var institutionId = ctx.RequestUser.InstitutionId;
 17
 3418        var user = new EstudUser(institutionId, data.Name, email);
 3419        var student = new EstudStudent(user, institutionId, data.Name);
 3420        var userRole = new EstudUserRole(institutionId, user, studentRole.Id);
 3421        ctx.AddRange(student, userRole);
 22
 23        // TODO: Refactor to use Domain Events Pattern
 3424        var webhookSubscriptions = await ctx.WebhookSubscriptions.Where(x => x.InstitutionId == institutionId && x.IsAct
 3425            .Select(x => new { x.Id, x.Events }).ToListAsync() ?? [];
 12226        foreach (var webhookSubscription in webhookSubscriptions.Where(x => x.Events.Contains(WebhookEventType.StudentCr
 27        {
 1828            var webhookCall = new WebhookCall(institutionId, webhookSubscription.Id, new { student.Name, user.Email }, W
 1829            ctx.Add(webhookCall);
 30        }
 31
 3432        await userManager.CreateAsync(user, $"Estud@{Guid.NewGuid()}");
 33
 3434        return new CreateStudentOut { Id = student.Id };
 3635    }
 36}