|
3 | 3 | using System.Linq.Expressions; |
4 | 4 | using System.Threading; |
5 | 5 | using System.Threading.Tasks; |
| 6 | +using OneBeyond.Studio.Application.SharedKernel.Repositories.Exceptions; |
6 | 7 | using OneBeyond.Studio.Application.SharedKernel.Specifications; |
7 | 8 | using OneBeyond.Studio.Domain.SharedKernel.Entities; |
8 | 9 | using OneBeyond.Studio.Domain.SharedKernel.Specifications; |
9 | 10 |
|
10 | 11 | namespace OneBeyond.Studio.Application.SharedKernel.Repositories; |
11 | 12 |
|
12 | 13 | /// <summary> |
13 | | -/// Represents a repository with read-only operations. |
| 14 | +/// Read-only repository exposing query operations over <typeparamref name="TEntity"/>. |
| 15 | +/// Results are detached. |
14 | 16 | /// </summary> |
| 17 | +/// <typeparam name="TEntity">Type of the queried entity.</typeparam> |
15 | 18 | public interface IRORepository<TEntity> |
16 | 19 | { |
| 20 | + /// <summary> |
| 21 | + /// Returns the entities matching <paramref name="filter"/>, or all entities when it is <see langword="null"/>. |
| 22 | + /// </summary> |
| 23 | + /// <param name="filter">Predicate to match, or <see langword="null"/> to match every entity.</param> |
| 24 | + /// <param name="includes">Related object graph to load alongside each entity, or <see langword="null"/> for none.</param> |
| 25 | + /// <param name="paging">Slice of the result set to return, or <see langword="null"/> for all matches.</param> |
| 26 | + /// <param name="sortings">Ordering to apply.</param> |
| 27 | + /// <param name="cancellationToken">Token used to cancel the operation.</param> |
17 | 28 | Task<IReadOnlyCollection<TEntity>> ListAsync( |
18 | 29 | Expression<Func<TEntity, bool>>? filter = default, |
19 | 30 | Includes<TEntity>? includes = default, |
20 | 31 | Paging? paging = default, |
21 | 32 | IReadOnlyCollection<Sorting<TEntity>>? sortings = default, |
22 | 33 | CancellationToken cancellationToken = default); |
23 | 34 |
|
| 35 | + /// <summary> |
| 36 | + /// Projects the entities matching <paramref name="preFilter"/> onto <typeparamref name="TResultDto"/>, |
| 37 | + /// then returns those matching <paramref name="filter"/>. |
| 38 | + /// </summary> |
| 39 | + /// <remarks> |
| 40 | + /// <paramref name="preFilter"/> is applied in entity space before projection; <paramref name="filter"/> |
| 41 | + /// is applied in result space after it. The projection is resolved from the registered mapping for |
| 42 | + /// <typeparamref name="TResultDto"/>. |
| 43 | + /// </remarks> |
| 44 | + /// <typeparam name="TResultDto">Type each entity is projected onto.</typeparam> |
| 45 | + /// <param name="preFilter">Predicate applied to entities before projection, or <see langword="null"/> to match all.</param> |
| 46 | + /// <param name="filter">Predicate applied to projected results, or <see langword="null"/> to match all.</param> |
| 47 | + /// <param name="paging">Slice of the result set to return, or <see langword="null"/> for all matches.</param> |
| 48 | + /// <param name="sortings">Ordering to apply.</param> |
| 49 | + /// <param name="cancellationToken">Token used to cancel the operation.</param> |
24 | 50 | Task<IReadOnlyCollection<TResultDto>> ListAsync<TResultDto>( |
25 | 51 | Expression<Func<TEntity, bool>>? preFilter, |
26 | 52 | Expression<Func<TResultDto, bool>>? filter = default, |
27 | 53 | Paging? paging = default, |
28 | 54 | IReadOnlyCollection<Sorting<TResultDto>>? sortings = default, |
29 | 55 | CancellationToken cancellationToken = default); |
30 | 56 |
|
| 57 | + /// <summary> |
| 58 | + /// Returns the entities matching <paramref name="filter"/> projected onto <typeparamref name="TResultDto"/> |
| 59 | + /// via <paramref name="projection"/>. |
| 60 | + /// </summary> |
| 61 | + /// <typeparam name="TResultDto">Type each entity is projected onto.</typeparam> |
| 62 | + /// <param name="projection">Expression mapping an entity to a result. Translated to the query, not run in memory.</param> |
| 63 | + /// <param name="filter">Predicate applied to entities before projection, or <see langword="null"/> to match all.</param> |
| 64 | + /// <param name="paging">Slice of the result set to return, or <see langword="null"/> for all matches.</param> |
| 65 | + /// <param name="sortings">Ordering applied to entities before projection.</param> |
| 66 | + /// <param name="cancellationToken">Token used to cancel the operation.</param> |
31 | 67 | Task<IReadOnlyCollection<TResultDto>> ListAsync<TResultDto>( |
32 | 68 | Expression<Func<TEntity, TResultDto>> projection, |
33 | 69 | Expression<Func<TEntity, bool>>? filter = default, |
34 | 70 | Paging? paging = default, |
35 | 71 | IReadOnlyCollection<Sorting<TEntity>>? sortings = default, |
36 | 72 | CancellationToken cancellationToken = default); |
37 | 73 |
|
| 74 | + /// <summary> |
| 75 | + /// Counts the entities matching <paramref name="filter"/>, or all entities when it is <see langword="null"/>. |
| 76 | + /// </summary> |
| 77 | + /// <param name="filter">Predicate to match, or <see langword="null"/> to count every entity.</param> |
| 78 | + /// <param name="cancellationToken">Token used to cancel the operation.</param> |
38 | 79 | Task<int> CountAsync( |
39 | 80 | Expression<Func<TEntity, bool>>? filter = default, |
40 | 81 | CancellationToken cancellationToken = default); |
41 | 82 |
|
| 83 | + /// <summary> |
| 84 | + /// Counts the entities matching <paramref name="preFilter"/> whose <typeparamref name="TResultDto"/> |
| 85 | + /// projection matches <paramref name="filter"/>. |
| 86 | + /// </summary> |
| 87 | + /// <typeparam name="TResultDto">Type each entity is projected onto.</typeparam> |
| 88 | + /// <param name="preFilter">Predicate applied to entities before projection, or <see langword="null"/> to match all.</param> |
| 89 | + /// <param name="filter">Predicate applied to projected results, or <see langword="null"/> to match all.</param> |
| 90 | + /// <param name="cancellationToken">Token used to cancel the operation.</param> |
42 | 91 | Task<int> CountAsync<TResultDto>( |
43 | 92 | Expression<Func<TEntity, bool>>? preFilter, |
44 | 93 | Expression<Func<TResultDto, bool>>? filter = default, |
45 | 94 | CancellationToken cancellationToken = default); |
46 | 95 |
|
| 96 | + /// <summary> |
| 97 | + /// Determines whether any entity matches <paramref name="filter"/>, or whether any entity exists |
| 98 | + /// when it is <see langword="null"/>. |
| 99 | + /// </summary> |
| 100 | + /// <param name="filter">Predicate to match, or <see langword="null"/> to match every entity.</param> |
| 101 | + /// <param name="cancellationToken">Token used to cancel the operation.</param> |
47 | 102 | Task<bool> AnyAsync( |
48 | 103 | Expression<Func<TEntity, bool>>? filter = default, |
49 | 104 | CancellationToken cancellationToken = default); |
50 | 105 |
|
| 106 | + /// <summary> |
| 107 | + /// Determines whether any entity matching <paramref name="preFilter"/> has a <typeparamref name="TResultDto"/> |
| 108 | + /// projection matching <paramref name="filter"/>. |
| 109 | + /// </summary> |
| 110 | + /// <typeparam name="TResultDto">Type each entity is projected onto.</typeparam> |
| 111 | + /// <param name="preFilter">Predicate applied to entities before projection, or <see langword="null"/> to match all.</param> |
| 112 | + /// <param name="filter">Predicate applied to projected results, or <see langword="null"/> to match all.</param> |
| 113 | + /// <param name="cancellationToken">Token used to cancel the operation.</param> |
51 | 114 | Task<bool> AnyAsync<TResultDto>( |
52 | 115 | Expression<Func<TEntity, bool>>? preFilter, |
53 | 116 | Expression<Func<TResultDto, bool>>? filter = default, |
54 | 117 | CancellationToken cancellationToken = default); |
55 | 118 | } |
56 | 119 |
|
57 | 120 | /// <summary> |
58 | | -/// Represents a repository with read-only operations. |
| 121 | +/// Read-only repository that adds identifier-based lookups for an entity keyed by |
| 122 | +/// <typeparamref name="TEntityId"/>. |
59 | 123 | /// </summary> |
| 124 | +/// <typeparam name="TEntity">Type of the queried entity.</typeparam> |
| 125 | +/// <typeparam name="TEntityId">Type of the entity identifier.</typeparam> |
60 | 126 | public interface IRORepository<TEntity, TEntityId> : IRORepository<TEntity> |
61 | 127 | where TEntity : DomainEntity<TEntityId> |
62 | 128 | where TEntityId : notnull |
63 | 129 | { |
| 130 | + /// <summary> |
| 131 | + /// Returns the entity identified by <paramref name="entityId"/>. |
| 132 | + /// </summary> |
| 133 | + /// <param name="entityId">Identifier of the entity to load.</param> |
| 134 | + /// <param name="includes">Related object graph to load alongside the entity, or <see langword="null"/> for none.</param> |
| 135 | + /// <param name="cancellationToken">Token used to cancel the operation.</param> |
| 136 | + /// <returns>The matching entity; never <see langword="null"/>.</returns> |
| 137 | + /// <exception cref="EntityNotFoundException">No entity with <paramref name="entityId"/> exists.</exception> |
| 138 | + /// <exception cref="EntityAccessDeniedException">The entity exists but the active read policy denies access to it.</exception> |
64 | 139 | Task<TEntity> GetByIdAsync( |
65 | 140 | TEntityId entityId, |
66 | 141 | Includes<TEntity>? includes, |
67 | 142 | CancellationToken cancellationToken); |
68 | 143 |
|
| 144 | + /// <summary> |
| 145 | + /// Returns the entity identified by <paramref name="entityId"/> projected onto <typeparamref name="TResultDto"/> |
| 146 | + /// using the registered mapping. |
| 147 | + /// </summary> |
| 148 | + /// <typeparam name="TResultDto">Type the entity is projected onto.</typeparam> |
| 149 | + /// <param name="entityId">Identifier of the entity to load.</param> |
| 150 | + /// <param name="cancellationToken">Token used to cancel the operation.</param> |
| 151 | + /// <returns>The projected result; never <see langword="null"/>.</returns> |
| 152 | + /// <exception cref="EntityNotFoundException">No entity with <paramref name="entityId"/> exists.</exception> |
| 153 | + /// <exception cref="EntityAccessDeniedException">The entity exists but the active read policy denies access to it.</exception> |
69 | 154 | Task<TResultDto> GetByIdAsync<TResultDto>( |
70 | 155 | TEntityId entityId, |
71 | 156 | CancellationToken cancellationToken); |
72 | 157 |
|
| 158 | + /// <summary> |
| 159 | + /// Returns the entity identified by <paramref name="entityId"/> projected onto <typeparamref name="TResultDto"/> |
| 160 | + /// via <paramref name="projection"/>. |
| 161 | + /// </summary> |
| 162 | + /// <typeparam name="TResultDto">Type the entity is projected onto.</typeparam> |
| 163 | + /// <param name="entityId">Identifier of the entity to load.</param> |
| 164 | + /// <param name="projection">Expression mapping the entity to a result. Translated to the query, not run in memory.</param> |
| 165 | + /// <param name="cancellationToken">Token used to cancel the operation.</param> |
| 166 | + /// <returns>The projected result; never <see langword="null"/>.</returns> |
| 167 | + /// <exception cref="EntityNotFoundException">No entity with <paramref name="entityId"/> exists.</exception> |
| 168 | + /// <exception cref="EntityAccessDeniedException">The entity exists but the active read policy denies access to it.</exception> |
73 | 169 | Task<TResultDto> GetByIdAsync<TResultDto>( |
74 | 170 | TEntityId entityId, |
75 | 171 | Expression<Func<TEntity, TResultDto>> projection, |
|
0 commit comments