Skip to content

Commit a3cca01

Browse files
feature(#17): this commit introduces a fluent class for building query parameters, improving the SDK's usability
1 parent ef5035a commit a3cca01

1 file changed

Lines changed: 73 additions & 0 deletions

File tree

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
namespace HttpsRichardy.Federation.Sdk.Filtering;
2+
3+
public sealed class RealmFilters
4+
{
5+
internal string? Id { get; private set; }
6+
internal string? Name { get; private set; }
7+
8+
internal bool? IncludeDeleted { get; private set; }
9+
10+
internal int PageNumber { get; private set; } = 1;
11+
internal int PageSize { get; private set; } = 20;
12+
13+
public RealmFilters WithIdentifier(string identifier)
14+
{
15+
if (!string.IsNullOrWhiteSpace(identifier))
16+
{
17+
Id = identifier.Trim();
18+
}
19+
20+
return this;
21+
}
22+
23+
public RealmFilters WithName(string name)
24+
{
25+
if (!string.IsNullOrWhiteSpace(name))
26+
{
27+
Name = name.Trim();
28+
}
29+
30+
return this;
31+
}
32+
33+
public RealmFilters WithIncludeDeleted(bool? includeDeleted)
34+
{
35+
IncludeDeleted = includeDeleted;
36+
return this;
37+
}
38+
39+
public RealmFilters WithPageNumber(int pageNumber)
40+
{
41+
if (pageNumber > 0)
42+
{
43+
PageNumber = pageNumber;
44+
}
45+
46+
return this;
47+
}
48+
49+
public RealmFilters WithPageSize(int pageSize)
50+
{
51+
if (pageSize > 0)
52+
{
53+
PageSize = pageSize;
54+
}
55+
56+
return this;
57+
}
58+
59+
public static RealmFetchParameters WithoutFilters => new();
60+
public static RealmFilters AsBuilder() => new();
61+
62+
public RealmFetchParameters Build()
63+
{
64+
return new RealmFetchParameters
65+
{
66+
Id = Id,
67+
Name = Name,
68+
IncludeDeleted = IncludeDeleted,
69+
PageNumber = PageNumber,
70+
PageSize = PageSize
71+
};
72+
}
73+
}

0 commit comments

Comments
 (0)