| [877c13c] | 1 | using ChapterX.Application.Status.Commands;
|
|---|
| 2 | using ChapterX.Application.Status.Queries;
|
|---|
| 3 | using MediatR;
|
|---|
| 4 | using Microsoft.AspNetCore.Authorization;
|
|---|
| 5 | using Microsoft.AspNetCore.Mvc;
|
|---|
| 6 | using Microsoft.Extensions.Logging;
|
|---|
| 7 |
|
|---|
| 8 | namespace ChapterX.API.Controllers
|
|---|
| 9 | {
|
|---|
| 10 | [Route("api/[controller]")]
|
|---|
| 11 | [ApiController]
|
|---|
| 12 | public class StatusController : ControllerBase
|
|---|
| 13 | {
|
|---|
| 14 | private readonly IMediator _mediator;
|
|---|
| 15 | private readonly ILogger<StatusController> _logger;
|
|---|
| 16 |
|
|---|
| 17 | public StatusController(IMediator mediator, ILogger<StatusController> logger)
|
|---|
| 18 | {
|
|---|
| 19 | _mediator = mediator;
|
|---|
| 20 | _logger = logger;
|
|---|
| 21 | }
|
|---|
| 22 |
|
|---|
| 23 | // GET: api/Status
|
|---|
| 24 | [HttpGet]
|
|---|
| 25 | [AllowAnonymous]
|
|---|
| 26 | public async Task<ActionResult> GetAll()
|
|---|
| 27 | {
|
|---|
| 28 | _logger.LogInformation("Fetching all status values");
|
|---|
| 29 | var response = await _mediator.Send(new GetAllRequest());
|
|---|
| 30 | return Ok(response);
|
|---|
| 31 | }
|
|---|
| 32 |
|
|---|
| 33 | // GET: api/Status/5
|
|---|
| 34 | [HttpGet("{id:int}")]
|
|---|
| 35 | [AllowAnonymous]
|
|---|
| 36 | public async Task<ActionResult> GetById([FromRoute] int id)
|
|---|
| 37 | {
|
|---|
| 38 | _logger.LogInformation("Fetching status with ID: {StatusId}", id);
|
|---|
| 39 | var response = await _mediator.Send(new GetRequest(id));
|
|---|
| 40 | return Ok(response);
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 | // POST: api/Status
|
|---|
| 44 | // Note: Status is an enum in the domain; runtime changes may be limited.
|
|---|
| 45 | [HttpPost]
|
|---|
| 46 | [Authorize]
|
|---|
| 47 | public async Task<ActionResult> Add([FromBody] AddRequest request)
|
|---|
| 48 | {
|
|---|
| 49 | _logger.LogInformation("Adding a new status value");
|
|---|
| 50 | var response = await _mediator.Send(request);
|
|---|
| 51 | return Ok(response);
|
|---|
| 52 | }
|
|---|
| 53 |
|
|---|
| 54 | // PUT: api/Status/5
|
|---|
| 55 | [HttpPut("{id:int}")]
|
|---|
| 56 | [Authorize]
|
|---|
| 57 | public async Task<ActionResult> Update([FromRoute] int id)
|
|---|
| 58 | {
|
|---|
| 59 | _logger.LogInformation("Updating status with ID: {StatusId}", id);
|
|---|
| 60 | var response = await _mediator.Send(new UpdateRequest(id));
|
|---|
| 61 | return Ok(response);
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | // DELETE: api/Status
|
|---|
| 65 | [HttpDelete]
|
|---|
| 66 | [Authorize]
|
|---|
| 67 | public async Task<ActionResult> Delete([FromBody] DeleteRequest request)
|
|---|
| 68 | {
|
|---|
| 69 | _logger.LogInformation("Deleting a status value");
|
|---|
| 70 | var response = await _mediator.Send(request);
|
|---|
| 71 | return Ok(response);
|
|---|
| 72 | }
|
|---|
| 73 | }
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|