< Summary - Syki

Information
Class: Syki.Back.Features.Academic.CreateNotification.CreateNotificationService
Assembly: Back
File(s): /home/runner/work/syki/syki/Back/Features/Academic/CreateNotification/CreateNotificationService.cs
Tag: 4_16869239191
Line coverage
100%
Covered lines: 25
Uncovered lines: 0
Coverable lines: 25
Total lines: 43
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%
CreateNotificationFor()100%11100%

File(s)

/home/runner/work/syki/syki/Back/Features/Academic/CreateNotification/CreateNotificationService.cs

#LineLine coverage
 1namespace Syki.Back.Features.Academic.CreateNotification;
 2
 243public class CreateNotificationService(SykiDbContext ctx) : IAcademicService
 4{
 5    public async Task<NotificationOut> Create(Guid institutionId, CreateNotificationIn data)
 6    {
 247        var notification = new Notification(institutionId, data.Title, data.Description, data.TargetUsers, data.Timeless
 8
 249        if (data.TargetUsers is UsersGroup.All or UsersGroup.Teachers)
 10        {
 1411            await CreateNotificationFor(institutionId, notification.Id, UserRole.Teacher);
 12        }
 2413        if (data.TargetUsers is UsersGroup.All or UsersGroup.Students)
 14        {
 1615            await CreateNotificationFor(institutionId, notification.Id, UserRole.Student);
 16        }
 17
 2418        ctx.Add(notification);
 2419        await ctx.SaveChangesAsync();
 20
 2421        return notification.ToOut();
 2422    }
 23
 24    private async Task CreateNotificationFor(Guid institutionId, Guid notificationId, UserRole userRole)
 25    {
 3026        FormattableString sql = $@"
 3027            SELECT
 3028                u.id
 3029            FROM
 3030                syki.users u
 3031            INNER JOIN
 3032                syki.roles r ON r.name = {userRole.ToString()}
 3033            INNER JOIN
 3034                syki.user_roles ur ON ur.user_id = u.id AND ur.role_id = r.id
 3035            WHERE
 3036                u.institution_id = {institutionId}
 3037        ";
 38
 3039        var usersIds = await ctx.Database.SqlQuery<Guid>(sql).ToListAsync();
 40
 4841        usersIds.ForEach(userId => ctx.UserNotifications.Add(new UserNotification(userId, notificationId)));
 3042    }
 43}