< Summary - Syki

Information
Class: Syki.Back.Features.Notifications.MarkNotificationsAsViewed.MarkNotificationsAsViewedService
Assembly: Back
File(s): /home/runner/work/syki/syki/Back/Features/Notifications/MarkNotificationsAsViewed/MarkNotificationsAsViewedService.cs
Tag: 97_27801654829
Line coverage
0%
Covered lines: 0
Uncovered lines: 17
Coverable lines: 17
Total lines: 34
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%
.ctor()100%210%
.cctor()100%210%
MarkAsViewed()0%4260%

File(s)

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

#LineLine coverage
 1namespace Syki.Back.Features.Notifications.MarkNotificationsAsViewed;
 2
 03public class MarkNotificationsAsViewedService(SykiDbContext ctx) : ISykiService
 4{
 5    private class Validator : AbstractValidator<MarkNotificationsAsViewedIn>
 6    {
 07        public Validator()
 8        {
 09            When(x => !x.MarkAll, () =>
 010            {
 011                RuleFor(x => x.NotificationId).NotNull().WithError(InvalidNotificationId.I);
 012            });
 013        }
 14    }
 015    private static readonly Validator V = new();
 16
 17    public async Task<OneOf<SykiSuccess, SykiError>> MarkAsViewed(MarkNotificationsAsViewedIn data)
 18    {
 019        if (V.Run(data, out var error)) return error;
 20
 021        var query = ctx.UserNotifications.Where(x => x.UserId == ctx.RequestUser.Id && x.ViewedAt == null);
 022        if (!data.MarkAll) query = query.Where(x => x.NotificationId == data.NotificationId);
 23
 024        var notifications = await query.ToListAsync();
 025        foreach (var notification in notifications)
 26        {
 027            notification.ViewedAt = DateTime.UtcNow;
 28        }
 29
 030        await ctx.SaveChangesAsync();
 31
 032        return SykiSuccess.I;
 033    }
 34}