添加Admin角色授权并优化DictController代码格式

This commit is contained in:
罗澜大帅哥 2025-07-16 21:54:40 +08:00
parent 0ddc553ce4
commit 5d9da6360a
2 changed files with 29 additions and 21 deletions

View File

@ -48,10 +48,8 @@ namespace AGSS.Controllers.Dict
[HttpPost("parents")]
public async Task<ActionResult> CreateParent([FromBody] CreateParentRequest request)
{
var result = await _dictService.CreateParentAsync(request.Label, request.Value);
return Ok(new ReturnTemplate(200, "创建成功啦!", result));
}
// 请求模型
@ -73,7 +71,7 @@ public class CreateParentRequest
// 2.1 更新父级项
[Authorize(Roles = "Admin")]
[HttpPut("parents/{uuid}")]
public async Task<ActionResult> UpdateParent(
[FromRoute] Guid uuid,
@ -112,7 +110,6 @@ public class CreateParentRequest
/// </summary>
/// <param name="uuid">The unique identifier (UUID) of the parent dictionary entry to be deleted.</param>
/// <returns>An action result indicating the success or failure of the deletion operation. On success, returns a 200 status code with a confirmation message. In case of an exception, it returns a 200 status code with an error message and exception details.</returns>
[Authorize(Roles = "Admin")]
[HttpDelete("parents/{uuid}")]
public async Task<ActionResult> DeleteParent([FromRoute] Guid uuid)
{
@ -170,7 +167,8 @@ public class CreateParentRequest
/// <remarks>
/// The value of this property should correspond to an existing dictionary item that is not a child itself (i.e., it does not have its own ParentId).
/// </remarks>
[Required(ErrorMessage = "父级ID不能为空")] public Guid ParentId { get; set; }
[Required(ErrorMessage = "父级ID不能为空")]
public Guid ParentId { get; set; }
[Required(ErrorMessage = "父级值不能为空")] public string ParentValue { get; set; } = null!;
@ -180,7 +178,8 @@ public class CreateParentRequest
/// <remarks>
/// The label should be descriptive and meaningful to easily identify the purpose or content of the dictionary item. It plays a crucial role in the user interface and backend logic, serving as a key identifier for related operations.
/// </remarks>
[Required(ErrorMessage = "字典标签不能为空")] public string Label { get; set; } = null!;
[Required(ErrorMessage = "字典标签不能为空")]
public string Label { get; set; } = null!;
[Required(ErrorMessage = "字典值不能为空")] public string Value { get; set; } = null!;
@ -191,6 +190,7 @@ public class CreateParentRequest
/// This property is part of the request model for creating or updating a child dictionary item. It allows for the inclusion of an English label, enhancing multilingual support within the application.
/// </remarks>
public string? LabelEn { get; set; }
public string? Remark { get; set; }
/// <summary>
@ -242,7 +242,8 @@ public class CreateParentRequest
/// <remarks>
/// The Label is used to provide a meaningful name for the dictionary item that can be displayed in user interfaces or referenced in other parts of the application. It is crucial for the identification and management of dictionary items within the system.
/// </remarks>
[Required(ErrorMessage = "字典标签不能为空")] public string Label { get; set; } = null!;
[Required(ErrorMessage = "字典标签不能为空")]
public string Label { get; set; } = null!;
/// <summary>
/// Represents the value of a dictionary item. This property is required and must be provided when updating or creating a dictionary child item.
@ -250,7 +251,8 @@ public class CreateParentRequest
/// <remarks>
/// The value is a unique identifier for the dictionary item within its parent context. It should be meaningful and reflect the nature of the item it represents.
/// </remarks>
[Required(ErrorMessage = "字典值不能为空")] public string Value { get; set; } = null!;
[Required(ErrorMessage = "字典值不能为空")]
public string Value { get; set; } = null!;
/// <summary>
/// Represents the English label for a dictionary item. This property can be used to store an English translation or alternative name for the dictionary entry, facilitating internationalization and localization efforts.

View File

@ -1,6 +1,7 @@
using AGSS.Models.DTOs;
using AGSS.Models.Template;
using AGSS.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace AGSS.Controllers.Menu;
@ -20,6 +21,7 @@ public class MenuController : ControllerBase
/// 新增父级菜单
/// </summary>
[HttpPost("createParent")]
[Authorize(Roles = "Admin")]
public async Task<ReturnTemplate> CreateParentMenu([FromBody] MenuInitialRequest request)
{
return await _menuService.CreateParentMenu(request);
@ -28,6 +30,7 @@ public class MenuController : ControllerBase
/// <summary>
/// 编辑父级菜单
/// </summary>
[Authorize(Roles = "Admin")]
[HttpPut("updateParent")]
public async Task<ReturnTemplate> UpdateParentMenu([FromBody] MenuUpdateRequest request)
{
@ -38,6 +41,7 @@ public class MenuController : ControllerBase
/// 新增子级菜单
/// </summary>
[HttpPost("createChild")]
[Authorize(Roles = "Admin")]
public async Task<ReturnTemplate> CreateChildMenu([FromBody] MenuRequest request)
{
return await _menuService.CreateChildMenu(request);
@ -47,6 +51,7 @@ public class MenuController : ControllerBase
/// 编辑子级菜单
/// </summary>
[HttpPut("updateChild")]
[Authorize(Roles = "Admin")]
public async Task<ReturnTemplate> UpdateChildMenu([FromBody] MenuUpdateRequestSon request)
{
return await _menuService.UpdateChildMenu(request);
@ -65,6 +70,7 @@ public class MenuController : ControllerBase
/// 删除菜单
/// </summary>
[HttpDelete("delete/{uuid}")]
[Authorize(Roles = "Admin")]
public async Task<ReturnTemplate> DeleteMenu(string uuid)
{
return await _menuService.DeleteMenu(uuid);