- AccountController: 운영자 CRUD 엔드포인트 (create, list, detail, update, delete) - AccountService: 비즈니스 로직 구현 - Account DTOs: 요청/응답 DTO 5종 - ErrorCodes: Forbidden 코드 추가 - DI 등록 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
96 lines
4.0 KiB
C#
96 lines
4.0 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")]
|
|
[ApiExplorerSettings(GroupName = "account")]
|
|
[Authorize(Roles = "Super")]
|
|
public class AccountController : ControllerBase
|
|
{
|
|
private readonly IAccountService _accountService;
|
|
|
|
public AccountController(IAccountService accountService)
|
|
{
|
|
_accountService = accountService;
|
|
}
|
|
|
|
[HttpPost("create")]
|
|
[SwaggerOperation(
|
|
Summary = "운영자 계정 생성",
|
|
Description = "Super Admin이 새로운 운영자(Manager/User) 계정을 생성합니다.")]
|
|
[SwaggerResponse(200, "생성 성공", typeof(ApiResponse<AccountResponseDto>))]
|
|
[SwaggerResponse(400, "잘못된 요청")]
|
|
[SwaggerResponse(401, "인증되지 않은 요청")]
|
|
[SwaggerResponse(403, "권한 없음")]
|
|
[SwaggerResponse(409, "이메일 중복")]
|
|
public async Task<IActionResult> CreateAsync([FromBody] CreateAccountRequestDto request)
|
|
{
|
|
var result = await _accountService.CreateAsync(request);
|
|
return Ok(ApiResponse<AccountResponseDto>.Success(result));
|
|
}
|
|
|
|
[HttpPost("list")]
|
|
[SwaggerOperation(
|
|
Summary = "운영자 목록 조회",
|
|
Description = "Super Admin이 운영자(Manager/User) 목록을 조회합니다. Super Admin은 목록에 포함되지 않습니다.")]
|
|
[SwaggerResponse(200, "조회 성공", typeof(ApiResponse<AccountListResponseDto>))]
|
|
[SwaggerResponse(401, "인증되지 않은 요청")]
|
|
[SwaggerResponse(403, "권한 없음")]
|
|
public async Task<IActionResult> GetListAsync([FromBody] AccountListRequestDto request)
|
|
{
|
|
var result = await _accountService.GetListAsync(request);
|
|
return Ok(ApiResponse<AccountListResponseDto>.Success(result));
|
|
}
|
|
|
|
[HttpPost("{adminCode}")]
|
|
[SwaggerOperation(
|
|
Summary = "운영자 상세 조회",
|
|
Description = "Super Admin이 특정 운영자의 상세 정보를 조회합니다.")]
|
|
[SwaggerResponse(200, "조회 성공", typeof(ApiResponse<AccountResponseDto>))]
|
|
[SwaggerResponse(401, "인증되지 않은 요청")]
|
|
[SwaggerResponse(403, "권한 없음")]
|
|
[SwaggerResponse(404, "운영자를 찾을 수 없음")]
|
|
public async Task<IActionResult> GetByAdminCodeAsync([FromRoute] string adminCode)
|
|
{
|
|
var result = await _accountService.GetByAdminCodeAsync(adminCode);
|
|
return Ok(ApiResponse<AccountResponseDto>.Success(result));
|
|
}
|
|
|
|
[HttpPost("{adminCode}/update")]
|
|
[SwaggerOperation(
|
|
Summary = "운영자 정보 수정",
|
|
Description = "Super Admin이 운영자의 정보(이름, 전화번호, 권한)를 수정합니다.")]
|
|
[SwaggerResponse(200, "수정 성공", typeof(ApiResponse<AccountResponseDto>))]
|
|
[SwaggerResponse(400, "잘못된 요청")]
|
|
[SwaggerResponse(401, "인증되지 않은 요청")]
|
|
[SwaggerResponse(403, "권한 없음")]
|
|
[SwaggerResponse(404, "운영자를 찾을 수 없음")]
|
|
public async Task<IActionResult> UpdateAsync(
|
|
[FromRoute] string adminCode,
|
|
[FromBody] UpdateAccountRequestDto request)
|
|
{
|
|
var result = await _accountService.UpdateAsync(adminCode, request);
|
|
return Ok(ApiResponse<AccountResponseDto>.Success(result));
|
|
}
|
|
|
|
[HttpPost("{adminCode}/delete")]
|
|
[SwaggerOperation(
|
|
Summary = "운영자 계정 삭제",
|
|
Description = "Super Admin이 운영자 계정을 삭제합니다. (Soft Delete)")]
|
|
[SwaggerResponse(200, "삭제 성공")]
|
|
[SwaggerResponse(401, "인증되지 않은 요청")]
|
|
[SwaggerResponse(403, "권한 없음")]
|
|
[SwaggerResponse(404, "운영자를 찾을 수 없음")]
|
|
public async Task<IActionResult> DeleteAsync([FromRoute] string adminCode)
|
|
{
|
|
await _accountService.DeleteAsync(adminCode);
|
|
return Ok(ApiResponse.Success());
|
|
}
|
|
}
|