68 lines
2.0 KiB
C#
68 lines
2.0 KiB
C#
using Management.Data;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System.Text.Json;
|
|
|
|
namespace Management.Controllers;
|
|
|
|
/// <summary>
|
|
/// Public help content endpoint — anonymous, no auth required.
|
|
/// Returns 200 with default message when key not found, so client
|
|
/// never needs to handle a 404.
|
|
/// </summary>
|
|
[ApiController]
|
|
[Route("api/help")]
|
|
public class HelpController : ControllerBase
|
|
{
|
|
private readonly SqlService _sql;
|
|
private readonly ILogger<HelpController> _logger;
|
|
|
|
public HelpController(SqlService sql, ILogger<HelpController> logger)
|
|
{
|
|
_sql = sql;
|
|
_logger = logger;
|
|
}
|
|
|
|
/// <summary>
|
|
/// GET /api/help/{key}
|
|
/// Returns active help content for the given key, or a friendly
|
|
/// default if no content has been authored yet.
|
|
/// </summary>
|
|
[HttpGet("{key}")]
|
|
public async Task<IActionResult> GetHelp(string key, CancellationToken ct)
|
|
{
|
|
try
|
|
{
|
|
var rqst = JsonSerializer.Serialize(new { helpKey = key });
|
|
var resp = await _sql.ExecProcAsync("dbo.spHelp", "get", rqst, ct: ct);
|
|
|
|
if (!string.IsNullOrWhiteSpace(resp))
|
|
{
|
|
using var doc = JsonDocument.Parse(resp);
|
|
var root = doc.RootElement;
|
|
|
|
if (root.TryGetProperty("ok", out var ok) && ok.GetBoolean())
|
|
return Content(resp, "application/json");
|
|
}
|
|
|
|
// Key not found — return 200 with friendly default so clients
|
|
// don't need special 404 handling
|
|
return Ok(new
|
|
{
|
|
ok = true,
|
|
title = "Help",
|
|
body = "<p>No information available for this topic yet.</p>"
|
|
});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Error retrieving help content for key: {Key}", key);
|
|
return Ok(new
|
|
{
|
|
ok = true,
|
|
title = "Help",
|
|
body = "<p>No information available for this topic yet.</p>"
|
|
});
|
|
}
|
|
}
|
|
}
|