修改接口

This commit is contained in:
2025-10-16 15:21:52 +08:00
parent 82220ce0b8
commit dd398c1c32
274 changed files with 22777 additions and 22905 deletions

View File

@@ -7,8 +7,8 @@ namespace FutureMailAPI.Controllers
{
[ApiController]
[Route("api/v1/users")]
[Authorize]
public class UsersController : ControllerBase
public class UsersController : BaseController
{
private readonly IUserService _userService;
private readonly ILogger<UsersController> _logger;
@@ -20,12 +20,12 @@ namespace FutureMailAPI.Controllers
}
[HttpGet("{id}")]
public async Task<ActionResult<ApiResponse<UserResponseDto>>> GetUser(int id)
public async Task<IActionResult> GetUser(int id)
{
// 从JWT令牌中获取当前用户ID
var currentUserId = GetCurrentUserId();
if (currentUserId == null)
if (currentUserId <= 0)
{
return Unauthorized(ApiResponse<UserResponseDto>.ErrorResult("未授权访问"));
}
@@ -47,7 +47,7 @@ namespace FutureMailAPI.Controllers
}
[HttpPut("{id}")]
public async Task<ActionResult<ApiResponse<UserResponseDto>>> UpdateUser(int id, [FromBody] UserUpdateDto updateDto)
public async Task<IActionResult> UpdateUser(int id, [FromBody] UserUpdateDto updateDto)
{
if (!ModelState.IsValid)
{
@@ -57,7 +57,7 @@ namespace FutureMailAPI.Controllers
// 从JWT令牌中获取当前用户ID
var currentUserId = GetCurrentUserId();
if (currentUserId == null)
if (currentUserId <= 0)
{
return Unauthorized(ApiResponse<UserResponseDto>.ErrorResult("未授权访问"));
}
@@ -79,7 +79,7 @@ namespace FutureMailAPI.Controllers
}
[HttpPost("{id}/change-password")]
public async Task<ActionResult<ApiResponse<bool>>> ChangePassword(int id, [FromBody] ChangePasswordDto changePasswordDto)
public async Task<IActionResult> ChangePassword(int id, [FromBody] ChangePasswordDto changePasswordDto)
{
if (!ModelState.IsValid)
{
@@ -89,7 +89,7 @@ namespace FutureMailAPI.Controllers
// 从JWT令牌中获取当前用户ID
var currentUserId = GetCurrentUserId();
if (currentUserId == null)
if (currentUserId <= 0)
{
return Unauthorized(ApiResponse<bool>.ErrorResult("未授权访问"));
}
@@ -109,17 +109,5 @@ namespace FutureMailAPI.Controllers
return Ok(result);
}
private int? GetCurrentUserId()
{
var userIdClaim = User.FindFirst(System.Security.Claims.ClaimTypes.NameIdentifier);
if (userIdClaim == null || !int.TryParse(userIdClaim.Value, out var userId))
{
return null;
}
return userId;
}
}
}