SPMS_API/SPMS.API/Controllers/ProfileController.cs
SEAN e81b12fbea feat: 내 정보 조회/수정 API 구현 (#62)
- ProfileResponseDto, UpdateProfileRequestDto 생성
- IAuthService에 GetProfileAsync, UpdateProfileAsync 추가
- AuthService에 프로필 조회/수정 로직 구현
- ProfileController 생성 (v1/in/account/profile)
2026-02-10 10:48:57 +09:00

60 lines
2.3 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;
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))
{
return Unauthorized(ApiResponse<object>.Fail("101", "인증 정보가 유효하지 않습니다."));
}
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))
{
return Unauthorized(ApiResponse<object>.Fail("101", "인증 정보가 유효하지 않습니다."));
}
var result = await _authService.UpdateProfileAsync(adminId, request);
return Ok(ApiResponse<ProfileResponseDto>.Success(result));
}
}