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
TModelModel type.
TDtoDTO type.
TFilterFilter 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
filterTFilterFilter to apply.
sortIEnumerable<ISorting<TModel>>Sortings, passed as comma-separated property paths, prefixed with "-" for descending order (e.g. "name,-created").
offsetint?Number of models to skip.
limitint?Maximum number of models to return, up to MaxLimit (it's also the default one).
includeIEnumerable<IInclusion<TModel>>Inclusions, passed as comma-separated property paths of related models (e.g. "category,photos"), each of up to MaxInclusionDepth properties.
cancellationTokenCancellationTokenToken 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-Countheader if CountTotalByDefault is set or the request asks for it with thePrefer: count=exactheader (Prefer: count=noneskips it).
PostAsync(TDto, CancellationToken)
Creates a model from the DTO.
[HttpPost]
public virtual Task<ActionResult<TDto>> PostAsync(TDto dto, CancellationToken cancellationToken = default)
Parameters
dtoTDtoDTO of the model to create.
cancellationTokenCancellationTokenToken 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
dtoTDtoDTO of the model to update.
cancellationTokenCancellationTokenToken to cancel the request.
Returns
- Task<IActionResult>
NoContentif the model is updated.