using System.Collections.Generic; using MediatR; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using TakeoutSaaS.Application.App.Stores.Dto; using TakeoutSaaS.Application.App.Stores.Queries; using TakeoutSaaS.Shared.Abstractions.Constants; using TakeoutSaaS.Shared.Abstractions.Results; using TakeoutSaaS.Shared.Web.Api; namespace TakeoutSaaS.MiniApi.Controllers; /// /// 桌码上下文。 /// [ApiVersion("1.0")] [Authorize] [Route("api/mini/v{version:apiVersion}/tables")] public sealed class TablesController(IMediator mediator) : BaseApiController { /// /// 解析桌码并返回上下文。 /// [HttpGet("{code}/context")] [ProducesResponseType(typeof(ApiResponse), StatusCodes.Status200OK)] [ProducesResponseType(typeof(ApiResponse), StatusCodes.Status404NotFound)] public async Task> GetContext(string code, CancellationToken cancellationToken) { var result = await mediator.Send(new GetStoreTableContextQuery { TableCode = code }, cancellationToken); return result is null ? ApiResponse.Error(ErrorCodes.NotFound, "桌码不存在") : ApiResponse.Ok(result); } }