SPMS_API/SPMS.API/Controllers/ServiceController.cs
seonkyu.kim 4cb54e4c41 feat: API Key 재발급 API 구현 (#46)
- ApiKeyRefreshResponseDto 추가
- IServiceManagementService.RefreshApiKeyAsync 인터페이스 추가
- ServiceManagementService.RefreshApiKeyAsync 구현 (32~64자 랜덤 키 생성)
- ServiceController.RefreshApiKeyAsync 엔드포인트 추가
2026-02-10 00:13:16 +09:00

81 lines
3.5 KiB
C#

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Swashbuckle.AspNetCore.Annotations;
using SPMS.Application.DTOs.Service;
using SPMS.Application.Interfaces;
using SPMS.Domain.Common;
namespace SPMS.API.Controllers;
[ApiController]
[Route("v1/in/service")]
[ApiExplorerSettings(GroupName = "service")]
[Authorize(Roles = "Super")]
public class ServiceController : ControllerBase
{
private readonly IServiceManagementService _serviceManagementService;
public ServiceController(IServiceManagementService serviceManagementService)
{
_serviceManagementService = serviceManagementService;
}
[HttpPost("list")]
[SwaggerOperation(
Summary = "서비스 목록 조회",
Description = "등록된 서비스 목록을 조회합니다. 페이징, 검색, 상태 필터를 지원합니다.")]
[SwaggerResponse(200, "조회 성공", typeof(ApiResponse<ServiceListResponseDto>))]
[SwaggerResponse(401, "인증되지 않은 요청")]
[SwaggerResponse(403, "권한 없음")]
public async Task<IActionResult> GetListAsync([FromBody] ServiceListRequestDto request)
{
var result = await _serviceManagementService.GetListAsync(request);
return Ok(ApiResponse<ServiceListResponseDto>.Success(result));
}
[HttpPost("{serviceCode}")]
[SwaggerOperation(
Summary = "서비스 상세 조회",
Description = "특정 서비스의 상세 정보를 조회합니다.")]
[SwaggerResponse(200, "조회 성공", typeof(ApiResponse<ServiceResponseDto>))]
[SwaggerResponse(401, "인증되지 않은 요청")]
[SwaggerResponse(403, "권한 없음")]
[SwaggerResponse(404, "서비스를 찾을 수 없음")]
public async Task<IActionResult> GetByServiceCodeAsync([FromRoute] string serviceCode)
{
var result = await _serviceManagementService.GetByServiceCodeAsync(serviceCode);
return Ok(ApiResponse<ServiceResponseDto>.Success(result));
}
[HttpPost("{serviceCode}/status")]
[SwaggerOperation(
Summary = "서비스 상태 변경",
Description = "서비스의 상태를 변경합니다. (Active: 0, Suspended: 1)")]
[SwaggerResponse(200, "상태 변경 성공", typeof(ApiResponse<ServiceResponseDto>))]
[SwaggerResponse(400, "잘못된 요청 또는 이미 해당 상태")]
[SwaggerResponse(401, "인증되지 않은 요청")]
[SwaggerResponse(403, "권한 없음")]
[SwaggerResponse(404, "서비스를 찾을 수 없음")]
public async Task<IActionResult> ChangeStatusAsync(
[FromRoute] string serviceCode,
[FromBody] ChangeServiceStatusRequestDto request)
{
var result = await _serviceManagementService.ChangeStatusAsync(serviceCode, request);
return Ok(ApiResponse<ServiceResponseDto>.Success(result));
}
[HttpPost("{serviceCode}/apikey/refresh")]
[SwaggerOperation(
Summary = "API Key 재발급",
Description = "서비스의 API Key를 재발급합니다. 기존 키는 즉시 무효화되며, 새 키는 1회만 표시됩니다.")]
[SwaggerResponse(200, "재발급 성공", typeof(ApiResponse<ApiKeyRefreshResponseDto>))]
[SwaggerResponse(401, "인증되지 않은 요청")]
[SwaggerResponse(403, "권한 없음")]
[SwaggerResponse(404, "서비스를 찾을 수 없음")]
public async Task<IActionResult> RefreshApiKeyAsync([FromRoute] string serviceCode)
{
var result = await _serviceManagementService.RefreshApiKeyAsync(serviceCode);
return Ok(ApiResponse<ApiKeyRefreshResponseDto>.Success(result));
}
}