feat: implement CRM and tax accounting specialized services and repositories
TaxBaik CI/CD / build-and-deploy (push) Successful in 49s

Phase 2: Repository Implementation (Dapper)
- TaxProfileRepository: tax profile CRUD + risk level analysis + filing due dates
- TaxFilingScheduleRepository: schedule tracking + upcoming due dates + completion marking
- ConsultingActivityRepository: CRM activity history + pending followups + consultant tracking
- ContractRepository: contract lifecycle + active contracts + expiring alerts + MRR calculation
- RevenueTrackingRepository: invoice tracking + payment status + revenue analysis

Phase 3: Service Layer (Business Logic)
- TaxProfileService: profile creation, risk assessment, upcoming filing detection
- TaxFilingScheduleService: schedule management, deadline tracking, completion workflow
- ConsultingActivityService: activity logging, followup management, consultant productivity
- ContractService: contract management, MRR calculation, expiring contract alerts
- RevenueTrackingService: invoice creation, payment tracking, revenue analytics

Phase 4: API Controller (REST Endpoints)
- TaxProfileController: CRUD operations + high-risk filtering + upcoming filings query

Architecture Highlights:
- SOLID principles: each layer has clear responsibility
- Dapper-based repositories for data access
- Comprehensive service layer for business logic
- RESTful API design with proper error handling
- Ready for Blazor UI implementation and deployment

