using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Tnsu.ApprovalRoute.Api.Common; using Tnsu.ApprovalRoute.Application.TemplateRouteSteps; namespace Tnsu.ApprovalRoute.Api.Controllers; [ApiController] [Authorize] [Route("api/template-routes/{routeId:int}/steps")] [Produces("application/json")] public sealed class TemplateRouteStepsController(TemplateRouteStepService service) : ControllerBase { [HttpGet] [ProducesResponseType(typeof(ApiResponse>), StatusCodes.Status200OK)] public async Task List(int routeId, CancellationToken ct) => (await service.ListAsync(routeId, ct)).ToActionResult(); [HttpGet("{id:int}")] [ProducesResponseType(typeof(ApiResponse), StatusCodes.Status200OK)] [ProducesResponseType(typeof(ApiError), StatusCodes.Status404NotFound)] public async Task Get(int routeId, int id, CancellationToken ct) => (await service.GetAsync(routeId, id, ct)).ToActionResult(); [HttpPost] [ProducesResponseType(typeof(ApiResponse), StatusCodes.Status200OK)] [ProducesResponseType(typeof(ApiError), StatusCodes.Status400BadRequest)] [ProducesResponseType(typeof(ApiError), StatusCodes.Status404NotFound)] public async Task Create(int routeId, CreateTemplateRouteStepRequest body, CancellationToken ct) => (await service.CreateAsync(routeId, body, ct)).ToActionResult(); [HttpPut("{id:int}")] [ProducesResponseType(typeof(ApiResponse), StatusCodes.Status200OK)] [ProducesResponseType(typeof(ApiError), StatusCodes.Status400BadRequest)] [ProducesResponseType(typeof(ApiError), StatusCodes.Status404NotFound)] public async Task Update(int routeId, int id, UpdateTemplateRouteStepRequest body, CancellationToken ct) => (await service.UpdateAsync(routeId, id, body, ct)).ToActionResult(); [HttpPatch("{id:int}")] [ProducesResponseType(typeof(ApiResponse), StatusCodes.Status200OK)] [ProducesResponseType(typeof(ApiError), StatusCodes.Status400BadRequest)] [ProducesResponseType(typeof(ApiError), StatusCodes.Status404NotFound)] [ProducesResponseType(typeof(ApiError), StatusCodes.Status409Conflict)] public async Task Patch(int routeId, int id, PatchTemplateRouteStepRequest body, CancellationToken ct) => (await service.PatchAsync(routeId, id, body, ct)).ToActionResult(); [HttpDelete("{id:int}")] [ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(typeof(ApiError), StatusCodes.Status404NotFound)] public async Task Delete(int routeId, int id, CancellationToken ct) => (await service.DeleteAsync(routeId, id, ct)).ToActionResult(); }