feat: 管理端核心实体CRUD补齐

This commit is contained in:
2025-12-02 10:19:35 +08:00
parent 1a01454266
commit 93141fbf0c
75 changed files with 4513 additions and 0 deletions

View File

@@ -0,0 +1,108 @@
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using TakeoutSaaS.Application.App.Deliveries.Commands;
using TakeoutSaaS.Application.App.Deliveries.Dto;
using TakeoutSaaS.Application.App.Deliveries.Queries;
using TakeoutSaaS.Domain.Deliveries.Enums;
using TakeoutSaaS.Module.Authorization.Attributes;
using TakeoutSaaS.Shared.Abstractions.Constants;
using TakeoutSaaS.Shared.Abstractions.Results;
using TakeoutSaaS.Shared.Web.Api;
namespace TakeoutSaaS.AdminApi.Controllers;
/// <summary>
/// 配送单管理。
/// </summary>
[ApiVersion("1.0")]
[Authorize]
[Route("api/admin/v{version:apiVersion}/deliveries")]
public sealed class DeliveriesController : BaseApiController
{
private readonly IMediator _mediator;
/// <summary>
/// 初始化控制器。
/// </summary>
public DeliveriesController(IMediator mediator)
{
_mediator = mediator;
}
/// <summary>
/// 创建配送单。
/// </summary>
[HttpPost]
[PermissionAuthorize("delivery:create")]
[ProducesResponseType(typeof(ApiResponse<DeliveryOrderDto>), StatusCodes.Status200OK)]
public async Task<ApiResponse<DeliveryOrderDto>> Create([FromBody] CreateDeliveryOrderCommand command, CancellationToken cancellationToken)
{
var result = await _mediator.Send(command, cancellationToken);
return ApiResponse<DeliveryOrderDto>.Ok(result);
}
/// <summary>
/// 查询配送单列表。
/// </summary>
[HttpGet]
[PermissionAuthorize("delivery:read")]
[ProducesResponseType(typeof(ApiResponse<IReadOnlyList<DeliveryOrderDto>>), StatusCodes.Status200OK)]
public async Task<ApiResponse<IReadOnlyList<DeliveryOrderDto>>> List([FromQuery] long? orderId, [FromQuery] DeliveryStatus? status, CancellationToken cancellationToken)
{
var result = await _mediator.Send(new SearchDeliveryOrdersQuery
{
OrderId = orderId,
Status = status
}, cancellationToken);
return ApiResponse<IReadOnlyList<DeliveryOrderDto>>.Ok(result);
}
/// <summary>
/// 获取配送单详情。
/// </summary>
[HttpGet("{deliveryOrderId:long}")]
[PermissionAuthorize("delivery:read")]
[ProducesResponseType(typeof(ApiResponse<DeliveryOrderDto>), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ApiResponse<object>), StatusCodes.Status404NotFound)]
public async Task<ApiResponse<DeliveryOrderDto>> Detail(long deliveryOrderId, CancellationToken cancellationToken)
{
var result = await _mediator.Send(new GetDeliveryOrderByIdQuery { DeliveryOrderId = deliveryOrderId }, cancellationToken);
return result == null
? ApiResponse<DeliveryOrderDto>.Error(ErrorCodes.NotFound, "配送单不存在")
: ApiResponse<DeliveryOrderDto>.Ok(result);
}
/// <summary>
/// 更新配送单。
/// </summary>
[HttpPut("{deliveryOrderId:long}")]
[PermissionAuthorize("delivery:update")]
[ProducesResponseType(typeof(ApiResponse<DeliveryOrderDto>), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ApiResponse<object>), StatusCodes.Status404NotFound)]
public async Task<ApiResponse<DeliveryOrderDto>> Update(long deliveryOrderId, [FromBody] UpdateDeliveryOrderCommand command, CancellationToken cancellationToken)
{
command.DeliveryOrderId = command.DeliveryOrderId == 0 ? deliveryOrderId : command.DeliveryOrderId;
var result = await _mediator.Send(command, cancellationToken);
return result == null
? ApiResponse<DeliveryOrderDto>.Error(ErrorCodes.NotFound, "配送单不存在")
: ApiResponse<DeliveryOrderDto>.Ok(result);
}
/// <summary>
/// 删除配送单。
/// </summary>
[HttpDelete("{deliveryOrderId:long}")]
[PermissionAuthorize("delivery:delete")]
[ProducesResponseType(typeof(ApiResponse<object>), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ApiResponse<object>), StatusCodes.Status404NotFound)]
public async Task<ApiResponse<object>> Delete(long deliveryOrderId, CancellationToken cancellationToken)
{
var success = await _mediator.Send(new DeleteDeliveryOrderCommand { DeliveryOrderId = deliveryOrderId }, cancellationToken);
return success
? ApiResponse<object>.Ok(null)
: ApiResponse<object>.Error(ErrorCodes.NotFound, "配送单不存在");
}
}