fix: 菜单固定为全局

This commit is contained in:
2025-12-27 16:33:18 +08:00
parent 212c7bde44
commit dd58cc2ed0
6 changed files with 61 additions and 32 deletions

View File

@@ -60,11 +60,8 @@ public sealed class MenusController(IMediator mediator) : BaseApiController
[ProducesResponseType(typeof(ApiResponse<MenuDefinitionDto>), StatusCodes.Status200OK)]
public async Task<ApiResponse<MenuDefinitionDto>> Create([FromBody, Required] CreateMenuCommand command, CancellationToken cancellationToken)
{
// 1. 创建菜单
var result = await mediator.Send(command, cancellationToken);
// 2. 返回创建结果
return ApiResponse<MenuDefinitionDto>.Ok(result);
// 1. 菜单已固定,禁止新增
return await Task.FromResult(ApiResponse<MenuDefinitionDto>.Error(StatusCodes.Status403Forbidden, "菜单已固定,禁止新增"));
}
/// <summary>
@@ -79,16 +76,8 @@ public sealed class MenusController(IMediator mediator) : BaseApiController
[FromBody, Required] UpdateMenuCommand command,
CancellationToken cancellationToken)
{
// 1. 绑定菜单 ID
command = command with { Id = menuId };
// 2. 执行更新
var result = await mediator.Send(command, cancellationToken);
// 3. 返回或 404
return result is null
? ApiResponse<MenuDefinitionDto>.Error(StatusCodes.Status404NotFound, "菜单不存在")
: ApiResponse<MenuDefinitionDto>.Ok(result);
// 1. 菜单已固定,禁止修改
return await Task.FromResult(ApiResponse<MenuDefinitionDto>.Error(StatusCodes.Status403Forbidden, "菜单已固定,禁止修改"));
}
/// <summary>
@@ -99,10 +88,7 @@ public sealed class MenusController(IMediator mediator) : BaseApiController
[ProducesResponseType(typeof(ApiResponse<bool>), StatusCodes.Status200OK)]
public async Task<ApiResponse<bool>> Delete(long menuId, CancellationToken cancellationToken)
{
// 1. 删除菜单
var result = await mediator.Send(new DeleteMenuCommand { Id = menuId }, cancellationToken);
// 2. 返回执行结果
return ApiResponse<bool>.Ok(result);
// 1. 菜单已固定,禁止删除
return await Task.FromResult(ApiResponse<bool>.Error(StatusCodes.Status403Forbidden, "菜单已固定,禁止删除"));
}
}