Table of Contents

Class QueryOnlyApiController<TListQuery, TListRequestDto, TListQueryResponse, TViewQuery, TViewQueryResponse, TQueryOnlyControllerLogMessageActions>

Namespace
Whipstaff.AspNetCore
Assembly
Whipstaff.AspNetCore.dll

A generic API controller supporting List and View operations. Pre-defines CQRS activities along with Authorization and logging.

public abstract class QueryOnlyApiController<TListQuery, TListRequestDto, TListQueryResponse, TViewQuery, TViewQueryResponse, TQueryOnlyControllerLogMessageActions> : ControllerBase where TListQuery : IAuditableRequest<TListRequestDto, TListQueryResponse> where TListRequestDto : class, new() where TListQueryResponse : class where TViewQuery : IAuditableRequest<long, TViewQueryResponse?> where TViewQueryResponse : class where TQueryOnlyControllerLogMessageActions : IQueryOnlyControllerLogMessageActions

Type Parameters

TListQuery

The type for the List Query.

TListRequestDto

The type for the Request DTO for the List Operation.

TListQueryResponse

The type for the Response DTO for the List Operation.

TViewQuery

The type for the View Query.

TViewQueryResponse

The type for the Response DTO for the View Operation.

TQueryOnlyControllerLogMessageActions

The type for the log message actions mapping class.

Inheritance
QueryOnlyApiController<TListQuery, TListRequestDto, TListQueryResponse, TViewQuery, TViewQueryResponse, TQueryOnlyControllerLogMessageActions>
Derived
Inherited Members
Extension Methods

Constructors

QueryOnlyApiController(IAuthorizationService, ILogger<QueryOnlyApiController<TListQuery, TListRequestDto, TListQueryResponse, TViewQuery, TViewQueryResponse, TQueryOnlyControllerLogMessageActions>>, IMediator, IAuditableQueryFactory<TListQuery, TListRequestDto, TListQueryResponse, TViewQuery, TViewQueryResponse>, TQueryOnlyControllerLogMessageActions)

protected QueryOnlyApiController(IAuthorizationService authorizationService, ILogger<QueryOnlyApiController<TListQuery, TListRequestDto, TListQueryResponse, TViewQuery, TViewQueryResponse, TQueryOnlyControllerLogMessageActions>> logger, IMediator mediator, IAuditableQueryFactory<TListQuery, TListRequestDto, TListQueryResponse, TViewQuery, TViewQueryResponse> queryFactory, TQueryOnlyControllerLogMessageActions logMessageActionMappings)

Parameters

authorizationService IAuthorizationService

The authorization service for validating access.

logger ILogger<QueryOnlyApiController<TListQuery, TListRequestDto, TListQueryResponse, TViewQuery, TViewQueryResponse, TQueryOnlyControllerLogMessageActions>>

The logger object.

mediator IMediator

The mediatr object to publish CQRS messages to.

queryFactory IAuditableQueryFactory<TListQuery, TListRequestDto, TListQueryResponse, TViewQuery, TViewQueryResponse>

The factory for generating Query messages.

logMessageActionMappings TQueryOnlyControllerLogMessageActions

Log Message Action mappings.

Properties

AuthorizationService

Gets the authorization service instance used to authorize requests.

protected IAuthorizationService AuthorizationService { get; }

Property Value

IAuthorizationService

LogMessageActionMappings

Gets the log message action mappings.

protected TQueryOnlyControllerLogMessageActions LogMessageActionMappings { get; }

Property Value

TQueryOnlyControllerLogMessageActions

Logger

Gets the logging framework instance.

protected ILogger Logger { get; }

Property Value

ILogger

Mediator

Gets the Mediator instance used for issuing CQRS messages.

protected IMediator Mediator { get; }

Property Value

IMediator

QueryFactory

Gets the query factory for creating queries to push through the mediator.

protected IAuditableQueryFactory<TListQuery, TListRequestDto, TListQueryResponse, TViewQuery, TViewQueryResponse> QueryFactory { get; }

Property Value

IAuditableQueryFactory<TListQuery, TListRequestDto, TListQueryResponse, TViewQuery, TViewQueryResponse>

Methods

GetListActionResultAsync(TListQueryResponse)

Gets the Action Result for the List operation.

protected abstract Task<ActionResult<TListQueryResponse>> GetListActionResultAsync(TListQueryResponse listResponse)

Parameters

listResponse TListQueryResponse

The Response DTO from the CQRS operation.

Returns

Task<ActionResult<TListQueryResponse>>

A Task<TResult> representing the result of the asynchronous operation.

GetListPolicyAsync()

Gets the authorization policy for the List operation.

protected abstract Task<string> GetListPolicyAsync()

Returns

Task<string>

A Task<TResult> representing the result of the asynchronous operation.

GetListQueryAsync(TListRequestDto, ClaimsPrincipal, CancellationToken)

Gets the CQRS List Query.

protected abstract Task<TListQuery> GetListQueryAsync(TListRequestDto listRequestDto, ClaimsPrincipal claimsPrincipal, CancellationToken cancellationToken)

Parameters

listRequestDto TListRequestDto

The List Request DTO.

claimsPrincipal ClaimsPrincipal

The claims principal for the user making the list request.

cancellationToken CancellationToken

The cancellation token for the request.

Returns

Task<TListQuery>

The list query.

GetViewActionResultAsync(TViewQueryResponse)

Gets the Action Result for the View operation.

protected abstract Task<ActionResult<TViewQueryResponse>> GetViewActionResultAsync(TViewQueryResponse viewResponse)

Parameters

viewResponse TViewQueryResponse

The Response DTO from the CQRS operation.

Returns

Task<ActionResult<TViewQueryResponse>>

A Task<TResult> representing the result of the asynchronous operation.

GetViewPolicyAsync()

Gets the authorization policy for the View operation.

protected abstract Task<string> GetViewPolicyAsync()

Returns

Task<string>

A Task<TResult> representing the result of the asynchronous operation.

GetViewQueryAsync(long, ClaimsPrincipal, CancellationToken)

Gets CQRS the View Query for the request.

protected abstract Task<TViewQuery> GetViewQueryAsync(long id, ClaimsPrincipal claimsPrincipal, CancellationToken cancellationToken)

Parameters

id long

Unique id of the item to view.

claimsPrincipal ClaimsPrincipal

The claims principal of the user requesting the view.

cancellationToken CancellationToken

Cancellation token for the request.

Returns

Task<TViewQuery>

The view query.

ListAsync(CancellationToken)

Entry point for HTTP GET operations to list items.

[HttpGet]
public Task<ActionResult<TListQueryResponse>> ListAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

Cancellation token for the operations.

Returns

Task<ActionResult<TListQueryResponse>>

A Task<TResult> representing the result of the asynchronous operation.

Remarks

Directs requests to List or View operations depending on whether an id is passed.

ViewAsync(long, CancellationToken)

Entry point for HTTP GET operation to view items.

[HttpGet("{id:long}")]
public Task<ActionResult<TViewQueryResponse>> ViewAsync(long id, CancellationToken cancellationToken)

Parameters

id long

unique id of the entity to view.

cancellationToken CancellationToken

Cancellation token for the operations.

Returns

Task<ActionResult<TViewQueryResponse>>

A Task<TResult> representing the result of the asynchronous operation.

Remarks

Directs requests to List or View operations depending on whether an id is passed.