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

b1f6c1c4 / ProfessionalAccounting / 327

28 Apr 2025 05:37PM UTC coverage: 51.346% (-3.0%) from 54.325%
327

push

appveyor

b1f6c1c4
ci buildx

6620 of 12893 relevant lines covered (51.35%)

126.37 hits per line

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

21.62
/AccountingServer.BLL/Util/QueryHelper.cs
1
/* Copyright (C) 2020-2025 b1f6c1c4
2
 *
3
 * This file is part of ProfessionalAccounting.
4
 *
5
 * ProfessionalAccounting is free software: you can redistribute it and/or
6
 * modify it under the terms of the GNU Affero General Public License as
7
 * published by the Free Software Foundation, version 3.
8
 *
9
 * ProfessionalAccounting is distributed in the hope that it will be useful, but
10
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License
12
 * for more details.
13
 *
14
 * You should have received a copy of the GNU Affero General Public License
15
 * along with ProfessionalAccounting.  If not, see
16
 * <https://www.gnu.org/licenses/>.
17
 */
18

19
using System;
20
using System.Collections.Generic;
21
using System.Linq;
22
using AccountingServer.Entities;
23
using AccountingServer.Entities.Util;
24

25
namespace AccountingServer.BLL.Util;
26

27
public abstract class BinaryQueries<TAtom> : IQueryAry<TAtom> where TAtom : class
28
{
29
    protected BinaryQueries(IQueryCompounded<TAtom> filter1,
7✔
30
        IQueryCompounded<TAtom> filter2)
31
    {
7✔
32
        Filter1 = filter1;
7✔
33
        Filter2 = filter2;
7✔
34
    }
7✔
35

36
    public abstract OperatorType Operator { get; }
37

38
    public IQueryCompounded<TAtom> Filter1 { get; }
39

40
    public IQueryCompounded<TAtom> Filter2 { get; }
41

42
    public T Accept<T>(IQueryVisitor<TAtom, T> visitor) => visitor.Visit(this);
13✔
43
}
44

45
public sealed class IntersectQueries<TAtom> : BinaryQueries<TAtom> where TAtom : class
46
{
47
    public IntersectQueries(IQueryCompounded<TAtom> filter1,
48
        IQueryCompounded<TAtom> filter2) : base(filter1, filter2) { }
7✔
49

50
    public override OperatorType Operator => OperatorType.Intersect;
13✔
51
}
52

53
public sealed class UnionQueries<TAtom> : BinaryQueries<TAtom> where TAtom : class
54
{
55
    public UnionQueries(IQueryCompounded<TAtom> filter1,
56
        IQueryCompounded<TAtom> filter2) : base(filter1, filter2) { }
×
57

58
    public override OperatorType Operator => OperatorType.Union;
×
59
}
60

61
public sealed class SubtractQueries<TAtom> : BinaryQueries<TAtom> where TAtom : class
62
{
63
    public SubtractQueries(IQueryCompounded<TAtom> filter1,
64
        IQueryCompounded<TAtom> filter2) : base(filter1, filter2) { }
×
65

66
    public override OperatorType Operator => OperatorType.Subtract;
×
67
}
68

69
public sealed class SimpleDetailQuery : IDetailQueryAtom
70
{
71
    public TitleKind? Kind { get; init; }
72
    public VoucherDetail Filter { get; init; }
73
    public bool? IsPseudoCurrency { get; init; }
74
    public bool IsFundBidirectional { get; init; }
75
    public int Dir { get; init; }
76
    public string ContentPrefix { get; init; }
77
    public string RemarkPrefix { get; init; }
78
    public T Accept<T>(IQueryVisitor<IDetailQueryAtom, T> visitor) => visitor.Visit(this);
×
79
}
80

81
public sealed class SimpleVoucherQuery : IVoucherQueryAtom
82
{
83
    public bool ForAll { get; init; } = false;
×
84
    public Voucher VoucherFilter { get; init; } = null;
×
85
    public DateFilter Range { get; init; } = DateFilter.Unconstrained;
×
86
    public string RemarkPrefix { get; init; } = null;
×
87
    public IQueryCompounded<IDetailQueryAtom> DetailFilter { get; init; } = null;
×
88
    public T Accept<T>(IQueryVisitor<IVoucherQueryAtom, T> visitor) => visitor.Visit(this);
×
89
}
90

91
public static class QueryHelper
92
{
93
    public static IQueryCompounded<TAtom> QueryAny<TAtom>(
94
            this IEnumerable<IQueryCompounded<TAtom>> lst) where TAtom : class
95
        => !lst.Any() ? null : lst.First().QueryAny(lst.Skip(1));
×
96

97
    public static IQueryCompounded<TAtom> QueryAll<TAtom>(
98
            this IEnumerable<IQueryCompounded<TAtom>> lst) where TAtom : class
99
    {
×
100
        if (lst.Any())
×
101
            lst.First().QueryAll(lst.Skip(1));
×
102

103
        if (lst is IEnumerable<IQueryCompounded<IDetailQueryAtom>>)
×
104
            return (IQueryCompounded<TAtom>)DetailQueryUnconstrained.Instance;
×
105

106
        if (lst is IEnumerable<IQueryCompounded<IVoucherQueryAtom>>)
×
107
            return (IQueryCompounded<TAtom>)VoucherQueryUnconstrained.Instance;
×
108

109
        if (lst is IEnumerable<IQueryCompounded<IDistributedQueryAtom>>)
×
110
            return (IQueryCompounded<TAtom>)DistributedQueryUnconstrained.Instance;
×
111

112
        throw new NotImplementedException();
×
113
    }
×
114

115
    public static IQueryCompounded<TAtom> QueryAny<TAtom>(
116
            this IQueryCompounded<TAtom> b,
117
            IEnumerable<IQueryCompounded<TAtom>> lst) where TAtom : class
118
        => b == null ? lst.QueryAny()
×
119
            : lst.Where(static (c) => c != null).Aggregate(b, (q, v) => new UnionQueries<TAtom>(q, v));
×
120

121
    public static IQueryCompounded<TAtom> QueryAll<TAtom>(
122
            this IQueryCompounded<TAtom> b,
123
            IEnumerable<IQueryCompounded<TAtom>> lst) where TAtom : class
124
        => b == null ? null
×
125
            : lst.Where(static (c) => c != null).Aggregate(b, (q, v) => new IntersectQueries<TAtom>(q, v));
×
126

127
    public static IQueryCompounded<TAtom> QueryBut<TAtom>(
128
            this IQueryCompounded<TAtom> b,
129
            IEnumerable<IQueryCompounded<TAtom>> lst) where TAtom : class
130
        => b == null ? null
×
131
            : lst.Where(static (c) => c != null).Aggregate(b, (q, v) => new SubtractQueries<TAtom>(q, v));
×
132
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc