Table of Contents

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

TKey

Primary key type.

TModel

Model type.

TDto

DTO type.

TFilter

Filter 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

service IService<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

id TKey

Primary key value.

cancellationToken CancellationToken

Token to cancel the request.

Returns

Task<IActionResult>

NoContent if 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

id TKey

Primary key value.

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<TDto>>

DTO, or NotFound if 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

id TKey

Primary key value.

dtoPatch JsonPatchDocument<TDto>

JSON patch of the DTO.

cancellationToken CancellationToken

Token to cancel the request.

Returns

Task<IActionResult>

NoContent if the model is updated.