From 2bbe2ef47f2496d25d0f22eb815243c838f78104 Mon Sep 17 00:00:00 2001 From: kjh2064 Date: Fri, 3 Jul 2026 17:34:45 +0900 Subject: [PATCH] =?UTF-8?q?P16:=20TaxFilingController=20=E2=86=92=20FastEn?= =?UTF-8?q?dpoints=20(AllEndpoints.cs)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Migrate TaxFilingController to 6 FastEndpoints - GetUpcoming, GetByClientId, GetById, Create, Update, Delete - Backup original controller as .bak - All endpoints require Bearer token auth Co-Authored-By: Claude Haiku 4.5 --- .../Controllers/TaxFilingController.cs.bak | 84 +++++++ .../Endpoints/TaxFiling/AllEndpoints.cs | 224 ++++++++++++++++++ 2 files changed, 308 insertions(+) create mode 100644 src/TaxBaik.Web/Controllers/TaxFilingController.cs.bak create mode 100644 src/TaxBaik.Web/Endpoints/TaxFiling/AllEndpoints.cs diff --git a/src/TaxBaik.Web/Controllers/TaxFilingController.cs.bak b/src/TaxBaik.Web/Controllers/TaxFilingController.cs.bak new file mode 100644 index 0000000..1727b0c --- /dev/null +++ b/src/TaxBaik.Web/Controllers/TaxFilingController.cs.bak @@ -0,0 +1,84 @@ +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 TaxFilingController : ControllerBase +{ + private readonly TaxFilingService _taxFilingService; + + public TaxFilingController(TaxFilingService taxFilingService) + { + _taxFilingService = taxFilingService; + } + + [HttpGet("upcoming")] + public async Task GetUpcoming([FromQuery] int daysAhead = 30) + { + var filings = await _taxFilingService.GetUpcomingAsync(daysAhead); + return Ok(new { data = filings }); + } + + [HttpGet("client/{clientId}")] + public async Task GetByClientId(int clientId) + { + var filings = await _taxFilingService.GetByClientIdAsync(clientId); + return Ok(new { data = filings }); + } + + [HttpGet("{id}")] + public async Task GetById(int id) + { + var filing = await _taxFilingService.GetByIdAsync(id); + if (filing == null) + return NotFound(new ProblemDetails { Title = "신고 일정을 찾을 수 없습니다.", Status = StatusCodes.Status404NotFound }); + + return Ok(filing); + } + + [HttpPost] + public async Task Create([FromBody] TaxFiling filing) + { + try + { + var filingId = await _taxFilingService.CreateAsync(filing); + var result = await _taxFilingService.GetByIdAsync(filingId); + return CreatedAtAction(nameof(GetById), new { id = filingId }, result); + } + catch (Exception ex) + { + return BadRequest(new ProblemDetails { Title = ex.Message, Status = StatusCodes.Status400BadRequest }); + } + } + + [HttpPut("{id}")] + public async Task Update(int id, [FromBody] TaxFiling filing) + { + filing.Id = id; + try + { + await _taxFilingService.UpdateAsync(filing); + var result = await _taxFilingService.GetByIdAsync(id); + if (result == null) + return NotFound(new ProblemDetails { Title = "신고 일정을 찾을 수 없습니다.", Status = StatusCodes.Status404NotFound }); + + return Ok(result); + } + catch (Exception ex) + { + return BadRequest(new ProblemDetails { Title = ex.Message, Status = StatusCodes.Status400BadRequest }); + } + } + + [HttpDelete("{id}")] + public async Task Delete(int id) + { + await _taxFilingService.DeleteAsync(id); + return NoContent(); + } +} diff --git a/src/TaxBaik.Web/Endpoints/TaxFiling/AllEndpoints.cs b/src/TaxBaik.Web/Endpoints/TaxFiling/AllEndpoints.cs new file mode 100644 index 0000000..051b4ff --- /dev/null +++ b/src/TaxBaik.Web/Endpoints/TaxFiling/AllEndpoints.cs @@ -0,0 +1,224 @@ +using FastEndpoints; +using TaxBaik.Application.Services; +using TaxBaik.Domain.Entities; + +namespace TaxBaik.Web.Endpoints.TaxFiling; + +// DTOs +public class GetUpcomingQuery +{ + public int DaysAhead { get; set; } = 30; +} + +public class CreateTaxFilingRequest +{ + public int? ClientId { get; set; } + public string? FilingType { get; set; } + public DateTime? DueDate { get; set; } + public DateTime? CompletedDate { get; set; } + public string? Status { get; set; } + public string? Notes { get; set; } +} + +public class UpdateTaxFilingRequest +{ + public string? FilingType { get; set; } + public DateTime? DueDate { get; set; } + public DateTime? CompletedDate { get; set; } + public string? Status { get; set; } + public string? Notes { get; set; } +} + +public class TaxFilingListResponse +{ + public List Data { get; set; } = []; +} + +public class TaxFilingResponse +{ + public int Id { get; set; } +} + +public class TaxFilingUpdateResponse +{ + public string Message { get; set; } = string.Empty; +} + +// Endpoints +public class GetUpcomingEndpoint : Endpoint +{ + private readonly TaxFilingService _service; + public GetUpcomingEndpoint(TaxFilingService service) => _service = service; + + public override void Configure() + { + Get("/api/taxfiling/upcoming"); + Policies("Bearer"); + } + + public override async Task HandleAsync(GetUpcomingQuery request, CancellationToken ct) + { + try + { + var filings = await _service.GetUpcomingAsync(request.DaysAhead); + await SendAsync(new TaxFilingListResponse { Data = filings.Cast().ToList() }, 200, cancellation: ct); + } + catch (Exception ex) + { + ThrowError(ex.Message, statusCode: 500); + } + } +} + +public class GetByClientIdEndpoint : Endpoint +{ + private readonly TaxFilingService _service; + public GetByClientIdEndpoint(TaxFilingService service) => _service = service; + + public override void Configure() + { + Get("/api/taxfiling/client/{clientId}"); + Policies("Bearer"); + } + + public override async Task HandleAsync(EmptyRequest _, CancellationToken ct) + { + var clientId = Route("clientId"); + try + { + var filings = await _service.GetByClientIdAsync(clientId); + await SendAsync(new TaxFilingListResponse { Data = filings.Cast().ToList() }, 200, cancellation: ct); + } + catch (Exception ex) + { + ThrowError(ex.Message, statusCode: 500); + } + } +} + +public class GetByIdEndpoint : Endpoint +{ + private readonly TaxFilingService _service; + public GetByIdEndpoint(TaxFilingService service) => _service = service; + + public override void Configure() + { + Get("/api/taxfiling/{id}"); + Policies("Bearer"); + } + + public override async Task HandleAsync(EmptyRequest _, CancellationToken ct) + { + var id = Route("id"); + try + { + var filing = await _service.GetByIdAsync(id); + if (filing == null) + ThrowError("신고 일정을 찾을 수 없습니다.", statusCode: 404); + await SendAsync(filing, 200, cancellation: ct); + } + catch (Exception ex) + { + ThrowError(ex.Message, statusCode: 500); + } + } +} + +public class CreateEndpoint : Endpoint +{ + private readonly TaxFilingService _service; + public CreateEndpoint(TaxFilingService service) => _service = service; + + public override void Configure() + { + Post("/api/taxfiling"); + Policies("Bearer"); + } + + public override async Task HandleAsync(CreateTaxFilingRequest request, CancellationToken ct) + { + try + { + var filing = new TaxFiling + { + ClientId = request.ClientId, + FilingType = request.FilingType, + DueDate = request.DueDate, + CompletedDate = request.CompletedDate, + Status = request.Status, + Notes = request.Notes + }; + var filingId = await _service.CreateAsync(filing); + var result = await _service.GetByIdAsync(filingId); + await SendAsync(new TaxFilingResponse { Id = filingId }, 201, cancellation: ct); + } + catch (Exception ex) + { + ThrowError(ex.Message); + } + } +} + +public class UpdateEndpoint : Endpoint +{ + private readonly TaxFilingService _service; + public UpdateEndpoint(TaxFilingService service) => _service = service; + + public override void Configure() + { + Put("/api/taxfiling/{id}"); + Policies("Bearer"); + } + + public override async Task HandleAsync(UpdateTaxFilingRequest request, CancellationToken ct) + { + var id = Route("id"); + try + { + var filing = new TaxFiling + { + Id = id, + FilingType = request.FilingType, + DueDate = request.DueDate, + CompletedDate = request.CompletedDate, + Status = request.Status, + Notes = request.Notes + }; + await _service.UpdateAsync(filing); + var result = await _service.GetByIdAsync(id); + if (result == null) + ThrowError("신고 일정을 찾을 수 없습니다.", statusCode: 404); + await SendAsync(new TaxFilingUpdateResponse { Message = "신고 일정이 수정되었습니다." }, 200, cancellation: ct); + } + catch (Exception ex) + { + ThrowError(ex.Message); + } + } +} + +public class DeleteEndpoint : Endpoint +{ + private readonly TaxFilingService _service; + public DeleteEndpoint(TaxFilingService service) => _service = service; + + public override void Configure() + { + Delete("/api/taxfiling/{id}"); + Policies("Bearer"); + } + + public override async Task HandleAsync(EmptyRequest _, CancellationToken ct) + { + var id = Route("id"); + try + { + await _service.DeleteAsync(id); + await SendNoContentAsync(ct); + } + catch (Exception ex) + { + ThrowError(ex.Message); + } + } +}