SPMS_API/SPMS.API/Controllers/ProfileController.cs
SEAN 4bc08715fa improvement: 공통 응답/에러 포맷 고정 (#164)
- FieldError DTO 공통화 (SPMS.Domain/Common)
- ValidationErrorData + ApiResponse.ValidationFail() 추가
- InvalidModelStateResponseFactory로 ModelState 에러 ApiResponse 변환
- Controller Unauthorized 응답 throw SpmsException으로 통일 (에러코드 102)
- MessageValidationService ValidationErrorDto → FieldError 교체

Closes #164
2026-02-24 16:24:56 +09:00

57 lines
2.2 KiB
C#

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Swashbuckle.AspNetCore.Annotations;
using SPMS.Application.DTOs.Account;
using SPMS.Application.Interfaces;
using SPMS.Domain.Common;
using SPMS.Domain.Exceptions;
namespace SPMS.API.Controllers;
[ApiController]
[Route("v1/in/account/profile")]
[ApiExplorerSettings(GroupName = "account")]
[Authorize]
public class ProfileController : ControllerBase
{
private readonly IAuthService _authService;
public ProfileController(IAuthService authService)
{
_authService = authService;
}
[HttpPost("info")]
[SwaggerOperation(
Summary = "내 정보 조회",
Description = "현재 로그인된 관리자의 프로필 정보를 조회합니다.")]
[SwaggerResponse(200, "조회 성공", typeof(ApiResponse<ProfileResponseDto>))]
[SwaggerResponse(401, "인증되지 않은 요청")]
public async Task<IActionResult> GetProfileAsync()
{
var adminIdClaim = User.FindFirst("adminId")?.Value;
if (string.IsNullOrEmpty(adminIdClaim) || !long.TryParse(adminIdClaim, out var adminId))
throw SpmsException.Unauthorized("인증 정보가 유효하지 않습니다.");
var result = await _authService.GetProfileAsync(adminId);
return Ok(ApiResponse<ProfileResponseDto>.Success(result));
}
[HttpPost("update")]
[SwaggerOperation(
Summary = "내 정보 수정",
Description = "현재 로그인된 관리자의 프로필 정보(이름, 전화번호)를 수정합니다.")]
[SwaggerResponse(200, "수정 성공", typeof(ApiResponse<ProfileResponseDto>))]
[SwaggerResponse(400, "변경된 내용 없음")]
[SwaggerResponse(401, "인증되지 않은 요청")]
public async Task<IActionResult> UpdateProfileAsync([FromBody] UpdateProfileRequestDto request)
{
var adminIdClaim = User.FindFirst("adminId")?.Value;
if (string.IsNullOrEmpty(adminIdClaim) || !long.TryParse(adminIdClaim, out var adminId))
throw SpmsException.Unauthorized("인증 정보가 유효하지 않습니다.");
var result = await _authService.UpdateProfileAsync(adminId, request);
return Ok(ApiResponse<ProfileResponseDto>.Success(result));
}
}