Skip to content

Commit 67d6b8a

Browse files
merge pull request #24 from https-richardy/feature/17-fluent-builder-improve-sdk-usability
[#17] - fluent builder improve sdk usability
2 parents 9b1dbd9 + be58053 commit 67d6b8a

7 files changed

Lines changed: 376 additions & 1 deletion

File tree

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
namespace HttpsRichardy.Federation.Sdk.Contracts.Filtering;
2+
3+
public sealed class GroupFilters
4+
{
5+
internal string? Id { get; private set; }
6+
internal string? RealmId { get; private set; }
7+
internal string? Name { get; private set; }
8+
9+
internal bool? IsDeleted { get; private set; }
10+
11+
internal DateOnly? CreatedAfter { get; private set; }
12+
internal DateOnly? CreatedBefore { get; private set; }
13+
14+
public GroupFilters WithIdentifier(string identifier)
15+
{
16+
if (!string.IsNullOrWhiteSpace(identifier))
17+
{
18+
Id = identifier.Trim();
19+
}
20+
21+
return this;
22+
}
23+
24+
public GroupFilters WithRealmId(string realmId)
25+
{
26+
if (!string.IsNullOrWhiteSpace(realmId))
27+
{
28+
RealmId = realmId.Trim();
29+
}
30+
31+
return this;
32+
}
33+
34+
public GroupFilters WithName(string name)
35+
{
36+
if (!string.IsNullOrWhiteSpace(name))
37+
{
38+
Name = name.Trim();
39+
}
40+
41+
return this;
42+
}
43+
44+
public GroupFilters WithIsDeleted(bool? isDeleted)
45+
{
46+
IsDeleted = isDeleted;
47+
return this;
48+
}
49+
50+
public GroupFilters WithCreatedAfter(DateOnly? createdAfter)
51+
{
52+
CreatedAfter = createdAfter;
53+
return this;
54+
}
55+
56+
public GroupFilters WithCreatedBefore(DateOnly? createdBefore)
57+
{
58+
CreatedBefore = createdBefore;
59+
return this;
60+
}
61+
62+
public static GroupsFetchParameters WithoutFilters => new();
63+
public static GroupFilters AsBuilder() => new();
64+
65+
public GroupsFetchParameters Build()
66+
{
67+
return new GroupsFetchParameters
68+
{
69+
Id = Id,
70+
RealmId = RealmId,
71+
Name = Name,
72+
IsDeleted = IsDeleted,
73+
CreatedAfter = CreatedAfter,
74+
CreatedBefore = CreatedBefore
75+
};
76+
}
77+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
namespace HttpsRichardy.Federation.Sdk.Contracts.Filtering;
2+
3+
public sealed class GroupPermissionsFilters
4+
{
5+
internal string? PermissionName { get; private set; }
6+
7+
internal int PageNumber { get; private set; } = 1;
8+
internal int PageSize { get; private set; } = 60;
9+
10+
public GroupPermissionsFilters WithPermissionName(string permissionName)
11+
{
12+
if (!string.IsNullOrWhiteSpace(permissionName))
13+
{
14+
PermissionName = permissionName.Trim();
15+
}
16+
17+
return this;
18+
}
19+
20+
public GroupPermissionsFilters WithPageNumber(int pageNumber)
21+
{
22+
if (pageNumber > 0)
23+
{
24+
PageNumber = pageNumber;
25+
}
26+
27+
return this;
28+
}
29+
30+
public GroupPermissionsFilters WithPageSize(int pageSize)
31+
{
32+
if (pageSize > 0)
33+
{
34+
PageSize = pageSize;
35+
}
36+
37+
return this;
38+
}
39+
40+
public static ListGroupPermissionsParameters WithoutFilters => new();
41+
public static GroupPermissionsFilters AsBuilder() => new();
42+
43+
public ListGroupPermissionsParameters Build()
44+
{
45+
return new ListGroupPermissionsParameters
46+
{
47+
PermissionName = PermissionName,
48+
PageNumber = PageNumber,
49+
PageSize = PageSize
50+
};
51+
}
52+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
namespace HttpsRichardy.Federation.Sdk.Contracts.Filtering;
2+
3+
public sealed class PermissionFilters
4+
{
5+
internal string? Name { get; private set; }
6+
internal bool IncludeDeleted { get; private set; } = false;
7+
8+
internal int PageNumber { get; private set; } = 1;
9+
internal int PageSize { get; private set; } = 20;
10+
11+
public PermissionFilters WithName(string name)
12+
{
13+
if (!string.IsNullOrWhiteSpace(name))
14+
{
15+
Name = name.Trim();
16+
}
17+
18+
return this;
19+
}
20+
21+
public PermissionFilters WithIncludeDeleted(bool includeDeleted)
22+
{
23+
IncludeDeleted = includeDeleted;
24+
return this;
25+
}
26+
27+
public PermissionFilters WithPageNumber(int pageNumber)
28+
{
29+
if (pageNumber > 0)
30+
{
31+
PageNumber = pageNumber;
32+
}
33+
34+
return this;
35+
}
36+
37+
public PermissionFilters WithPageSize(int pageSize)
38+
{
39+
if (pageSize > 0)
40+
{
41+
PageSize = pageSize;
42+
}
43+
44+
return this;
45+
}
46+
47+
public static PermissionsFetchParameters WithoutFilters => new();
48+
public static PermissionFilters AsBuilder() => new();
49+
50+
public PermissionsFetchParameters Build()
51+
{
52+
return new PermissionsFetchParameters
53+
{
54+
Name = Name,
55+
IncludeDeleted = IncludeDeleted,
56+
PageNumber = PageNumber,
57+
PageSize = PageSize
58+
};
59+
}
60+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
namespace HttpsRichardy.Federation.Sdk.Contracts.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+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
namespace HttpsRichardy.Federation.Sdk.Contracts.Filtering;
2+
3+
public sealed class UserFilters
4+
{
5+
internal string? Id { get; private set; }
6+
internal string? Username { get; private set; }
7+
8+
internal bool? IsDeleted { get; private set; }
9+
10+
internal int PageNumber { get; private set; } = 1;
11+
internal int PageSize { get; private set; } = 60;
12+
13+
public UserFilters WithIdentifier(string identifier)
14+
{
15+
if (!string.IsNullOrWhiteSpace(identifier))
16+
{
17+
Id = identifier.Trim();
18+
}
19+
20+
return this;
21+
}
22+
23+
public UserFilters WithUsername(string username)
24+
{
25+
if (!string.IsNullOrWhiteSpace(username))
26+
{
27+
Username = username.Trim();
28+
}
29+
30+
return this;
31+
}
32+
33+
public UserFilters WithIsDeleted(bool? isDeleted)
34+
{
35+
IsDeleted = isDeleted;
36+
return this;
37+
}
38+
39+
public UserFilters WithPageNumber(int pageNumber)
40+
{
41+
if (pageNumber > 0)
42+
{
43+
PageNumber = pageNumber;
44+
}
45+
46+
return this;
47+
}
48+
49+
public UserFilters WithPageSize(int pageSize)
50+
{
51+
if (pageSize > 0)
52+
{
53+
PageSize = pageSize;
54+
}
55+
56+
return this;
57+
}
58+
59+
public static UsersFetchParameters WithoutFilters => new();
60+
public static UserFilters AsBuilder() => new();
61+
62+
public UsersFetchParameters Build()
63+
{
64+
return new UsersFetchParameters
65+
{
66+
Id = Id,
67+
Username = Username,
68+
IsDeleted = IsDeleted,
69+
PageNumber = PageNumber,
70+
PageSize = PageSize
71+
};
72+
}
73+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
namespace HttpsRichardy.Federation.Sdk.Contracts.Filtering;
2+
3+
public sealed class UserGroupsFilters
4+
{
5+
internal int PageNumber { get; private set; } = 1;
6+
internal int PageSize { get; private set; } = 60;
7+
8+
public UserGroupsFilters WithPageNumber(int pageNumber)
9+
{
10+
if (pageNumber > 0)
11+
{
12+
PageNumber = pageNumber;
13+
}
14+
15+
return this;
16+
}
17+
18+
public UserGroupsFilters WithPageSize(int pageSize)
19+
{
20+
if (pageSize > 0)
21+
{
22+
PageSize = pageSize;
23+
}
24+
25+
return this;
26+
}
27+
28+
public static ListUserAssignedGroupsParameters WithoutFilters => new();
29+
public static UserGroupsFilters AsBuilder() => new();
30+
31+
public ListUserAssignedGroupsParameters Build()
32+
{
33+
return new ListUserAssignedGroupsParameters
34+
{
35+
PageNumber = PageNumber,
36+
PageSize = PageSize
37+
};
38+
}
39+
}

Packages/Federation.Sdk/Source/Helpers/QueryParametersHelper.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ public static string ToQueryString<TParameters>(TParameters instance)
1313
foreach (var property in properties)
1414
{
1515
var value = property.GetValue(instance);
16-
if (value is null) continue;
16+
if (value is null)
17+
continue;
1718

1819
string name = ToCamelCase(property.Name);
1920
string stringValue = value switch

0 commit comments

Comments
 (0)