Added a new `Delete` method to the `OutResController` class to delete all output results for a fake/test profile. The method is accessible via the `DELETE /fake` route and supports cancellation via a `CancellationToken`. Included XML documentation for the method, describing its purpose, parameters, and return type. Added `[ProducesResponseType]` attributes to specify possible HTTP response codes: `204 No Content` for success and `400 Bad Request` for invalid requests. The method uses `IMediator` to send a `DeleteOutResCommand` with a `ProfileId` obtained from the `IConfiguration` instance.
108 lines
4.1 KiB
C#
108 lines
4.1 KiB
C#
using MediatR;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using ReC.API.Extensions;
|
|
using ReC.Application.OutResults.Commands;
|
|
using ReC.Application.OutResults.Queries;
|
|
|
|
namespace ReC.API.Controllers;
|
|
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public class OutResController(IMediator mediator, IConfiguration config) : ControllerBase
|
|
{
|
|
/// <summary>
|
|
/// Gets output results based on the provided query parameters.
|
|
/// </summary>
|
|
/// <param name="query">The query to filter output results.</param>
|
|
/// <param name="cancel">A token to cancel the operation.</param>
|
|
/// <returns>A list of output results matching the query.</returns>
|
|
[HttpGet]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
public async Task<IActionResult> Get([FromQuery] ReadOutResQuery query, CancellationToken cancel) => Ok(await mediator.Send(query, cancel));
|
|
|
|
/// <summary>
|
|
/// Gets output results for a fake/test profile.
|
|
/// </summary>
|
|
/// <param name="cancel">A token to cancel the operation.</param>
|
|
/// <returns>A list of output results for the fake profile.</returns>
|
|
[HttpGet("fake")]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
public async Task<IActionResult> Get(CancellationToken cancel) => Ok(await mediator.Send(new ReadOutResQuery()
|
|
{
|
|
ProfileId = config.GetFakeProfileId()
|
|
}, cancel));
|
|
|
|
/// <summary>
|
|
/// Gets a specific output result for a fake/test profile and action.
|
|
/// </summary>
|
|
/// <param name="actionId">The ID of the action to retrieve the result for.</param>
|
|
/// <param name="cancel">A token to cancel the operation.</param>
|
|
/// <param name="resultType">Specifies which part of the result to return (Full, Header, or Body).</param>
|
|
/// <returns>The requested output result or a part of it (header/body).</returns>
|
|
[HttpGet("fake/{actionId}")]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
public async Task<IActionResult> Get([FromRoute] long actionId, CancellationToken cancel, ResultType resultType = ResultType.Full)
|
|
{
|
|
var res = (await mediator.Send(new ReadOutResQuery()
|
|
{
|
|
ProfileId = config.GetFakeProfileId(),
|
|
ActionId = actionId
|
|
}, cancel)).First();
|
|
|
|
return resultType switch
|
|
{
|
|
ResultType.Body => res.Body is null ? Ok(new object { }) : Ok(res.Body.JsonToDynamic()),
|
|
ResultType.Header => res.Header is null ? Ok(new object { }) : Ok(res.Header.JsonToDynamic()),
|
|
_ => Ok(res),
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// Deletes output results based on the provided criteria.
|
|
/// </summary>
|
|
/// <param name="command">The command containing the deletion criteria, such as ActionId or ProfileId.</param>
|
|
/// <param name="cancel">A token to cancel the operation.</param>
|
|
/// <returns>An empty response indicating success.</returns>
|
|
[HttpDelete]
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
|
public async Task<IActionResult> Delete([FromQuery] DeleteOutResCommand command, CancellationToken cancel)
|
|
{
|
|
await mediator.Send(command, cancel);
|
|
return NoContent();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Deletes all output results for a fake/test profile.
|
|
/// </summary>
|
|
/// <param name="cancel">A token to cancel the operation.</param>
|
|
/// <returns>An empty response indicating success.</returns>
|
|
[HttpDelete("fake")]
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
|
public async Task<IActionResult> Delete(CancellationToken cancel)
|
|
{
|
|
await mediator.Send(new DeleteOutResCommand() { ProfileId = config.GetFakeProfileId() }, cancel);
|
|
return NoContent();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Defines the type of result to be returned from an output result query.
|
|
/// </summary>
|
|
public enum ResultType
|
|
{
|
|
/// <summary>
|
|
/// Return the full result object.
|
|
/// </summary>
|
|
Full,
|
|
/// <summary>
|
|
/// Return only the header part of the result.
|
|
/// </summary>
|
|
Header,
|
|
/// <summary>
|
|
/// Return only the body part of the result.
|
|
/// </summary>
|
|
Body
|
|
}
|