• 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

96.92
/OpenRestoApi/Infrastructure/Persistence/Repositories/SectionRepository.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.BookingServiceTests")]
10
[OnlyAccessibleBy("OpenRestoApi.Tests.Services.AdminServiceTests")]
11
[OnlyAccessibleBy("OpenRestoApi.Tests.Services.RestaurantManagementServiceTests")]
12
[OnlyAccessibleBy("OpenRestoApi.Tests.Services.WalkInTests")]
13
[OnlyAccessibleBy("OpenRestoApi.Tests.Controllers.AdminControllerRestoreTests")]
14
[OnlyAccessibleBy("OpenRestoApi.Tests.Controllers.AdminControllerSectionsReorderTests")]
15
[OnlyAccessibleBy("OpenRestoApi.Tests.Controllers.AdminControllerUpdateTests")]
16
[OnlyAccessibleBy("OpenRestoApi.Tests.Controllers.AdminControllerEmailTests")]
17
[OnlyAccessibleBy("OpenRestoApi.Tests.Controllers.AdminControllerLookupTests")]
18
[OnlyAccessibleBy("OpenRestoApi.Tests.Integration.RepositoryTests")]
19
[ExternalAccessAllowed]
20
internal class SectionRepository(AppDbContext db) : ISectionRepository
748✔
21
{
22
    private readonly AppDbContext _db = db;
748✔
23

24
    public async Task<Section?> GetByIdAsync(int id)
25
    {
26
        return await _db.Sections.FindAsync(id);
80✔
27
    }
80✔
28

29
    // ── Bundle 2 additions ─────────────────────────────────────────────────────
30

31
    public async Task<Section?> FindByIdAsync(int id)
32
    {
NEW
UNCOV
33
        return await _db.Sections.FindAsync(id);
×
NEW
UNCOV
34
    }
×
35

36
    public async Task<List<Section>> GetByRestaurantAsync(int restaurantId)
37
    {
38
        return await _db.Sections
22✔
39
            .Where(s => s.RestaurantId == restaurantId)
22✔
40
            .OrderBy(s => s.SortOrder).ThenBy(s => s.Id)
22✔
41
            .ToListAsync();
22✔
42
    }
22✔
43

44
    public async Task<List<Section>> GetByRestaurantAsync(int restaurantId, bool includeTables)
45
    {
46
        IQueryable<Section> q = _db.Sections
10✔
47
            .Where(s => s.RestaurantId == restaurantId)
10✔
48
            .OrderBy(s => s.SortOrder).ThenBy(s => s.Id);
10✔
49

50
        if (includeTables)
10✔
51
        {
52
            q = q.Include(s => s.Tables);
10✔
53
        }
54

55
        return await q.ToListAsync();
10✔
56
    }
10✔
57

58
    public async Task<int> CountByRestaurantAsync(int restaurantId)
59
    {
60
        return await _db.Sections.CountAsync(s => s.RestaurantId == restaurantId);
66✔
61
    }
66✔
62

63
    public async Task<bool?> ReorderAsync(int restaurantId, IReadOnlyList<int> sectionIds)
64
    {
65
        bool restaurantExists = await _db.Restaurants.AnyAsync(r => r.Id == restaurantId);
50✔
66
        if (!restaurantExists)
50✔
67
        {
68
            return null;
6✔
69
        }
70

71
        if (sectionIds == null)
44✔
72
        {
73
            return false;
2✔
74
        }
75

76
        List<Section> sections = await _db.Sections
42✔
77
            .Where(s => s.RestaurantId == restaurantId)
42✔
78
            .ToListAsync();
42✔
79

80
        if (sectionIds.Count != sections.Count ||
42✔
81
            sectionIds.Distinct().Count() != sectionIds.Count)
42✔
82
        {
83
            return false;
10✔
84
        }
85

86
        Dictionary<int, Section> sectionsById = sections.ToDictionary(s => s.Id);
112✔
87
        if (sectionIds.Any(id => !sectionsById.ContainsKey(id)))
112✔
88
        {
89
            return false;
2✔
90
        }
91

92
        for (int i = 0; i < sectionIds.Count; i++)
216✔
93
        {
94
            sectionsById[sectionIds[i]].SortOrder = i;
78✔
95
        }
96

97
        await _db.SaveChangesAsync();
30✔
98
        return true;
30✔
99
    }
50✔
100

101
    public async Task AddAsync(Section section)
102
    {
103
        _db.Sections.Add(section);
66✔
104
        await _db.SaveChangesAsync();
66✔
105
    }
66✔
106

107
    public void Remove(Section section)
108
    {
109
        _db.Sections.Remove(section);
4✔
110
    }
4✔
111

112
    public async Task<Section?> FindForRestaurantAsync(int sectionId, int restaurantId)
113
    {
114
        return await _db.Sections
18✔
115
            .FirstOrDefaultAsync(s => s.Id == sectionId && s.RestaurantId == restaurantId);
18✔
116
    }
18✔
117

118
    public async Task<Section?> GetWithTablesForRestaurantAsync(int sectionId, int restaurantId)
119
    {
120
        return await _db.Sections
8✔
121
            .Include(s => s.Tables)
8✔
122
            .FirstOrDefaultAsync(s => s.Id == sectionId && s.RestaurantId == restaurantId);
8✔
123
    }
8✔
124

125
    public async Task SaveChangesAsync()
126
    {
127
        await _db.SaveChangesAsync();
8✔
128
    }
8✔
129
}
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