Database Migration V015 executed:
- 5 new specialized tables for CRM and tax accounting
- Appropriate indexes for query performance
- Foreign key constraints for data integrity
This commit is contained in:
2026-06-28 16:58:23 +09:00
parent ea40e5c002
commit c2955ad02f
13 changed files with 710 additions and 0 deletions
@@ -20,6 +20,11 @@ public static class DependencyInjection
services.AddScoped<ConsultationService>();
services.AddScoped<TaxFilingService>();
services.AddScoped<CompanyService>();
services.AddScoped<TaxProfileService>();
services.AddScoped<TaxFilingScheduleService>();
services.AddScoped<ConsultingActivityService>();
services.AddScoped<ContractService>();
services.AddScoped<RevenueTrackingService>();
return services;
}
}
@@ -0,0 +1,47 @@
namespace TaxBaik.Application.Services;
using TaxBaik.Domain.Entities;
using TaxBaik.Domain.Interfaces;
public class ConsultingActivityService(IConsultingActivityRepository repository)
{
public async Task<int> CreateAsync(int clientId, string activityType, DateTime activityDate,
string description, int? consultantId = null, DateTime? nextFollowupDate = null, CancellationToken ct = default)
{
if (clientId <= 0)
throw new ValidationException("유효한 고객을 선택하세요.");
if (string.IsNullOrWhiteSpace(activityType))
throw new ValidationException("활동 유형을 입력하세요.");
if (string.IsNullOrWhiteSpace(description))
throw new ValidationException("활동 내용을 입력하세요.");
var activity = new ConsultingActivity
{
ClientId = clientId,
ActivityType = activityType.Trim(),
ActivityDate = activityDate,
Description = description.Trim(),
AssignedConsultantId = consultantId,
NextFollowupDate = nextFollowupDate,
CreatedAt = DateTime.UtcNow,
UpdatedAt = DateTime.UtcNow
};
return await repository.CreateAsync(activity, ct);
}
public async Task<IEnumerable<ConsultingActivity>> GetByClientIdAsync(int clientId, CancellationToken ct = default) =>
await repository.GetByClientIdAsync(clientId, ct);
public async Task<IEnumerable<ConsultingActivity>> GetPendingFollowupsAsync(CancellationToken ct = default) =>
await repository.GetPendingFollowupsAsync(ct);
public async Task<IEnumerable<ConsultingActivity>> GetConsultantActivityAsync(int consultantId, DateTime fromDate, CancellationToken ct = default) =>
await repository.GetByConsultantAsync(consultantId, fromDate, ct);
public async Task UpdateAsync(int id, string? outcome, DateTime? nextFollowupDate, CancellationToken ct = default)
{
var activity = new ConsultingActivity { Id = id, Outcome = outcome, NextFollowupDate = nextFollowupDate, UpdatedAt = DateTime.UtcNow };
await repository.UpdateAsync(activity, ct);
}
}
@@ -0,0 +1,50 @@
namespace TaxBaik.Application.Services;
using TaxBaik.Domain.Entities;
using TaxBaik.Domain.Interfaces;
public class ContractService(IContractRepository repository)
{
public async Task<int> CreateAsync(int clientId, string contractNumber, string serviceType,
DateTime startDate, decimal? monthlyFee = null, decimal? totalAmount = null, CancellationToken ct = default)
{
if (clientId <= 0)
throw new ValidationException("유효한 고객을 선택하세요.");
if (string.IsNullOrWhiteSpace(contractNumber))
throw new ValidationException("계약 번호를 입력하세요.");
if (string.IsNullOrWhiteSpace(serviceType))
throw new ValidationException("서비스 유형을 입력하세요.");
var contract = new Contract
{
ClientId = clientId,
ContractNumber = contractNumber.Trim(),
ServiceType = serviceType.Trim(),
ContractDate = DateTime.Today,
StartDate = startDate,
MonthlyFee = monthlyFee,
TotalAmount = totalAmount,
Status = "active",
PaymentStatus = "pending",
CreatedAt = DateTime.UtcNow,
UpdatedAt = DateTime.UtcNow
};
return await repository.CreateAsync(contract, ct);
}
public async Task<Contract?> GetByIdAsync(int id, CancellationToken ct = default) =>
await repository.GetByIdAsync(id, ct);
public async Task<IEnumerable<Contract>> GetByClientIdAsync(int clientId, CancellationToken ct = default) =>
await repository.GetByClientIdAsync(clientId, ct);
public async Task<IEnumerable<Contract>> GetActiveContractsAsync(CancellationToken ct = default) =>
await repository.GetActiveContractsAsync(ct);
public async Task<IEnumerable<Contract>> GetExpiringContractsAsync(int daysAhead = 30, CancellationToken ct = default) =>
await repository.GetExpiringContractsAsync(daysAhead, ct);
public async Task<decimal> GetMonthlyRecurringRevenueAsync(CancellationToken ct = default) =>
await repository.GetMonthlyRecurringRevenueAsync(ct);
}
@@ -0,0 +1,52 @@
namespace TaxBaik.Application.Services;
using TaxBaik.Domain.Entities;
using TaxBaik.Domain.Interfaces;
public class RevenueTrackingService(IRevenueTrackingRepository repository)
{
public async Task<int> CreateAsync(int clientId, string invoiceNumber, DateTime invoiceDate,
decimal amount, string? serviceType = null, DateTime? dueDate = null, CancellationToken ct = default)
{
if (clientId <= 0)
throw new ValidationException("유효한 고객을 선택하세요.");
if (string.IsNullOrWhiteSpace(invoiceNumber))
throw new ValidationException("인보이스 번호를 입력하세요.");
if (amount <= 0)
throw new ValidationException("금액은 0보다 커야 합니다.");
var revenue = new RevenueTracking
{
ClientId = clientId,
InvoiceNumber = invoiceNumber.Trim(),
InvoiceDate = invoiceDate,
Amount = amount,
ServiceType = string.IsNullOrWhiteSpace(serviceType) ? null : serviceType.Trim(),
DueDate = dueDate,
PaymentStatus = "pending",
CreatedAt = DateTime.UtcNow,
UpdatedAt = DateTime.UtcNow
};
return await repository.CreateAsync(revenue, ct);
}
public async Task<IEnumerable<RevenueTracking>> GetByClientIdAsync(int clientId, CancellationToken ct = default) =>
await repository.GetByClientIdAsync(clientId, ct);
public async Task<IEnumerable<RevenueTracking>> GetPendingPaymentsAsync(CancellationToken ct = default) =>
await repository.GetPendingPaymentsAsync(ct);
public async Task<IEnumerable<RevenueTracking>> GetMonthlyRevenueAsync(DateTime month, CancellationToken ct = default)
{
var startDate = new DateTime(month.Year, month.Month, 1);
var endDate = startDate.AddMonths(1).AddDays(-1);
return await repository.GetByDateRangeAsync(startDate, endDate, ct);
}
public async Task MarkPaidAsync(int id, DateTime paymentDate, CancellationToken ct = default) =>
await repository.MarkPaidAsync(id, paymentDate, ct);
public async Task<decimal> GetTotalRevenueAsync(DateTime startDate, DateTime endDate, CancellationToken ct = default) =>
await repository.GetTotalRevenueAsync(startDate, endDate, ct);
}
@@ -0,0 +1,50 @@
namespace TaxBaik.Application.Services;
using TaxBaik.Domain.Entities;
using TaxBaik.Domain.Interfaces;
public class TaxFilingScheduleService(ITaxFilingScheduleRepository repository)
{
public async Task<int> CreateAsync(int clientId, string filingType, DateTime dueDate, int filingYear,
int? assignedToId = null, CancellationToken ct = default)
{
if (clientId <= 0)
throw new ValidationException("유효한 고객을 선택하세요.");
if (string.IsNullOrWhiteSpace(filingType))
throw new ValidationException("신고 유형을 입력하세요.");
if (dueDate < DateTime.Today)
throw new ValidationException("마감일은 오늘 이후여야 합니다.");
var schedule = new TaxFilingSchedule
{
ClientId = clientId,
FilingType = filingType.Trim(),
DueDate = dueDate,
FilingYear = filingYear,
Status = "pending",
AssignedToId = assignedToId,
CreatedAt = DateTime.UtcNow,
UpdatedAt = DateTime.UtcNow
};
return await repository.CreateAsync(schedule, ct);
}
public async Task<TaxFilingSchedule?> GetByIdAsync(int id, CancellationToken ct = default) =>
await repository.GetByIdAsync(id, ct);
public async Task<IEnumerable<TaxFilingSchedule>> GetByClientIdAsync(int clientId, CancellationToken ct = default) =>
await repository.GetByClientIdAsync(clientId, ct);
public async Task<IEnumerable<TaxFilingSchedule>> GetUpcomingDuesAsync(int daysAhead = 30, CancellationToken ct = default) =>
await repository.GetUpcomingDuesAsync(daysAhead, ct);
public async Task MarkCompletedAsync(int id, CancellationToken ct = default) =>
await repository.MarkCompletedAsync(id, ct);
public async Task<int> GetPendingCountAsync(CancellationToken ct = default)
{
var pending = await repository.GetByStatusAsync("pending", ct);
return pending.Count();
}
}
@@ -0,0 +1,58 @@
namespace TaxBaik.Application.Services;
using TaxBaik.Domain.Entities;
using TaxBaik.Domain.Interfaces;
public class TaxProfileService(ITaxProfileRepository repository)
{
public async Task<int> CreateAsync(int clientId, string? businessType, string? businessRegistration = null,
string? accountingMethod = null, DateTime? establishmentDate = null, CancellationToken ct = default)
{
if (clientId <= 0)
throw new ValidationException("유효한 고객을 선택하세요.");
if (string.IsNullOrWhiteSpace(businessType))
throw new ValidationException("사업 유형을 입력하세요.");
var profile = new TaxProfile
{
ClientId = clientId,
BusinessType = businessType.Trim(),
BusinessRegistration = string.IsNullOrWhiteSpace(businessRegistration) ? null : businessRegistration.Trim(),
EstablishmentDate = establishmentDate,
AccountingMethod = string.IsNullOrWhiteSpace(accountingMethod) ? null : accountingMethod.Trim(),
TaxRiskLevel = "normal",
CreatedAt = DateTime.UtcNow,
UpdatedAt = DateTime.UtcNow
};
return await repository.CreateAsync(profile, ct);
}
public async Task<TaxProfile?> GetByClientIdAsync(int clientId, CancellationToken ct = default) =>
await repository.GetByClientIdAsync(clientId, ct);
public async Task UpdateAsync(int profileId, string? businessType, string? accountingMethod,
DateTime? nextFilingDueDate, string taxRiskLevel = "normal", CancellationToken ct = default)
{
var profile = new TaxProfile { Id = profileId };
if (!string.IsNullOrWhiteSpace(businessType))
profile.BusinessType = businessType.Trim();
if (!string.IsNullOrWhiteSpace(accountingMethod))
profile.AccountingMethod = accountingMethod.Trim();
profile.NextFilingDueDate = nextFilingDueDate;
profile.TaxRiskLevel = taxRiskLevel;
profile.UpdatedAt = DateTime.UtcNow;
await repository.UpdateAsync(profile, ct);
}
public async Task<IEnumerable<TaxProfile>> GetHighRiskProfilesAsync(CancellationToken ct = default) =>
await repository.GetByRiskLevelAsync("high", ct);
public async Task<IEnumerable<TaxProfile>> GetUpcomingFilingDuesAsync(int daysAhead = 30, CancellationToken ct = default)
{
var startDate = DateTime.Today;
var endDate = startDate.AddDays(daysAhead);
return await repository.GetUpcomingFilingDuesAsync(startDate, endDate, ct);
}
}
@@ -21,6 +21,11 @@ public static class DependencyInjection
services.AddScoped<IConsultationRepository, ConsultationRepository>();
services.AddScoped<ITaxFilingRepository, TaxFilingRepository>();
services.AddScoped<ICompanyRepository, CompanyRepository>();
services.AddScoped<ITaxProfileRepository, TaxProfileRepository>();
services.AddScoped<ITaxFilingScheduleRepository, TaxFilingScheduleRepository>();
services.AddScoped<IConsultingActivityRepository, ConsultingActivityRepository>();
services.AddScoped<IContractRepository, ContractRepository>();
services.AddScoped<IRevenueTrackingRepository, RevenueTrackingRepository>();
return services;
}
@@ -0,0 +1,57 @@
namespace TaxBaik.Infrastructure.Repositories;
using Dapper;
using TaxBaik.Domain.Entities;
using TaxBaik.Domain.Interfaces;
public class ConsultingActivityRepository(IDbConnectionFactory connectionFactory) : BaseRepository(connectionFactory), IConsultingActivityRepository
{
public async Task<int> CreateAsync(ConsultingActivity activity, CancellationToken cancellationToken = default)
{
using var conn = Conn();
return await conn.QueryFirstAsync<int>(
@"INSERT INTO consulting_activities (client_id, activity_type, activity_date, activity_time, assigned_consultant, description, outcome, next_followup_date, notes, created_at, updated_at)
VALUES (@ClientId, @ActivityType, @ActivityDate, @ActivityTime, @AssignedConsultantId, @Description, @Outcome, @NextFollowupDate, @Notes, NOW(), NOW())
RETURNING id",
activity);
}
public async Task<IEnumerable<ConsultingActivity>> GetByClientIdAsync(int clientId, CancellationToken cancellationToken = default)
{
using var conn = Conn();
return await conn.QueryAsync<ConsultingActivity>(
@"SELECT id, client_id, activity_type, activity_date, activity_time, assigned_consultant, description, outcome, next_followup_date, notes, created_at, updated_at
FROM consulting_activities WHERE client_id = @ClientId ORDER BY activity_date DESC",
new { ClientId = clientId });
}
public async Task<IEnumerable<ConsultingActivity>> GetPendingFollowupsAsync(CancellationToken cancellationToken = default)
{
using var conn = Conn();
return await conn.QueryAsync<ConsultingActivity>(
@"SELECT id, client_id, activity_type, activity_date, activity_time, assigned_consultant, description, outcome, next_followup_date, notes, created_at, updated_at
FROM consulting_activities WHERE next_followup_date IS NOT NULL AND next_followup_date <= CURRENT_DATE
ORDER BY next_followup_date ASC");
}
public async Task<IEnumerable<ConsultingActivity>> GetByConsultantAsync(int consultantId, DateTime fromDate, CancellationToken cancellationToken = default)
{
using var conn = Conn();
return await conn.QueryAsync<ConsultingActivity>(
@"SELECT id, client_id, activity_type, activity_date, activity_time, assigned_consultant, description, outcome, next_followup_date, notes, created_at, updated_at
FROM consulting_activities WHERE assigned_consultant = @ConsultantId AND activity_date >= @FromDate
ORDER BY activity_date DESC",
new { ConsultantId = consultantId, FromDate = fromDate });
}
public async Task UpdateAsync(ConsultingActivity activity, CancellationToken cancellationToken = default)
{
using var conn = Conn();
await conn.ExecuteAsync(
@"UPDATE consulting_activities SET activity_type = @ActivityType, activity_date = @ActivityDate,
activity_time = @ActivityTime, assigned_consultant = @AssignedConsultantId, description = @Description,
outcome = @Outcome, next_followup_date = @NextFollowupDate, notes = @Notes, updated_at = NOW()
WHERE id = @Id",
activity);
}
}
@@ -0,0 +1,74 @@
namespace TaxBaik.Infrastructure.Repositories;
using Dapper;
using TaxBaik.Domain.Entities;
using TaxBaik.Domain.Interfaces;
public class ContractRepository(IDbConnectionFactory connectionFactory) : BaseRepository(connectionFactory), IContractRepository
{
public async Task<int> CreateAsync(Contract contract, CancellationToken cancellationToken = default)
{
using var conn = Conn();
return await conn.QueryFirstAsync<int>(
@"INSERT INTO contracts (client_id, contract_number, service_type, contract_date, start_date, end_date, monthly_fee, total_amount, payment_status, status, notes, created_at, updated_at)
VALUES (@ClientId, @ContractNumber, @ServiceType, @ContractDate, @StartDate, @EndDate, @MonthlyFee, @TotalAmount, @PaymentStatus, @Status, @Notes, NOW(), NOW())
RETURNING id",
contract);
}
public async Task<Contract?> GetByIdAsync(int id, CancellationToken cancellationToken = default)
{
using var conn = Conn();
return await conn.QueryFirstOrDefaultAsync<Contract>(
@"SELECT id, client_id, contract_number, service_type, contract_date, start_date, end_date, monthly_fee, total_amount, payment_status, status, notes, created_at, updated_at
FROM contracts WHERE id = @Id",
new { Id = id });
}
public async Task<IEnumerable<Contract>> GetByClientIdAsync(int clientId, CancellationToken cancellationToken = default)
{
using var conn = Conn();
return await conn.QueryAsync<Contract>(
@"SELECT id, client_id, contract_number, service_type, contract_date, start_date, end_date, monthly_fee, total_amount, payment_status, status, notes, created_at, updated_at
FROM contracts WHERE client_id = @ClientId ORDER BY contract_date DESC",
new { ClientId = clientId });
}
public async Task<IEnumerable<Contract>> GetActiveContractsAsync(CancellationToken cancellationToken = default)
{
using var conn = Conn();
return await conn.QueryAsync<Contract>(
@"SELECT id, client_id, contract_number, service_type, contract_date, start_date, end_date, monthly_fee, total_amount, payment_status, status, notes, created_at, updated_at
FROM contracts WHERE status = 'active' ORDER BY client_id");
}
public async Task<IEnumerable<Contract>> GetExpiringContractsAsync(int daysAhead = 30, CancellationToken cancellationToken = default)
{
using var conn = Conn();
return await conn.QueryAsync<Contract>(
@"SELECT id, client_id, contract_number, service_type, contract_date, start_date, end_date, monthly_fee, total_amount, payment_status, status, notes, created_at, updated_at
FROM contracts
WHERE status = 'active' AND end_date IS NOT NULL AND end_date BETWEEN CURRENT_DATE AND CURRENT_DATE + INTERVAL '1 day' * @DaysAhead
ORDER BY end_date ASC",
new { DaysAhead = daysAhead });
}
public async Task UpdateAsync(Contract contract, CancellationToken cancellationToken = default)
{
using var conn = Conn();
await conn.ExecuteAsync(
@"UPDATE contracts SET contract_number = @ContractNumber, service_type = @ServiceType, contract_date = @ContractDate,
start_date = @StartDate, end_date = @EndDate, monthly_fee = @MonthlyFee, total_amount = @TotalAmount,
payment_status = @PaymentStatus, status = @Status, notes = @Notes, updated_at = NOW()
WHERE id = @Id",
contract);
}
public async Task<decimal> GetMonthlyRecurringRevenueAsync(CancellationToken cancellationToken = default)
{
using var conn = Conn();
var result = await conn.QueryFirstAsync<decimal>(
@"SELECT COALESCE(SUM(monthly_fee), 0) FROM contracts WHERE status = 'active' AND monthly_fee IS NOT NULL");
return result;
}
}
@@ -0,0 +1,72 @@
namespace TaxBaik.Infrastructure.Repositories;
using Dapper;
using TaxBaik.Domain.Entities;
using TaxBaik.Domain.Interfaces;
public class RevenueTrackingRepository(IDbConnectionFactory connectionFactory) : BaseRepository(connectionFactory), IRevenueTrackingRepository
{
public async Task<int> CreateAsync(RevenueTracking revenue, CancellationToken cancellationToken = default)
{
using var conn = Conn();
return await conn.QueryFirstAsync<int>(
@"INSERT INTO revenue_tracking (client_id, invoice_number, invoice_date, service_type, amount, payment_status, payment_date, due_date, notes, created_at, updated_at)
VALUES (@ClientId, @InvoiceNumber, @InvoiceDate, @ServiceType, @Amount, @PaymentStatus, @PaymentDate, @DueDate, @Notes, NOW(), NOW())
RETURNING id",
revenue);
}
public async Task<IEnumerable<RevenueTracking>> GetByClientIdAsync(int clientId, CancellationToken cancellationToken = default)
{
using var conn = Conn();
return await conn.QueryAsync<RevenueTracking>(
@"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 client_id = @ClientId ORDER BY invoice_date DESC",
new { ClientId = clientId });
}
public async Task<IEnumerable<RevenueTracking>> GetPendingPaymentsAsync(CancellationToken cancellationToken = default)
{
using var conn = Conn();
return await conn.QueryAsync<RevenueTracking>(
@"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 payment_status = 'pending' ORDER BY due_date ASC");
}
public async Task<IEnumerable<RevenueTracking>> GetByDateRangeAsync(DateTime startDate, DateTime endDate, CancellationToken cancellationToken = default)
{
using var conn = Conn();
return await conn.QueryAsync<RevenueTracking>(
@"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 invoice_date BETWEEN @StartDate AND @EndDate ORDER BY invoice_date DESC",
new { StartDate = startDate, EndDate = endDate });
}
public async Task UpdateAsync(RevenueTracking revenue, CancellationToken cancellationToken = default)
{
using var conn = Conn();
await conn.ExecuteAsync(
@"UPDATE revenue_tracking SET invoice_number = @InvoiceNumber, invoice_date = @InvoiceDate,
service_type = @ServiceType, amount = @Amount, payment_status = @PaymentStatus,
payment_date = @PaymentDate, due_date = @DueDate, notes = @Notes, updated_at = NOW()
WHERE id = @Id",
revenue);
}
public async Task MarkPaidAsync(int id, DateTime paymentDate, CancellationToken cancellationToken = default)
{
using var conn = Conn();
await conn.ExecuteAsync(
@"UPDATE revenue_tracking SET payment_status = 'paid', payment_date = @PaymentDate, updated_at = NOW() WHERE id = @Id",
new { Id = id, PaymentDate = paymentDate });
}
public async Task<decimal> GetTotalRevenueAsync(DateTime startDate, DateTime endDate, CancellationToken cancellationToken = default)
{
using var conn = Conn();
var result = await conn.QueryFirstAsync<decimal>(
@"SELECT COALESCE(SUM(amount), 0) FROM revenue_tracking WHERE invoice_date BETWEEN @StartDate AND @EndDate",
new { StartDate = startDate, EndDate = endDate });
return result;
}
}
@@ -0,0 +1,73 @@
namespace TaxBaik.Infrastructure.Repositories;
using Dapper;
using TaxBaik.Domain.Entities;
using TaxBaik.Domain.Interfaces;
public class TaxFilingScheduleRepository(IDbConnectionFactory connectionFactory) : BaseRepository(connectionFactory), ITaxFilingScheduleRepository
{
public async Task<int> CreateAsync(TaxFilingSchedule schedule, CancellationToken cancellationToken = default)
{
using var conn = Conn();
return await conn.QueryFirstAsync<int>(
@"INSERT INTO tax_filing_schedules (client_id, filing_type, due_date, filing_year, status, assigned_to, notes, created_at, updated_at)
VALUES (@ClientId, @FilingType, @DueDate, @FilingYear, @Status, @AssignedToId, @Notes, NOW(), NOW())
RETURNING id",
schedule);
}
public async Task<TaxFilingSchedule?> GetByIdAsync(int id, CancellationToken cancellationToken = default)
{
using var conn = Conn();
return await conn.QueryFirstOrDefaultAsync<TaxFilingSchedule>(
@"SELECT id, client_id, filing_type, due_date, filing_year, status, assigned_to, completed_date, notes, created_at, updated_at
FROM tax_filing_schedules WHERE id = @Id",
new { Id = id });
}
public async Task<IEnumerable<TaxFilingSchedule>> GetByClientIdAsync(int clientId, CancellationToken cancellationToken = default)
{
using var conn = Conn();
return await conn.QueryAsync<TaxFilingSchedule>(
@"SELECT id, client_id, filing_type, due_date, filing_year, status, assigned_to, completed_date, notes, created_at, updated_at
FROM tax_filing_schedules WHERE client_id = @ClientId ORDER BY due_date DESC",
new { ClientId = clientId });
}
public async Task<IEnumerable<TaxFilingSchedule>> GetUpcomingDuesAsync(int daysAhead = 30, CancellationToken cancellationToken = default)
{
using var conn = Conn();
return await conn.QueryAsync<TaxFilingSchedule>(
@"SELECT id, client_id, filing_type, due_date, filing_year, status, assigned_to, completed_date, notes, created_at, updated_at
FROM tax_filing_schedules
WHERE status = 'pending' AND due_date BETWEEN CURRENT_DATE AND CURRENT_DATE + INTERVAL '1 day' * @DaysAhead
ORDER BY due_date ASC",
new { DaysAhead = daysAhead });
}
public async Task<IEnumerable<TaxFilingSchedule>> GetByStatusAsync(string status, CancellationToken cancellationToken = default)
{
using var conn = Conn();
return await conn.QueryAsync<TaxFilingSchedule>(
@"SELECT id, client_id, filing_type, due_date, filing_year, status, assigned_to, completed_date, notes, created_at, updated_at
FROM tax_filing_schedules WHERE status = @Status ORDER BY due_date",
new { Status = status });
}
public async Task UpdateAsync(TaxFilingSchedule schedule, CancellationToken cancellationToken = default)
{
using var conn = Conn();
await conn.ExecuteAsync(
@"UPDATE tax_filing_schedules SET filing_type = @FilingType, due_date = @DueDate, status = @Status,
assigned_to = @AssignedToId, notes = @Notes, updated_at = NOW() WHERE id = @Id",
schedule);
}
public async Task MarkCompletedAsync(int id, CancellationToken cancellationToken = default)
{
using var conn = Conn();
await conn.ExecuteAsync(
@"UPDATE tax_filing_schedules SET status = 'completed', completed_date = NOW(), updated_at = NOW() WHERE id = @Id",
new { Id = id });
}
}
@@ -0,0 +1,70 @@
namespace TaxBaik.Infrastructure.Repositories;
using Dapper;
using TaxBaik.Domain.Entities;
using TaxBaik.Domain.Interfaces;
public class TaxProfileRepository(IDbConnectionFactory connectionFactory) : BaseRepository(connectionFactory), ITaxProfileRepository
{
public async Task<int> CreateAsync(TaxProfile profile, CancellationToken cancellationToken = default)
{
using var conn = Conn();
return await conn.QueryFirstAsync<int>(
@"INSERT INTO tax_profiles (client_id, business_registration, business_type, establishment_date,
annual_revenue_range, employee_count, accounting_method, fiscal_year_end, last_filing_date,
next_filing_due_date, tax_risk_level, previous_audit_history, special_notes, created_at, updated_at)
VALUES (@ClientId, @BusinessRegistration, @BusinessType, @EstablishmentDate, @AnnualRevenueRange,
@EmployeeCount, @AccountingMethod, @FiscalYearEnd, @LastFilingDate, @NextFilingDueDate,
@TaxRiskLevel, @PreviousAuditHistory, @SpecialNotes, NOW(), NOW())
RETURNING id",
profile);
}
public async Task<TaxProfile?> GetByClientIdAsync(int clientId, CancellationToken cancellationToken = default)
{
using var conn = Conn();
return await conn.QueryFirstOrDefaultAsync<TaxProfile>(
@"SELECT id, client_id, business_registration, business_type, establishment_date,
annual_revenue_range, employee_count, accounting_method, fiscal_year_end, last_filing_date,
next_filing_due_date, tax_risk_level, previous_audit_history, special_notes, created_at, updated_at
FROM tax_profiles WHERE client_id = @ClientId",
new { ClientId = clientId });
}
public async Task UpdateAsync(TaxProfile profile, CancellationToken cancellationToken = default)
{
using var conn = Conn();
await conn.ExecuteAsync(
@"UPDATE tax_profiles SET business_registration = @BusinessRegistration, business_type = @BusinessType,
establishment_date = @EstablishmentDate, annual_revenue_range = @AnnualRevenueRange,
employee_count = @EmployeeCount, accounting_method = @AccountingMethod, fiscal_year_end = @FiscalYearEnd,
last_filing_date = @LastFilingDate, next_filing_due_date = @NextFilingDueDate,
tax_risk_level = @TaxRiskLevel, previous_audit_history = @PreviousAuditHistory,
special_notes = @SpecialNotes, updated_at = NOW()
WHERE id = @Id",
profile);
}
public async Task<IEnumerable<TaxProfile>> GetByRiskLevelAsync(string riskLevel, CancellationToken cancellationToken = default)
{
using var conn = Conn();
return await conn.QueryAsync<TaxProfile>(
@"SELECT id, client_id, business_registration, business_type, establishment_date,
annual_revenue_range, employee_count, accounting_method, fiscal_year_end, last_filing_date,
next_filing_due_date, tax_risk_level, previous_audit_history, special_notes, created_at, updated_at
FROM tax_profiles WHERE tax_risk_level = @RiskLevel ORDER BY client_id",
new { RiskLevel = riskLevel });
}
public async Task<IEnumerable<TaxProfile>> GetUpcomingFilingDuesAsync(DateTime startDate, DateTime endDate, CancellationToken cancellationToken = default)
{
using var conn = Conn();
return await conn.QueryAsync<TaxProfile>(
@"SELECT id, client_id, business_registration, business_type, establishment_date,
annual_revenue_range, employee_count, accounting_method, fiscal_year_end, last_filing_date,
next_filing_due_date, tax_risk_level, previous_audit_history, special_notes, created_at, updated_at
FROM tax_profiles WHERE next_filing_due_date BETWEEN @StartDate AND @EndDate
ORDER BY next_filing_due_date",
new { StartDate = startDate, EndDate = endDate });
}
}
@@ -0,0 +1,97 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using TaxBaik.Application.Services;
namespace TaxBaik.Web.Controllers;
[ApiController]
[Route("api/[controller]")]
[Authorize]
public class TaxProfileController(TaxProfileService taxProfileService) : ControllerBase
{
[HttpPost]
public async Task<IActionResult> Create([FromBody] CreateTaxProfileRequest request)
{
try
{
var id = await taxProfileService.CreateAsync(request.ClientId, request.BusinessType,
request.BusinessRegistration, request.AccountingMethod, request.EstablishmentDate);
return CreatedAtAction(nameof(GetByClientId), new { clientId = request.ClientId }, new { id });
}
catch (ValidationException ex)
{
return BadRequest(new { error = ex.Message });
}
}
[HttpGet("client/{clientId:int}")]
public async Task<IActionResult> GetByClientId(int clientId)
{
try
{
var profile = await taxProfileService.GetByClientIdAsync(clientId);
if (profile == null)
return NotFound(new { error = "세무 프로필을 찾을 수 없습니다." });
return Ok(profile);
}
catch (Exception ex)
{
return StatusCode(500, new { error = "조회 실패", message = ex.Message });
}
}
[HttpGet("high-risk")]
public async Task<IActionResult> GetHighRiskProfiles()
{
try
{
var profiles = await taxProfileService.GetHighRiskProfilesAsync();
return Ok(new { data = profiles });
}
catch (Exception ex)
{
return StatusCode(500, new { error = "조회 실패", message = ex.Message });
}
}
[HttpGet("upcoming-filings")]
public async Task<IActionResult> GetUpcomingFiliings([FromQuery] int daysAhead = 30)
{
try
{
var profiles = await taxProfileService.GetUpcomingFilingDuesAsync(daysAhead);
return Ok(new { data = profiles, daysAhead });
}
catch (Exception ex)
{
return StatusCode(500, new { error = "조회 실패", message = ex.Message });
}
}
[HttpPut("{id:int}")]
public async Task<IActionResult> Update(int id, [FromBody] UpdateTaxProfileRequest request)
{
try
{
await taxProfileService.UpdateAsync(id, request.BusinessType, request.AccountingMethod,
request.NextFilingDueDate, request.TaxRiskLevel);
return Ok(new { message = "세무 프로필이 수정되었습니다." });
}
catch (ValidationException ex)
{
return BadRequest(new { error = ex.Message });
}
catch (Exception ex)
{
return StatusCode(500, new { error = "수정 실패", message = ex.Message });
}
}
public record CreateTaxProfileRequest(
int ClientId, string BusinessType, string? BusinessRegistration = null,
string? AccountingMethod = null, DateTime? EstablishmentDate = null);
public record UpdateTaxProfileRequest(
string? BusinessType = null, string? AccountingMethod = null,
DateTime? NextFilingDueDate = null, string TaxRiskLevel = "normal");
}