• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

karanshukla / openresto / 28881805559

07 Jul 2026 04:23PM UTC coverage: 94.253% (+0.07%) from 94.185%
28881805559

Pull #209

github

web-flow
Merge 55996179b into 108a871bd
Pull Request #209: Massive Refactor

4316 of 4939 branches covered (87.39%)

Branch coverage included in aggregate %.

1466 of 1601 new or added lines in 120 files covered. (91.57%)

65 existing lines in 27 files now uncovered.

13954 of 14445 relevant lines covered (96.6%)

83.46 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.24
/OpenRestoApi/Infrastructure/Persistence/Repositories/AdminNotificationRepository.cs
1
using CustomAccessibility.Attributes;
2
using Microsoft.EntityFrameworkCore;
3
using OpenRestoApi.Core.Application.Interfaces;
4
using OpenRestoApi.Core.Domain;
5

6
namespace OpenRestoApi.Infrastructure.Persistence.Repositories;
7

8
[OnlyAccessibleBy("OpenRestoApi.Extensions.ServiceCollectionExtensions")]
9
[OnlyAccessibleBy("OpenRestoApi.Tests.Services.NotificationServiceTests")]
10
[OnlyAccessibleBy("OpenRestoApi.Tests.Services.BookingNotificationServiceTests")]
11
[ExternalAccessAllowed]
12
internal class AdminNotificationRepository(AppDbContext db) : IAdminNotificationRepository
66✔
13
{
14
    private readonly AppDbContext _db = db;
66✔
15

16
    public async Task<AdminNotification?> FindByIdAsync(int id)
17
    {
NEW
18
        return await _db.AdminNotifications.FindAsync(id);
×
NEW
19
    }
×
20

21
    public async Task<AdminNotification> AddAsync(AdminNotification notification)
22
    {
23
        _db.AdminNotifications.Add(notification);
10✔
24
        await _db.SaveChangesAsync();
10✔
25
        return notification;
10✔
26
    }
10✔
27

28
    public async Task<(List<AdminNotification> Items, int TotalCount)> QueryPagedAsync(int? restaurantId, string? type, bool? unreadOnly, int page, int pageSize)
29
    {
30
        IQueryable<AdminNotification> q = _db.AdminNotifications.AsQueryable();
10✔
31

32
        if (restaurantId.HasValue)
10✔
33
        {
34
            q = q.Where(n => n.RestaurantId == restaurantId.Value);
2✔
35
        }
36

37
        if (!string.IsNullOrWhiteSpace(type))
10✔
38
        {
39
            q = q.Where(n => n.Type == type);
2✔
40
        }
41

42
        if (unreadOnly == true)
10✔
43
        {
44
            q = q.Where(n => !n.IsRead);
2✔
45
        }
46

47
        q = q.OrderByDescending(n => n.CreatedAt);
10✔
48

49
        int total = await q.CountAsync();
10✔
50
        List<AdminNotification> items = await q
10✔
51
            .Skip((page - 1) * pageSize)
10✔
52
            .Take(pageSize)
10✔
53
            .ToListAsync();
10✔
54

55
        return (items, total);
10✔
56
    }
10✔
57

58
    public async Task<int> CountUnreadAsync(int? restaurantId)
59
    {
60
        return await _db.AdminNotifications.CountAsync(n =>
4✔
61
            (!restaurantId.HasValue || n.RestaurantId == restaurantId.Value) && !n.IsRead);
4✔
62
    }
4✔
63

64
    public async Task MarkReadAsync(int notificationId)
65
    {
66
        AdminNotification? n = await _db.AdminNotifications.FindAsync(notificationId);
6✔
67
        if (n is { IsRead: false })
6✔
68
        {
69
            n.IsRead = true;
2✔
70
            await _db.SaveChangesAsync();
2✔
71
        }
72
    }
6✔
73

74
    public async Task<int> MarkAllReadAsync(int restaurantId)
75
    {
76
        return await _db.AdminNotifications
2✔
77
            .Where(n => n.RestaurantId == restaurantId && !n.IsRead)
2✔
78
            .ExecuteUpdateAsync(s => s.SetProperty(n => n.IsRead, true));
4✔
79
    }
2✔
80

81
    public async Task DeleteByIdAsync(int notificationId)
82
    {
83
        AdminNotification? n = await _db.AdminNotifications.FindAsync(notificationId);
4✔
84
        if (n is not null)
4✔
85
        {
86
            _db.AdminNotifications.Remove(n);
2✔
87
            await _db.SaveChangesAsync();
2✔
88
        }
89
    }
4✔
90

91
    public async Task DeleteByIdsAsync(List<int> notificationIds)
92
    {
93
        List<AdminNotification> notifications = await _db.AdminNotifications
4✔
94
            .Where(n => notificationIds.Contains(n.Id))
4✔
95
            .ToListAsync();
4✔
96

97
        if (notifications.Count > 0)
4✔
98
        {
99
            _db.AdminNotifications.RemoveRange(notifications);
2✔
100
            await _db.SaveChangesAsync();
2✔
101
        }
102
    }
4✔
103

104
    public async Task<int> DeleteAllAsync(int? restaurantId, string? type, bool? unreadOnly)
105
    {
106
        IQueryable<AdminNotification> q = _db.AdminNotifications.AsQueryable();
8✔
107

108
        if (restaurantId.HasValue)
8✔
109
        {
110
            q = q.Where(n => n.RestaurantId == restaurantId.Value);
2✔
111
        }
112

113
        if (!string.IsNullOrWhiteSpace(type))
8✔
114
        {
115
            q = q.Where(n => n.Type == type);
2✔
116
        }
117

118
        if (unreadOnly == true)
8✔
119
        {
120
            q = q.Where(n => !n.IsRead);
2✔
121
        }
122

123
        return await q.ExecuteDeleteAsync();
8✔
124
    }
8✔
125

126
    public async Task<bool> ExistsNearlyFullForDayAsync(int restaurantId, DateTime dayStartUtc, DateTime dayEndUtc)
127
    {
128
        return await _db.AdminNotifications.AnyAsync(n =>
4✔
129
            n.RestaurantId == restaurantId &&
4✔
130
            n.Type == NotificationType.RestaurantNearlyFull &&
4✔
131
            n.BookingDate >= dayStartUtc &&
4✔
132
            n.BookingDate < dayEndUtc);
4✔
133
    }
4✔
134

135
    public async Task SaveChangesAsync()
136
    {
NEW
137
        await _db.SaveChangesAsync();
×
NEW
138
    }
×
139
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc