修改接口

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

@@ -6,9 +6,9 @@ using FutureMailAPI.DTOs;
namespace FutureMailAPI.Controllers
{
[ApiController]
[Route("api/v1/capsules")]
[Authorize]
public class CapsulesController : ControllerBase
[Route("api/v1/[controller]")]
public class CapsulesController : BaseController
{
private readonly ITimeCapsuleService _timeCapsuleService;
private readonly ILogger<CapsulesController> _logger;
@@ -20,17 +20,17 @@ namespace FutureMailAPI.Controllers
}
[HttpGet]
public async Task<ActionResult<ApiResponse<TimeCapsuleViewResponseDto>>> GetCapsules()
public async Task<IActionResult> GetCapsules()
{
// 从JWT令牌中获取当前用户ID
var currentUserId = GetCurrentUserId();
if (currentUserId == null)
if (currentUserId <= 0)
{
return Unauthorized(ApiResponse<TimeCapsuleViewResponseDto>.ErrorResult("未授权访问"));
}
var result = await _timeCapsuleService.GetTimeCapsuleViewAsync(currentUserId.Value);
var result = await _timeCapsuleService.GetTimeCapsuleViewAsync(currentUserId);
if (!result.Success)
{
@@ -41,7 +41,7 @@ namespace FutureMailAPI.Controllers
}
[HttpPut("{capsuleId}/style")]
public async Task<ActionResult<ApiResponse<TimeCapsuleResponseDto>>> UpdateCapsuleStyle(int capsuleId, [FromBody] TimeCapsuleStyleUpdateDto updateDto)
public async Task<IActionResult> UpdateCapsuleStyle(int capsuleId, [FromBody] TimeCapsuleStyleUpdateDto updateDto)
{
if (!ModelState.IsValid)
{
@@ -51,12 +51,12 @@ namespace FutureMailAPI.Controllers
// 从JWT令牌中获取当前用户ID
var currentUserId = GetCurrentUserId();
if (currentUserId == null)
if (currentUserId <= 0)
{
return Unauthorized(ApiResponse<TimeCapsuleResponseDto>.ErrorResult("未授权访问"));
}
var result = await _timeCapsuleService.UpdateTimeCapsuleStyleAsync(currentUserId.Value, capsuleId, updateDto);
var result = await _timeCapsuleService.UpdateTimeCapsuleStyleAsync(currentUserId, capsuleId, updateDto);
if (!result.Success)
{
@@ -65,17 +65,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;
}
}
}