Table of Contents

Class EntityQueryEndpointBase<TKey, TListModel, TReadModel>

Namespace
Arbiter.CommandQuery.Endpoints
Assembly
Arbiter.CommandQuery.Endpoints.dll

Provides a base class for defining RESTful query endpoints for an entity, including single, paged, and list queries.

public abstract class EntityQueryEndpointBase<TKey, TListModel, TReadModel> : IEndpointRoute

Type Parameters

TKey

The type of the entity key.

TListModel

The type of the list model returned by queries.

TReadModel

The type of the read model returned by single-entity queries.

Inheritance
EntityQueryEndpointBase<TKey, TListModel, TReadModel>
Implements
Derived
Inherited Members

Remarks

This class is intended for use in Blazor and WebAssembly applications to standardize entity query API patterns. It supports mapping endpoints for retrieving entities by ID, paged results, and filtered lists.

Constructors

EntityQueryEndpointBase(ILoggerFactory, string, string?)

Initializes a new instance of the EntityQueryEndpointBase<TKey, TListModel, TReadModel> class.

protected EntityQueryEndpointBase(ILoggerFactory loggerFactory, string entityName, string? routePrefix = null)

Parameters

loggerFactory ILoggerFactory

The logger factory to create an ILogger for this endpoint.

entityName string

The name of the entity for this endpoint.

routePrefix string

The route prefix for this endpoint. If not set, entityName is used.

Properties

EntityName

Gets the name of the entity for this endpoint.

public string EntityName { get; }

Property Value

string

Logger

Gets the logger for this endpoint.

protected ILogger Logger { get; }

Property Value

ILogger

RoutePrefix

Gets the route prefix for this endpoint.

public string RoutePrefix { get; }

Property Value

string

Methods

AddRoutes(IEndpointRouteBuilder)

Adds routes to the specified IEndpointRouteBuilder instance.

public void AddRoutes(IEndpointRouteBuilder endpoints)

Parameters

endpoints IEndpointRouteBuilder

The IEndpointRouteBuilder to add the route to.

GetPagedQuery(IMediator, string?, string?, int?, int?, ClaimsPrincipal?, CancellationToken)

Retrieves a paged result of entities using query string parameters.

protected virtual Task<Results<Ok<EntityPagedResult<TListModel>>, ProblemHttpResult>> GetPagedQuery(IMediator mediator, string? q = null, string? sort = null, int? page = 1, int? size = 20, ClaimsPrincipal? user = null, CancellationToken cancellationToken = default)

Parameters

mediator IMediator

The IMediator to send the request to.

q string

The raw query expression.

sort string

The sort expression.

page int?

The page number for the query. The default is 1.

size int?

The size of the page for the query. The default is 20.

user ClaimsPrincipal

The current security claims principal.

cancellationToken CancellationToken

The request cancellation token.

Returns

Task<Results<Ok<EntityPagedResult<TListModel>>, ProblemHttpResult>>

An awaitable task returning either EntityPagedResult<TReadModel> with the paged result or ProblemHttpResult on error.

GetQuery(IMediator, TKey, ClaimsPrincipal?, CancellationToken)

Retrieves a single entity by its identifier using the mediator service.

protected virtual Task<Results<Ok<TReadModel>, ProblemHttpResult>> GetQuery(IMediator mediator, TKey id, ClaimsPrincipal? user = null, CancellationToken cancellationToken = default)

Parameters

mediator IMediator

The IMediator to send the request to.

id TKey

The identifier of the entity to retrieve.

user ClaimsPrincipal

The current security claims principal.

cancellationToken CancellationToken

The request cancellation token.

Returns

Task<Results<Ok<TReadModel>, ProblemHttpResult>>

An awaitable task returning either Ok<TValue> with the entity or ProblemHttpResult on error.

GetSelectQuery(IMediator, string?, string?, ClaimsPrincipal?, CancellationToken)

Retrieves a list of entities using query string parameters.

protected virtual Task<Results<Ok<IReadOnlyCollection<TListModel>>, ProblemHttpResult>> GetSelectQuery(IMediator mediator, string? q = null, string? sort = null, ClaimsPrincipal? user = null, CancellationToken cancellationToken = default)

Parameters

mediator IMediator

The IMediator to send the request to.

q string

The raw query expression.

sort string

The sort expression.

user ClaimsPrincipal

The current security claims principal.

cancellationToken CancellationToken

The request cancellation token.

Returns

Task<Results<Ok<IReadOnlyCollection<TListModel>>, ProblemHttpResult>>

An awaitable task returning either IReadOnlyCollection<T> with the result list or ProblemHttpResult on error.

MapGroup(RouteGroupBuilder)

Maps the group of query endpoints for this entity, including single, paged, and list queries.

protected virtual void MapGroup(RouteGroupBuilder group)

Parameters

group RouteGroupBuilder

The RouteGroupBuilder used to define the endpoint group.

Remarks

This method adds endpoints for:

  • GET {id} - Retrieve an entity by ID
  • GET page - Retrieve a paged result of entities
  • POST page - Retrieve a paged result of entities using a query object
  • GET (root) - Retrieve a list of entities by query
  • POST query - Retrieve a list of entities using a select object

PostPagedQuery(IMediator, EntityQuery, ClaimsPrincipal?, CancellationToken)

Retrieves a paged result of entities using a posted EntityQuery object.

protected virtual Task<Results<Ok<EntityPagedResult<TListModel>>, ProblemHttpResult>> PostPagedQuery(IMediator mediator, EntityQuery entityQuery, ClaimsPrincipal? user = null, CancellationToken cancellationToken = default)

Parameters

mediator IMediator

The IMediator to send the request to.

entityQuery EntityQuery

The entity query specifying filter, sort, and pagination.

user ClaimsPrincipal

The current security claims principal.

cancellationToken CancellationToken

The request cancellation token.

Returns

Task<Results<Ok<EntityPagedResult<TListModel>>, ProblemHttpResult>>

An awaitable task returning either EntityPagedResult<TReadModel> with the paged result or ProblemHttpResult on error.

PostSelectQuery(IMediator, EntitySelect, ClaimsPrincipal?, CancellationToken)

Retrieves a list of entities using a posted EntitySelect object.

protected virtual Task<Results<Ok<IReadOnlyCollection<TListModel>>, ProblemHttpResult>> PostSelectQuery(IMediator mediator, EntitySelect entitySelect, ClaimsPrincipal? user = null, CancellationToken cancellationToken = default)

Parameters

mediator IMediator

The IMediator to send the request to.

entitySelect EntitySelect

The entity select specifying filter and sort criteria.

user ClaimsPrincipal

The current security claims principal.

cancellationToken CancellationToken

The request cancellation token.

Returns

Task<Results<Ok<IReadOnlyCollection<TListModel>>, ProblemHttpResult>>

An awaitable task returning either IReadOnlyCollection<T> with the result list or ProblemHttpResult on error.