< Summary - Estud

Information
Class: Estud.Back.Features.Notifications.MarkNotificationsAsViewed.MarkNotificationsAsViewedService
Assembly: Back
File(s): /home/runner/work/syki/syki/Back/Features/Notifications/MarkNotificationsAsViewed/MarkNotificationsAsViewedService.cs
Tag: 114_29044117136
Line coverage
100%
Covered lines: 17
Uncovered lines: 0
Coverable lines: 17
Total lines: 34
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
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%
.ctor()100%11100%
.cctor()100%11100%
MarkAsViewed()100%66100%

File(s)

/home/runner/work/syki/syki/Back/Features/Notifications/MarkNotificationsAsViewed/MarkNotificationsAsViewedService.cs

#LineLine coverage
 1namespace Estud.Back.Features.Notifications.MarkNotificationsAsViewed;
 2
 83public class MarkNotificationsAsViewedService(EstudDbContext ctx) : IEstudService
 4{
 5    private class Validator : AbstractValidator<MarkNotificationsAsViewedIn>
 6    {
 27        public Validator()
 8        {
 109            When(x => !x.MarkAll, () =>
 210            {
 211                RuleFor(x => x.NotificationId).NotNull().WithError(InvalidNotificationId.I);
 412            });
 213        }
 14    }
 215    private static readonly Validator V = new();
 16
 17    public async Task<OneOf<EstudSuccess, EstudError>> MarkAsViewed(MarkNotificationsAsViewedIn data)
 18    {
 1019        if (V.Run(data, out var error)) return error;
 20
 621        var query = ctx.UserNotifications.Where(x => x.UserId == ctx.RequestUser.Id && x.ViewedAt == null);
 822        if (!data.MarkAll) query = query.Where(x => x.NotificationId == data.NotificationId);
 23
 624        var notifications = await query.ToListAsync();
 2825        foreach (var notification in notifications)
 26        {
 827            notification.ViewedAt = DateTime.UtcNow;
 28        }
 29
 630        await ctx.SaveChangesAsync();
 31
 632        return EstudSuccess.I;
 833    }
 34}