diff --git a/TaxBaik.Application/Services/RevenueTrackingService.cs b/TaxBaik.Application/Services/RevenueTrackingService.cs index be9c66c..528236d 100644 --- a/TaxBaik.Application/Services/RevenueTrackingService.cs +++ b/TaxBaik.Application/Services/RevenueTrackingService.cs @@ -34,6 +34,9 @@ public class RevenueTrackingService(IRevenueTrackingRepository repository) public async Task> GetByClientIdAsync(int clientId, CancellationToken ct = default) => await repository.GetByClientIdAsync(clientId, ct); + public async Task GetByIdAsync(int id, CancellationToken ct = default) => + await repository.GetByIdAsync(id, ct); + public async Task> GetAllAsync(CancellationToken ct = default) => await repository.GetAllAsync(ct); diff --git a/TaxBaik.Domain/Interfaces/IRevenueTrackingRepository.cs b/TaxBaik.Domain/Interfaces/IRevenueTrackingRepository.cs index 498402b..6a1563f 100644 --- a/TaxBaik.Domain/Interfaces/IRevenueTrackingRepository.cs +++ b/TaxBaik.Domain/Interfaces/IRevenueTrackingRepository.cs @@ -5,6 +5,7 @@ using TaxBaik.Domain.Entities; public interface IRevenueTrackingRepository { Task CreateAsync(RevenueTracking revenue, CancellationToken cancellationToken = default); + Task GetByIdAsync(int id, CancellationToken cancellationToken = default); Task> GetAllAsync(CancellationToken cancellationToken = default); Task> GetByClientIdAsync(int clientId, CancellationToken cancellationToken = default); Task> GetPendingPaymentsAsync(CancellationToken cancellationToken = default); diff --git a/TaxBaik.Infrastructure/Repositories/RevenueTrackingRepository.cs b/TaxBaik.Infrastructure/Repositories/RevenueTrackingRepository.cs index a6fe61a..806d9c7 100644 --- a/TaxBaik.Infrastructure/Repositories/RevenueTrackingRepository.cs +++ b/TaxBaik.Infrastructure/Repositories/RevenueTrackingRepository.cs @@ -24,6 +24,15 @@ public class RevenueTrackingRepository(IDbConnectionFactory connectionFactory) : FROM revenue_tracking ORDER BY invoice_date DESC"); } + public async Task GetByIdAsync(int id, CancellationToken cancellationToken = default) + { + using var conn = Conn(); + return await conn.QueryFirstOrDefaultAsync( + @"SELECT id, client_id, invoice_number, invoice_date, service_type, amount, payment_status, payment_date, due_date, notes, created_at, updated_at + FROM revenue_tracking WHERE id = @Id", + new { Id = id }); + } + public async Task> GetByClientIdAsync(int clientId, CancellationToken cancellationToken = default) { using var conn = Conn(); diff --git a/TaxBaik.Web/Controllers/RevenueTrackingController.cs b/TaxBaik.Web/Controllers/RevenueTrackingController.cs index d850125..da54eba 100644 --- a/TaxBaik.Web/Controllers/RevenueTrackingController.cs +++ b/TaxBaik.Web/Controllers/RevenueTrackingController.cs @@ -41,11 +41,15 @@ public class RevenueTrackingController(RevenueTrackingService service) : Control [HttpGet("{id:int}")] public async Task GetById(int id) { - return StatusCode(StatusCodes.Status501NotImplemented, new + try { - error = "미구현", - message = "RevenueTrackingService.GetByIdAsync 구현이 필요합니다." - }); + var revenue = await service.GetByIdAsync(id); + return revenue is null ? NotFound(new { error = "조회 실패", message = "해당 청구를 찾을 수 없습니다." }) : Ok(revenue); + } + catch (Exception ex) + { + return StatusCode(500, new { error = "조회 실패", message = ex.Message }); + } } [HttpGet("client/{clientId:int}")]