Table of Contents

Class IndustriesController

Namespace
KadicErp.WebApi.Controllers.ReferenceData
Assembly
KadicErp.WebApi.dll

Industries controller - Uses Generic CRUD Controller Pattern Inherits from GenericCrudControllerBase to reuse common CRUD endpoints Only defines authorization policies and activate/deactivate endpoints

[Route("api/[controller]")]
[Authorize]
public class IndustriesController : GenericCrudControllerBase<IndustryDto, CreateIndustryCommand, UpdateIndustryCommand, GetIndustryByIdQuery, GetAllIndustriesQuery>
Inheritance
object
ControllerBase
GenericCrudControllerBase<IndustryDto, CreateIndustryCommand, UpdateIndustryCommand, GetIndustryByIdQuery, GetAllIndustriesQuery>
IndustriesController
Inherited Members
GenericCrudControllerBase<IndustryDto, CreateIndustryCommand, UpdateIndustryCommand, GetIndustryByIdQuery, GetAllIndustriesQuery>.Sender
GenericCrudControllerBase<IndustryDto, CreateIndustryCommand, UpdateIndustryCommand, GetIndustryByIdQuery, GetAllIndustriesQuery>.CreateGetByIdQuery(Guid)
GenericCrudControllerBase<IndustryDto, CreateIndustryCommand, UpdateIndustryCommand, GetIndustryByIdQuery, GetAllIndustriesQuery>.CreateGetAllQuery(PaginatorRequestDto, bool?)
GenericCrudControllerBase<IndustryDto, CreateIndustryCommand, UpdateIndustryCommand, GetIndustryByIdQuery, GetAllIndustriesQuery>.SetCommandId(UpdateIndustryCommand, Guid)
GenericCrudControllerBase<IndustryDto, CreateIndustryCommand, UpdateIndustryCommand, GetIndustryByIdQuery, GetAllIndustriesQuery>.HandleCommandResult(Result)
GenericCrudControllerBase<IndustryDto, CreateIndustryCommand, UpdateIndustryCommand, GetIndustryByIdQuery, GetAllIndustriesQuery>.HandleCommandResult<T>(Result<T>, string)
GenericCrudControllerBase<IndustryDto, CreateIndustryCommand, UpdateIndustryCommand, GetIndustryByIdQuery, GetAllIndustriesQuery>.Create(CreateIndustryCommand)
GenericCrudControllerBase<IndustryDto, CreateIndustryCommand, UpdateIndustryCommand, GetIndustryByIdQuery, GetAllIndustriesQuery>.Update(Guid, UpdateIndustryCommand)
GenericCrudControllerBase<IndustryDto, CreateIndustryCommand, UpdateIndustryCommand, GetIndustryByIdQuery, GetAllIndustriesQuery>.GetById(Guid)
GenericCrudControllerBase<IndustryDto, CreateIndustryCommand, UpdateIndustryCommand, GetIndustryByIdQuery, GetAllIndustriesQuery>.GetAll(PaginatorRequestDto, bool?)

Constructors

IndustriesController(ISender, IStringLocalizer<GeneralMessages>)

Industries controller - Uses Generic CRUD Controller Pattern Inherits from GenericCrudControllerBase to reuse common CRUD endpoints Only defines authorization policies and activate/deactivate endpoints

public IndustriesController(ISender sender, IStringLocalizer<GeneralMessages> localizer)

Parameters

sender ISender
localizer IStringLocalizer<GeneralMessages>

Methods

Activate(Guid)

[HttpPatch("{id}/activate")]
[Authorize(Policy = "REFERENCE_DATA_INDUSTRIES_ACTIVATE")]
public Task<IActionResult> Activate(Guid id)

Parameters

id Guid

Returns

Task<IActionResult>

Create(CreateIndustryCommand)

POST endpoint for creating a new entity. Returns 201 Created with Location header on success.

IMPORTANT: Override in derived class to add [HttpPost] and [Authorize(Policy = ...)]

[HttpPost]
[Authorize(Policy = "REFERENCE_DATA_INDUSTRIES_CREATE")]
[ProducesResponseType(typeof(Result<Guid>), 201)]
[ProducesResponseType(typeof(Result), 400)]
[ProducesResponseType(typeof(Result), 409)]
public override Task<IActionResult> Create(CreateIndustryCommand command)

Parameters

command CreateIndustryCommand

Returns

Task<IActionResult>

Deactivate(Guid)

[HttpPatch("{id}/deactivate")]
[Authorize(Policy = "REFERENCE_DATA_INDUSTRIES_DEACTIVATE")]
public Task<IActionResult> Deactivate(Guid id)

Parameters

id Guid

Returns

Task<IActionResult>

GetAll(PaginatorRequestDto, bool?)

GET endpoint for retrieving paginated list of entities. Supports optional isActive filter.

IMPORTANT: Override in derived class to add [HttpGet] and [Authorize(Policy = ...)] Override CreateGetAllQuery if you need additional filters. Note: ProducesResponseType attributes cannot be added here due to generic type parameters. Add them in derived class if needed for Swagger documentation.

[HttpGet]
[Authorize(Policy = "REFERENCE_DATA_INDUSTRIES_VIEW")]
[ProducesResponseType(typeof(PaginatorResponseDto<IndustryDto>), 200)]
[ProducesResponseType(typeof(Error), 400)]
public override Task<IActionResult> GetAll(PaginatorRequestDto paginator, bool? isActive = null)

Parameters

paginator PaginatorRequestDto
isActive bool?

Returns

Task<IActionResult>

GetById(Guid)

GET endpoint for retrieving a single entity by ID. Returns 404 Not Found if entity doesn't exist.

IMPORTANT: Override in derived class to add [HttpGet("{id}")] and [Authorize(Policy = ...)] Note: ProducesResponseType attributes cannot be added here due to generic type parameters. Add them in derived class if needed for Swagger documentation.

[HttpGet("{id}")]
[Authorize(Policy = "REFERENCE_DATA_INDUSTRIES_VIEW")]
[ProducesResponseType(typeof(IndustryDto), 200)]
[ProducesResponseType(typeof(Error), 404)]
public override Task<IActionResult> GetById(Guid id)

Parameters

id Guid

Returns

Task<IActionResult>

SetCommandId(UpdateIndustryCommand, Guid)

Updates the command with the ID from route. This method must be overridden in derived classes to properly set the Id.

For record types with 'with' expression, use:

protected override UpdateXCommand SetCommandId(UpdateXCommand command, Guid id)
    => command with { Id = id };
protected override UpdateIndustryCommand SetCommandId(UpdateIndustryCommand command, Guid id)

Parameters

command UpdateIndustryCommand
id Guid

Returns

UpdateIndustryCommand

Update(Guid, UpdateIndustryCommand)

PUT endpoint for updating an existing entity. Returns 200 OK on success.

IMPORTANT: Override in derived class to add [HttpPut("{id}")] and [Authorize(Policy = ...)]

[HttpPut("{id}")]
[Authorize(Policy = "REFERENCE_DATA_INDUSTRIES_UPDATE")]
[ProducesResponseType(typeof(Result), 200)]
[ProducesResponseType(typeof(Result), 400)]
[ProducesResponseType(typeof(Result), 404)]
[ProducesResponseType(typeof(Result), 409)]
public override Task<IActionResult> Update(Guid id, UpdateIndustryCommand command)

Parameters

id Guid
command UpdateIndustryCommand

Returns

Task<IActionResult>