Class MagicalizedController<TKey, TModel, TDto, TFilter>
- Namespace
- Magicalizer.Api.Controllers
- Assembly
- Magicalizer.dll
Magicalized controller of models with a primary key of one property.
public class MagicalizedController<TKey, TModel, TDto, TFilter> : MagicalizedControllerBase<TModel, TDto, TFilter> where TModel : class, IModel, new() where TDto : class, IDto<TModel>, new() where TFilter : class, IFilter, new()
Type Parameters
TKeyPrimary key type.
TModelModel type.
TDtoDTO type.
TFilterFilter type.
- Inheritance
-
ControllerBase<TModel, TDto>MagicalizedControllerBase<TModel, TDto, TFilter>MagicalizedController<TKey, TModel, TDto, TFilter>
- Inherited Members
Constructors
MagicalizedController(IService<TKey, TModel, TFilter>)
Creates a controller.
public MagicalizedController(IService<TKey, TModel, TFilter> service)
Parameters
serviceIService<TKey, TModel, TFilter>Service of the models.
Fields
service
Service of the models.
protected readonly IService<TKey, TModel, TFilter> service
Field Value
- IService<TKey, TModel, TFilter>
Methods
DeleteAsync(TKey, CancellationToken)
Deletes the model by the primary key.
[HttpDelete("{id}")]
public virtual Task<IActionResult> DeleteAsync(TKey id, CancellationToken cancellationToken = default)
Parameters
idTKeyPrimary key value.
cancellationTokenCancellationTokenToken to cancel the request.
Returns
- Task<IActionResult>
NoContentif the model is deleted.
GetAsync(TKey, IEnumerable<IInclusion<TModel>>?, CancellationToken)
Gets the DTO by the primary key.
[HttpGet("{id}")]
public virtual Task<ActionResult<TDto>> GetAsync(TKey id, IEnumerable<IInclusion<TModel>>? include = null, CancellationToken cancellationToken = default)
Parameters
idTKeyPrimary key value.
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<TDto>>
DTO, or
NotFoundif it doesn't exist.
PatchAsync(TKey, JsonPatchDocument<TDto>, CancellationToken)
Partially updates the model by the primary key with a JSON patch.
[HttpPatch("{id}")]
public virtual Task<IActionResult> PatchAsync(TKey id, JsonPatchDocument<TDto> dtoPatch, CancellationToken cancellationToken = default)
Parameters
idTKeyPrimary key value.
dtoPatchJsonPatchDocument<TDto>JSON patch of the DTO.
cancellationTokenCancellationTokenToken to cancel the request.
Returns
- Task<IActionResult>
NoContentif the model is updated.