Actions use enum

This commit is contained in:
2025-10-16 19:13:44 +02:00
parent 53276e858b
commit 6561ba3bc3
16 changed files with 140 additions and 84 deletions

View File

@@ -1,4 +1,5 @@
using API.Schema.ActionsContext;
using API.Schema.ActionsContext.Actions;
using Asp.Versioning;
using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.AspNetCore.Mvc;
@@ -13,19 +14,14 @@ namespace API.Controllers;
public class ActionsController(ActionsContext context) : Controller
{
/// <summary>
/// Returns the available Action Types (<see cref="ActionRecord.Action"/>) performed by Tranga
/// Returns the available Action Types (<see cref="ActionsEnum"/>)
/// </summary>
/// <response code="200">List of performed action-types</response>
/// <response code="500">Database error</response>
/// <response code="200">List of action-types</response>
[HttpGet("Types")]
[ProducesResponseType(Status200OK)]
[ProducesResponseType(Status500InternalServerError)]
public async Task<Results<Ok<List<string>>, InternalServerError>> GetAvailableActions()
[ProducesResponseType<ActionsEnum[]>(Status200OK, "application/json")]
public Ok<ActionsEnum[]> GetAvailableActions()
{
if (await context.Actions.Select(a => a.Action).Distinct().ToListAsync(HttpContext.RequestAborted) is not
{ } actions)
return TypedResults.InternalServerError();
return TypedResults.Ok(actions);
return TypedResults.Ok(Enum.GetValues<ActionsEnum>());
}
public sealed record Interval(DateTime Start, DateTime End);
@@ -35,7 +31,7 @@ public class ActionsController(ActionsContext context) : Controller
/// <response code="200">List of performed actions</response>
/// <response code="500">Database error</response>
[HttpPost("Interval")]
[ProducesResponseType(Status200OK)]
[ProducesResponseType<List<ActionRecord>>(Status200OK, "application/json")]
[ProducesResponseType(Status500InternalServerError)]
public async Task<Results<Ok<List<ActionRecord>>, InternalServerError>> GetActionsInterval([FromBody]Interval interval)
{
@@ -46,14 +42,14 @@ public class ActionsController(ActionsContext context) : Controller
}
/// <summary>
/// Returns <see cref="ActionRecord"/> with type <paramref name="Type"/>
/// Returns <see cref="ActionRecord"/> with <paramref name="Type"/> <see cref="ActionsEnum"/>
/// </summary>
/// <response code="200">List of performed actions</response>
/// <response code="500">Database error</response>
[HttpGet("Type/{Type}")]
[ProducesResponseType(Status200OK)]
[ProducesResponseType<List<ActionRecord>>(Status200OK, "application/json")]
[ProducesResponseType(Status500InternalServerError)]
public async Task<Results<Ok<List<ActionRecord>>, InternalServerError>> GetActionsWithType(string Type)
public async Task<Results<Ok<List<ActionRecord>>, InternalServerError>> GetActionsWithType(ActionsEnum Type)
{
if (await context.Actions.Where(a => a.Action == Type)
.ToListAsync(HttpContext.RequestAborted) is not { } actions)