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))] [SwaggerResponse(401, "인증되지 않은 요청")] public async Task 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.Success(result)); } [HttpPost("update")] [SwaggerOperation( Summary = "내 정보 수정", Description = "현재 로그인된 관리자의 프로필 정보(이름, 전화번호)를 수정합니다.")] [SwaggerResponse(200, "수정 성공", typeof(ApiResponse))] [SwaggerResponse(400, "변경된 내용 없음")] [SwaggerResponse(401, "인증되지 않은 요청")] public async Task 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.Success(result)); } }