Table of Contents

Class MagicalizedControllerBase<TModel, TDto, TFilter>

Namespace
Magicalizer.Api.Controllers
Assembly
Magicalizer.dll

Base of the magicalized controllers. Contains the actions that don't depend on the primary key (getting a list, creating and updating) and shared logic of the ones that do. Actions by the primary key are declared in the derived controllers, which differ only in the number of primary key properties. When the app starts, the conventions of Magicalizer set the route, the supported HTTP methods and the settings of the API description (by MagicalizedAttribute of the DTO), the authorization (by AuthenticatedOnlyAttribute and AuthorizedOnlyAttribute) and the maximum limit (MaxLimit) of these controllers and of the custom ones derived from them.

[Route("[magicalized]")]
public abstract class MagicalizedControllerBase<TModel, TDto, TFilter> : ControllerBase<TModel, TDto> where TModel : class, IModel, new() where TDto : class, IDto<TModel>, new() where TFilter : class, IFilter, new()

Type Parameters

TModel

Model type.

TDto

DTO type.

TFilter

Filter type.

Inheritance
ControllerBase<TModel, TDto>
MagicalizedControllerBase<TModel, TDto, TFilter>
Derived
Inherited Members

Methods

GetAsync(TFilter?, IEnumerable<ISorting<TModel>>?, int?, int?, IEnumerable<IInclusion<TModel>>?, CancellationToken)

Gets the DTOs that match the filter, sorted and paged, with related models included.

[HttpGet]
public virtual Task<ActionResult<IEnumerable<TDto>>> GetAsync(TFilter? filter = null, IEnumerable<ISorting<TModel>>? sort = null, int? offset = null, int? limit = null, IEnumerable<IInclusion<TModel>>? include = null, CancellationToken cancellationToken = default)

Parameters

filter TFilter

Filter to apply.

sort IEnumerable<ISorting<TModel>>

Sortings, passed as comma-separated property paths, prefixed with "-" for descending order (e.g. "name,-created").

offset int?

Number of models to skip.

limit int?

Maximum number of models to return, up to MaxLimit (it's also the default one).

include IEnumerable<IInclusion<TModel>>

Inclusions, passed as comma-separated property paths of related models (e.g. "category,photos"), each of up to MaxInclusionDepth properties.

cancellationToken CancellationToken

Token to cancel the request.

Returns

Task<ActionResult<IEnumerable<TDto>>>

DTOs that match the filter. The number of all of them is returned in the Paging-Total-Count header if CountTotalByDefault is set or the request asks for it with the Prefer: count=exact header (Prefer: count=none skips it).

PostAsync(TDto, CancellationToken)

Creates a model from the DTO.

[HttpPost]
public virtual Task<ActionResult<TDto>> PostAsync(TDto dto, CancellationToken cancellationToken = default)

Parameters

dto TDto

DTO of the model to create.

cancellationToken CancellationToken

Token to cancel the request.

Returns

Task<ActionResult<TDto>>

Created DTO.

PutAsync(TDto, CancellationToken)

Updates the model from the DTO.

[HttpPut]
public virtual Task<IActionResult> PutAsync(TDto dto, CancellationToken cancellationToken = default)

Parameters

dto TDto

DTO of the model to update.

cancellationToken CancellationToken

Token to cancel the request.

Returns

Task<IActionResult>

NoContent if the model is updated.