Skip to content

Commit 794cad2

Browse files
committed
more doc updates
1 parent 891fac6 commit 794cad2

File tree

9 files changed

+420
-122
lines changed

9 files changed

+420
-122
lines changed

src/Arbiter.CommandQuery/Queries/EntityContinuationQuery.cs

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,40 @@
66
namespace Arbiter.CommandQuery.Queries;
77

88
/// <summary>
9-
/// A query for paging entities by continuation token based on an <see cref="EntitySelect"/>.
9+
/// Represents a query for retrieving paged entities using a continuation token based on an <see cref="EntitySelect"/>.
10+
/// The result of the query will be of type <see cref="EntityContinuationResult{TReadModel}"/>.
1011
/// </summary>
11-
/// <typeparam name="TReadModel">The type of the read model.</typeparam>
12+
/// <typeparam name="TReadModel">The type of the read model returned as the result of the query.</typeparam>
13+
/// <remarks>
14+
/// This query is typically used in scenarios where data needs to be retrieved in pages, with each page being identified
15+
/// by a continuation token. The <see cref="EntitySelect"/> allows filtering and sorting of the data.
16+
/// </remarks>
17+
/// <example>
18+
/// The following example demonstrates how to use the <see cref="EntityContinuationQuery{TReadModel}"/>:
19+
/// <code>
20+
/// var principal = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, "JohnDoe") }));
21+
/// var entitySelect = new EntitySelect
22+
/// {
23+
/// Filter = new EntityFilter { Name = "Status", Operator = "eq", Value = "Active" },
24+
/// Sort = new List&lt;EntitySort&gt; { new EntitySort { Name = "Name", Direction = "asc" } }
25+
/// };
26+
///
27+
/// var query = new EntityContinuationQuery&lt;ProductReadModel&gt;(principal, entitySelect, pageSize: 20, continuationToken: "abc123");
28+
///
29+
/// // Send the query to the mediator instance
30+
/// var result = await mediator.Send(query);
31+
/// Console.WriteLine($"Continuation Token: {result?.ContinuationToken}");
32+
/// </code>
33+
/// </example>
1234
public record EntityContinuationQuery<TReadModel> : CacheableQueryBase<EntityContinuationResult<TReadModel>>
1335
{
1436
/// <summary>
1537
/// Initializes a new instance of the <see cref="EntityContinuationQuery{TReadModel}"/> class.
1638
/// </summary>
17-
/// <param name="principal">The <see cref="ClaimsPrincipal"/> this query is run for</param>
18-
/// <param name="query">The <see cref="EntitySelect"/> for this query</param>
19-
/// <param name="pageSize">The page size for this query</param>
20-
/// <param name="continuationToken">The continuation token for this query</param>
39+
/// <param name="principal">The <see cref="ClaimsPrincipal"/> representing the user executing the query.</param>
40+
/// <param name="query">The <see cref="EntitySelect"/> defining the filter and sort criteria for the query.</param>
41+
/// <param name="pageSize">The number of items to retrieve per page.</param>
42+
/// <param name="continuationToken">The continuation token for retrieving the next page of results.</param>
2143
public EntityContinuationQuery(ClaimsPrincipal? principal, EntitySelect? query, int pageSize = 10, string? continuationToken = null)
2244
: base(principal)
2345
{
@@ -27,19 +49,19 @@ public EntityContinuationQuery(ClaimsPrincipal? principal, EntitySelect? query,
2749
}
2850

2951
/// <summary>
30-
/// The <see cref="EntitySelect"/> for this query.
52+
/// Gets the <see cref="EntitySelect"/> defining the filter and sort criteria for the query.
3153
/// </summary>
3254
[JsonPropertyName("query")]
3355
public EntitySelect Query { get; }
3456

3557
/// <summary>
36-
/// The page size for this query.
58+
/// Gets the number of items to retrieve per page.
3759
/// </summary>
3860
[JsonPropertyName("pageSize")]
3961
public int PageSize { get; }
4062

4163
/// <summary>
42-
/// The continuation token for this query.
64+
/// Gets the continuation token for retrieving the next page of results.
4365
/// </summary>
4466
[JsonPropertyName("continuationToken")]
4567
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]

src/Arbiter.CommandQuery/Queries/EntityFilter.cs

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,50 +5,100 @@
55
namespace Arbiter.CommandQuery.Queries;
66

77
/// <summary>
8-
/// A filter for selecting entities.
8+
/// Represents a filter for selecting entities based on specific criteria.
99
/// </summary>
10+
/// <remarks>
11+
/// This class is typically used in queries to define filtering criteria for entities. Filters can be combined using logical operators
12+
/// such as "and" or "or" and can include nested filters for complex queries.
13+
/// </remarks>
14+
/// <example>
15+
/// The following example demonstrates how to use the <see cref="EntityFilter"/> class as a basic filter:
16+
/// <code>
17+
/// var filter = new EntityFilter
18+
/// {
19+
/// Name = "Status",
20+
/// Operator = "eq",
21+
/// Value = "Active"
22+
/// };
23+
/// </code>
24+
/// The following example demonstrates how to use the <see cref="EntityFilter"/> class as group filter:
25+
/// <code>
26+
/// var filter = new EntityFilter
27+
/// {
28+
/// Logic = "and",
29+
/// Filters = new List&lt;EntityFilter&gt;
30+
/// {
31+
/// new EntityFilter { Name = "Priority", Operator = "gt", Value = 1 },
32+
/// new EntityFilter { Name = "Status", Operator = "eq", Value = "Active" }
33+
/// }
34+
/// };
35+
/// </code>
36+
/// </example>
1037
[JsonConverter(typeof(EntityFilterConverter))]
1138
public class EntityFilter
1239
{
1340
/// <summary>
14-
/// The name of the field or property to filter on.
41+
/// Gets or sets the name of the field or property to filter on.
1542
/// </summary>
43+
/// <value>
44+
/// The name of the field or property to filter on.
45+
/// </value>
1646
[JsonPropertyName("name")]
1747
public string? Name { get; set; }
1848

1949
/// <summary>
20-
/// The operator to use for the filter. This can be "eq", "ne", "gt", "lt", "ge", "le", "contains", "startswith", or "endswith".
50+
/// Gets or sets the operator to use for the filter. This can be "eq" (equals), "ne" (not equals), "gt" (greater than),
51+
/// "lt" (less than), "ge" (greater than or equal), "le" (less than or equal), "contains", "startswith", or "endswith".
2152
/// </summary>
53+
/// <value>
54+
/// The operator to use for the filter.
55+
/// </value>
2256
/// <seealso cref="EntityFilterOperators"/>
2357
[JsonPropertyName("operator")]
2458
public string? Operator { get; set; }
2559

2660
/// <summary>
27-
/// The value to filter on.
61+
/// Gets or sets the value to filter on.
2862
/// </summary>
63+
/// <value>
64+
/// The value to filter on.
65+
/// </value>
2966
[JsonPropertyName("value")]
3067
public object? Value { get; set; }
3168

3269
/// <summary>
33-
/// The logic to use for the filter. This can be "and" or "or". Used with <see cref="Filters"/> property.
70+
/// Gets or sets the logical operator to use for combining filters. This can be "and" or "or".
3471
/// </summary>
72+
/// <value>
73+
/// The logical operator to use for combining filters.
74+
/// </value>
3575
/// <seealso cref="EntityFilterLogic"/>
3676
[JsonPropertyName("logic")]
3777
public string? Logic { get; set; }
3878

3979
/// <summary>
40-
/// The list filters to apply to the query. The logic for these filters is defined by the <see cref="Logic"/> property.
80+
/// Gets or sets the list of nested filters to apply to the query. The logic for these filters is defined by the <see cref="Logic"/> property.
4181
/// </summary>
82+
/// <value>
83+
/// The list of nested filters to apply to the query.
84+
/// </value>
4285
[JsonPropertyName("filters")]
4386
public IList<EntityFilter>? Filters { get; set; }
4487

4588
/// <summary>
46-
/// Check if this filter is valid. A filter is valid if it has a name or if it has a list of filters.
89+
/// Determines whether this filter is valid. A filter is considered valid if it has a name or if it contains a list of valid nested filters.
4790
/// </summary>
48-
/// <returns><see langword="true" /> if filter is valid; otherwise <see langword="false" /></returns>
91+
/// <returns>
92+
/// <see langword="true" /> if the filter is valid; otherwise, <see langword="false" />.
93+
/// </returns>
4994
public bool IsValid() => Filters?.Any(f => f.IsValid()) == true || Name is not null;
5095

51-
/// <inheritdoc />
96+
/// <summary>
97+
/// Computes the hash code for the current <see cref="EntityFilter"/> instance.
98+
/// </summary>
99+
/// <returns>
100+
/// A hash code for the current <see cref="EntityFilter"/> instance.
101+
/// </returns>
52102
public override int GetHashCode()
53103
{
54104
var hash = new HashCode();

src/Arbiter.CommandQuery/Queries/EntityIdentifierQuery.cs

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,34 @@
77
namespace Arbiter.CommandQuery.Queries;
88

99
/// <summary>
10-
/// A query for a single identifier.
10+
/// Represents a query for retrieving a single entity identified by a specific key.
11+
/// The result of the query will be of type <typeparamref name="TReadModel"/>.
1112
/// </summary>
12-
/// <typeparam name="TKey">The type of the key.</typeparam>
13-
/// <typeparam name="TReadModel">The type of the read model</typeparam>
13+
/// <typeparam name="TKey">The type of the key used to identify the entity.</typeparam>
14+
/// <typeparam name="TReadModel">The type of the read model returned as the result of the query.</typeparam>
15+
/// <remarks>
16+
/// This query is typically used in a CQRS (Command Query Responsibility Segregation) pattern to retrieve a single entity
17+
/// based on its unique identifier. It supports caching to optimize repeated queries for the same entity.
18+
/// </remarks>
19+
/// <example>
20+
/// The following example demonstrates how to use the <see cref="EntityIdentifierQuery{TKey, TReadModel}"/>:
21+
/// <code>
22+
/// var principal = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, "JohnDoe") }));
23+
/// var query = new EntityIdentifierQuery&lt;int, ProductReadModel&gt;(principal, 123);
24+
///
25+
/// // Send the query to the mediator instance
26+
/// var result = await mediator.Send(query);
27+
/// Console.WriteLine($"Product Name: {result?.Name}");
28+
/// </code>
29+
/// </example>
1430
public record EntityIdentifierQuery<TKey, TReadModel> : CacheableQueryBase<TReadModel>
1531
{
1632
/// <summary>
1733
/// Initializes a new instance of the <see cref="EntityIdentifierQuery{TKey, TReadModel}"/> class.
1834
/// </summary>
19-
/// <param name="principal">the <see cref="ClaimsPrincipal"/> this query is run for</param>
20-
/// <param name="id">The identifier for this query.</param>
21-
/// <exception cref="ArgumentNullException">When <paramref name="id"/> is null</exception>
35+
/// <param name="principal">The <see cref="ClaimsPrincipal"/> representing the user executing the query.</param>
36+
/// <param name="id">The identifier of the entity to retrieve.</param>
37+
/// <exception cref="ArgumentNullException">Thrown when <paramref name="id"/> is <c>null</c>.</exception>
2238
public EntityIdentifierQuery(ClaimsPrincipal? principal, [NotNull] TKey id)
2339
: base(principal)
2440
{
@@ -28,18 +44,30 @@ public EntityIdentifierQuery(ClaimsPrincipal? principal, [NotNull] TKey id)
2844
}
2945

3046
/// <summary>
31-
/// Gets the identifier for this query.
47+
/// Gets the identifier of the entity to retrieve.
3248
/// </summary>
49+
/// <value>
50+
/// The identifier of the entity to retrieve.
51+
/// </value>
3352
[NotNull]
3453
[JsonPropertyName("id")]
3554
public TKey Id { get; }
3655

37-
38-
/// <inheritdoc/>
56+
/// <summary>
57+
/// Generates a cache key for the query based on the identifier.
58+
/// </summary>
59+
/// <returns>
60+
/// A string representing the cache key for the query.
61+
/// </returns>
3962
public override string GetCacheKey()
4063
=> CacheTagger.GetKey<TReadModel, TKey>(CacheTagger.Buckets.Identifier, Id);
4164

42-
/// <inheritdoc/>
65+
/// <summary>
66+
/// Gets the cache tag associated with the <typeparamref name="TReadModel"/>.
67+
/// </summary>
68+
/// <returns>
69+
/// The cache tag for the <typeparamref name="TReadModel"/>, or <c>null</c> if no tag is available.
70+
/// </returns>
4371
public override string? GetCacheTag()
4472
=> CacheTagger.GetTag<TReadModel>();
4573
}

src/Arbiter.CommandQuery/Queries/EntityIdentifiersQuery.cs

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,35 @@
77
namespace Arbiter.CommandQuery.Queries;
88

99
/// <summary>
10-
/// A query for a list of identifiers.
10+
/// Represents a query for retrieving multiple entities identified by a list of keys.
11+
/// The result of the query will be a collection of type <typeparamref name="TReadModel"/>.
1112
/// </summary>
12-
/// <typeparam name="TKey">The type of the key.</typeparam>
13-
/// <typeparam name="TReadModel">The type of the read model</typeparam>
13+
/// <typeparam name="TKey">The type of the keys used to identify the entities.</typeparam>
14+
/// <typeparam name="TReadModel">The type of the read model returned as the result of the query.</typeparam>
15+
/// <remarks>
16+
/// This query is typically used in a CQRS (Command Query Responsibility Segregation) pattern to retrieve multiple entities
17+
/// based on their unique identifiers. It supports caching to optimize repeated queries for the same set of entities.
18+
/// </remarks>
19+
/// <example>
20+
/// The following example demonstrates how to use the <see cref="EntityIdentifiersQuery{TKey, TReadModel}"/>:
21+
/// <code>
22+
/// var principal = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, "JohnDoe") }));
23+
/// var ids = new List&lt;int&gt; { 1, 2, 3 };
24+
/// var query = new EntityIdentifiersQuery&lt;int, ProductReadModel&gt;(principal, ids);
25+
///
26+
/// // Send the query to the mediator instance
27+
/// var result = await mediator.Send(query);
28+
/// Console.WriteLine($"Retrieved {result?.Count} products.");
29+
/// </code>
30+
/// </example>
1431
public record EntityIdentifiersQuery<TKey, TReadModel> : CacheableQueryBase<IReadOnlyCollection<TReadModel>>
1532
{
1633
/// <summary>
1734
/// Initializes a new instance of the <see cref="EntityIdentifiersQuery{TKey, TReadModel}"/> class.
1835
/// </summary>
19-
/// <param name="principal">the <see cref="ClaimsPrincipal"/> this query is run for</param>
20-
/// <param name="ids">The list of identifiers for this query.</param>
21-
/// <exception cref="ArgumentNullException">When <paramref name="ids"/> is null</exception>
36+
/// <param name="principal">The <see cref="ClaimsPrincipal"/> representing the user executing the query.</param>
37+
/// <param name="ids">The list of identifiers for the entities to retrieve.</param>
38+
/// <exception cref="ArgumentNullException">Thrown when <paramref name="ids"/> is <c>null</c>.</exception>
2239
public EntityIdentifiersQuery(ClaimsPrincipal? principal, [NotNull] IReadOnlyCollection<TKey> ids)
2340
: base(principal)
2441
{
@@ -28,16 +45,21 @@ public EntityIdentifiersQuery(ClaimsPrincipal? principal, [NotNull] IReadOnlyCol
2845
}
2946

3047
/// <summary>
31-
/// Gets the list of identifiers for this query.
48+
/// Gets the list of identifiers for the entities to retrieve.
3249
/// </summary>
3350
/// <value>
34-
/// The list of identifiers for this query.
51+
/// The list of identifiers for the entities to retrieve.
3552
/// </value>
3653
[NotNull]
3754
[JsonPropertyName("ids")]
3855
public IReadOnlyCollection<TKey> Ids { get; }
3956

40-
/// <inheritdoc/>
57+
/// <summary>
58+
/// Generates a cache key for the query based on the list of identifiers.
59+
/// </summary>
60+
/// <returns>
61+
/// A string representing the cache key for the query.
62+
/// </returns>
4163
public override string GetCacheKey()
4264
{
4365
var hash = new HashCode();
@@ -48,7 +70,12 @@ public override string GetCacheKey()
4870
return CacheTagger.GetKey<TReadModel, int>(CacheTagger.Buckets.Identifiers, hash.ToHashCode());
4971
}
5072

51-
/// <inheritdoc/>
73+
/// <summary>
74+
/// Gets the cache tag associated with the <typeparamref name="TReadModel"/>.
75+
/// </summary>
76+
/// <returns>
77+
/// The cache tag for the <typeparamref name="TReadModel"/>, or <c>null</c> if no tag is available.
78+
/// </returns>
5279
public override string? GetCacheTag()
5380
=> CacheTagger.GetTag<TReadModel>();
5481
}

0 commit comments

Comments
 (0)