improvement: 서비스명 중복 확인 API 및 ID 정책 보강 (#210)
All checks were successful
SPMS_API/pipeline/head This commit looks good
All checks were successful
SPMS_API/pipeline/head This commit looks good
Reviewed-on: https://git.ipstein.myds.me/SPMS/SPMS_API/pulls/211
This commit is contained in:
commit
a44f023027
|
|
@ -21,6 +21,18 @@ public class ServiceController : ControllerBase
|
||||||
_serviceManagementService = serviceManagementService;
|
_serviceManagementService = serviceManagementService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpPost("name/check")]
|
||||||
|
[SwaggerOperation(
|
||||||
|
Summary = "서비스명 중복 체크",
|
||||||
|
Description = "서비스 등록 전 서비스명 사용 가능 여부를 확인합니다.")]
|
||||||
|
[SwaggerResponse(200, "중복 체크 성공", typeof(ApiResponse<ServiceNameCheckResponseDto>))]
|
||||||
|
[SwaggerResponse(400, "잘못된 요청")]
|
||||||
|
public async Task<IActionResult> CheckServiceNameAsync([FromBody] ServiceNameCheckRequestDto request)
|
||||||
|
{
|
||||||
|
var result = await _serviceManagementService.CheckServiceNameAsync(request);
|
||||||
|
return Ok(ApiResponse<ServiceNameCheckResponseDto>.Success(result));
|
||||||
|
}
|
||||||
|
|
||||||
[HttpPost("create")]
|
[HttpPost("create")]
|
||||||
[SwaggerOperation(
|
[SwaggerOperation(
|
||||||
Summary = "서비스 등록",
|
Summary = "서비스 등록",
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ namespace SPMS.Application.DTOs.Service;
|
||||||
public class CreateServiceRequestDto
|
public class CreateServiceRequestDto
|
||||||
{
|
{
|
||||||
[Required(ErrorMessage = "서비스명은 필수입니다.")]
|
[Required(ErrorMessage = "서비스명은 필수입니다.")]
|
||||||
[StringLength(100, ErrorMessage = "서비스명은 100자 이내여야 합니다.")]
|
[StringLength(100, MinimumLength = 2, ErrorMessage = "서비스명은 2~100자여야 합니다.")]
|
||||||
public string ServiceName { get; set; } = string.Empty;
|
public string ServiceName { get; set; } = string.Empty;
|
||||||
|
|
||||||
[StringLength(500, ErrorMessage = "설명은 500자 이내여야 합니다.")]
|
[StringLength(500, ErrorMessage = "설명은 500자 이내여야 합니다.")]
|
||||||
|
|
|
||||||
10
SPMS.Application/DTOs/Service/ServiceNameCheckRequestDto.cs
Normal file
10
SPMS.Application/DTOs/Service/ServiceNameCheckRequestDto.cs
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace SPMS.Application.DTOs.Service;
|
||||||
|
|
||||||
|
public class ServiceNameCheckRequestDto
|
||||||
|
{
|
||||||
|
[Required(ErrorMessage = "서비스명은 필수입니다.")]
|
||||||
|
[StringLength(100, MinimumLength = 1)]
|
||||||
|
public string ServiceName { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
namespace SPMS.Application.DTOs.Service;
|
||||||
|
|
||||||
|
public class ServiceNameCheckResponseDto
|
||||||
|
{
|
||||||
|
public string ServiceName { get; set; } = string.Empty;
|
||||||
|
public bool IsAvailable { get; set; }
|
||||||
|
}
|
||||||
|
|
@ -4,6 +4,7 @@ namespace SPMS.Application.Interfaces;
|
||||||
|
|
||||||
public interface IServiceManagementService
|
public interface IServiceManagementService
|
||||||
{
|
{
|
||||||
|
Task<ServiceNameCheckResponseDto> CheckServiceNameAsync(ServiceNameCheckRequestDto request);
|
||||||
Task<CreateServiceResponseDto> CreateAsync(CreateServiceRequestDto request, long adminId);
|
Task<CreateServiceResponseDto> CreateAsync(CreateServiceRequestDto request, long adminId);
|
||||||
Task<ServiceResponseDto> UpdateAsync(UpdateServiceRequestDto request);
|
Task<ServiceResponseDto> UpdateAsync(UpdateServiceRequestDto request);
|
||||||
Task<ServiceListResponseDto> GetListAsync(ServiceListRequestDto request);
|
Task<ServiceListResponseDto> GetListAsync(ServiceListRequestDto request);
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,16 @@ public class ServiceManagementService : IServiceManagementService
|
||||||
_credentialEncryptionService = credentialEncryptionService;
|
_credentialEncryptionService = credentialEncryptionService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<ServiceNameCheckResponseDto> CheckServiceNameAsync(ServiceNameCheckRequestDto request)
|
||||||
|
{
|
||||||
|
var exists = await _serviceRepository.ServiceNameExistsAsync(request.ServiceName);
|
||||||
|
return new ServiceNameCheckResponseDto
|
||||||
|
{
|
||||||
|
ServiceName = request.ServiceName,
|
||||||
|
IsAvailable = !exists
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<CreateServiceResponseDto> CreateAsync(CreateServiceRequestDto request, long adminId)
|
public async Task<CreateServiceResponseDto> CreateAsync(CreateServiceRequestDto request, long adminId)
|
||||||
{
|
{
|
||||||
// 서비스명 중복 검사
|
// 서비스명 중복 검사
|
||||||
|
|
@ -34,7 +44,7 @@ public class ServiceManagementService : IServiceManagementService
|
||||||
if (nameExists)
|
if (nameExists)
|
||||||
{
|
{
|
||||||
throw new SpmsException(
|
throw new SpmsException(
|
||||||
ErrorCodes.Conflict,
|
ErrorCodes.ServiceNameDuplicate,
|
||||||
"이미 존재하는 서비스명입니다.",
|
"이미 존재하는 서비스명입니다.",
|
||||||
409);
|
409);
|
||||||
}
|
}
|
||||||
|
|
@ -97,7 +107,7 @@ public class ServiceManagementService : IServiceManagementService
|
||||||
if (nameExists)
|
if (nameExists)
|
||||||
{
|
{
|
||||||
throw new SpmsException(
|
throw new SpmsException(
|
||||||
ErrorCodes.Conflict,
|
ErrorCodes.ServiceNameDuplicate,
|
||||||
"이미 존재하는 서비스명입니다.",
|
"이미 존재하는 서비스명입니다.",
|
||||||
409);
|
409);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ public static class ErrorCodes
|
||||||
public const string DecryptionFailed = "131";
|
public const string DecryptionFailed = "131";
|
||||||
public const string InvalidCredentials = "132";
|
public const string InvalidCredentials = "132";
|
||||||
public const string ServiceScopeRequired = "133";
|
public const string ServiceScopeRequired = "133";
|
||||||
|
public const string ServiceNameDuplicate = "134";
|
||||||
|
|
||||||
// === Device (4) ===
|
// === Device (4) ===
|
||||||
public const string DeviceNotFound = "141";
|
public const string DeviceNotFound = "141";
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user