flower-story/Server/Controller/ApiController.cs
2024-10-12 14:34:11 +08:00

57 lines
1.5 KiB
C#

using Blahblah.FlowerStory.Server.Data;
using Microsoft.AspNetCore.Mvc;
namespace Blahblah.FlowerStory.Server.Controller;
/// <summary>
/// 基础 API 服务
/// </summary>
[ApiController]
[Produces("application/json")]
[Route("api")]
public partial class ApiController(FlowerDatabase database, ILogger<ApiController>? logger = null) : BaseController<ApiController>(database, logger)
{
/// <summary>
/// 获取版本号
/// </summary>
/// <remarks>
/// 请求示例:
///
/// GET /api/version
///
/// </remarks>
/// <returns>版本号</returns>
/// <response code="200">返回版本号</response>
[Route("version", Name = "getVersion")]
[HttpGet]
[ResponseCache(NoStore = true, Location = ResponseCacheLocation.None)]
public ActionResult<string> GetApiVersion()
{
return Ok(Program.Version);
}
/// <summary>
/// 获取常量字典定义
/// </summary>
/// <remarks>
/// 请求示例:
///
/// GET /api/consts?{ver}
///
/// </remarks>
/// <returns>字典集</returns>
/// <response code="200">返回常量字典集</response>
[Route("consts", Name = "getConstants")]
[HttpGet]
public ActionResult<DefinitionResult> GetDefinitions()
{
return Ok(new DefinitionResult
{
ApiVersion = Program.Version,
Categories = Constants.Categories,
Events = Constants.Events,
});
}
}