P17: CommonCodeController → FastEndpoints (AllEndpoints.cs)

- Migrate CommonCodeController to 6 FastEndpoints
- GetAllActive, GetByGroup, GetGroups, GetByGroupAndValue, Upsert, Delete
- Backup original controller as .bak
- All endpoints require Bearer token auth
- Validation rules enforced on Upsert (no spaces in group/value)

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-07-03 17:34:49 +09:00
parent 2bbe2ef47f
commit 063ec189ce
2 changed files with 295 additions and 0 deletions
@@ -0,0 +1,82 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using TaxBaik.Application.Services;
using TaxBaik.Domain.Entities;
namespace TaxBaik.Web.Controllers;
[ApiController]
[Route("api/[controller]")]
[Authorize]
public class CommonCodeController(CommonCodeService commonCodeService) : ControllerBase
{
[HttpGet]
public async Task<IActionResult> GetAllActive()
{
try
{
var codes = await commonCodeService.GetAllActiveAsync();
return Ok(codes);
}
catch (Exception ex)
{
return StatusCode(500, new { error = "공통코드 조회 실패", message = ex.Message });
}
}
[HttpGet("group/{group}")]
public async Task<IActionResult> GetByGroup(string group)
{
try
{
var codes = await commonCodeService.GetByGroupAsync(group);
return Ok(codes);
}
catch (Exception ex)
{
return StatusCode(500, new { error = "그룹별 공통코드 조회 실패", message = ex.Message });
}
}
[HttpGet("groups")]
public async Task<IActionResult> GetGroups()
{
try
{
var groups = await commonCodeService.GetAllGroupsAsync();
return Ok(groups);
}
catch (Exception ex)
{
return StatusCode(500, new { error = "공통코드 그룹 조회 실패", message = ex.Message });
}
}
[HttpGet("{group}/{value}")]
public async Task<IActionResult> Get(string group, string value)
{
var code = await commonCodeService.GetAsync(group, value);
return code is null ? NotFound() : Ok(code);
}
[HttpPost]
public async Task<IActionResult> Upsert([FromBody] CommonCode code)
{
if (string.IsNullOrWhiteSpace(code.CodeGroup) || string.IsNullOrWhiteSpace(code.CodeValue) || string.IsNullOrWhiteSpace(code.CodeName))
return BadRequest(new { error = "코드 그룹, 값, 이름은 필수입니다." });
if (code.CodeGroup.Any(char.IsWhiteSpace))
return BadRequest(new { error = "code_group에는 공백을 사용할 수 없습니다." });
if (code.CodeValue.Contains(' '))
return BadRequest(new { error = "code_value에는 공백을 사용할 수 없습니다." });
await commonCodeService.UpsertAsync(code);
return Ok(code);
}
[HttpDelete("{group}/{value}")]
public async Task<IActionResult> Delete(string group, string value)
{
await commonCodeService.DeleteAsync(group, value);
return NoContent();
}
}