feat: implement API-first architecture Phase 1 - Dashboard API
**Architecture Refactor (SOLID Principles):** - Implement AdminDashboardController (REST API) - Add dashboard summary endpoint - Add upcoming filings endpoint - Add recent inquiries endpoint - Add monthly statistics endpoint **Database Layer (Repository Pattern):** - Extend IInquiryRepository with date range queries - Implement CountByDateRangeAsync - Implement CountByStatusAndDateAsync - Extend InquiryRepository with new methods **Service Layer (Single Responsibility):** - Extend AdminDashboardService with API methods - Add GetRecentInquiriesAsync - Add GetMonthlyStatsAsync with caching **Test Coverage:** - Update FakeInquiryRepository mock with new methods **SOLID Application:** ✓ Single Responsibility: Each class has one reason to change ✓ Open/Closed: Dashboard API can be extended without modifying existing code ✓ Dependency Inversion: Service depends on Repository abstraction ✓ Interface Segregation: API endpoints are focused and specific Status: ✓ Compiles successfully (0 errors, 0 warnings) Next phases: - Add remaining API controllers (Announcement, Client, FAQ, TaxFiling) - Refactor Blazor components to use API instead of services - Implement JWT token refresh mechanism - Add SignalR for change notifications Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -40,4 +40,48 @@ public class AdminDashboardService(
|
||||
memoryCache.Set(CacheKey, summary, CacheDuration);
|
||||
return summary;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 최근 문의 조회
|
||||
/// </summary>
|
||||
public async Task<IReadOnlyList<Inquiry>> GetRecentInquiriesAsync(int limit, CancellationToken ct = default)
|
||||
{
|
||||
var (inquiries, _) = await inquiryService.GetPagedAsync(1, limit, ct: ct);
|
||||
return inquiries.OrderByDescending(x => x.CreatedAt).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 월별 통계 (접수 건수, 진행 중, 완료)
|
||||
/// </summary>
|
||||
public async Task<object> GetMonthlyStatsAsync(string? month, CancellationToken ct = default)
|
||||
{
|
||||
var targetMonth = month != null && DateTime.TryParse($"{month}-01", out var dt)
|
||||
? dt
|
||||
: DateTime.Today;
|
||||
|
||||
var startDate = new DateTime(targetMonth.Year, targetMonth.Month, 1);
|
||||
var endDate = startDate.AddMonths(1).AddDays(-1);
|
||||
|
||||
// 캐시 시도 (일 단위)
|
||||
var cacheKey = $"admin-stats-{startDate:yyyy-MM}";
|
||||
if (memoryCache.TryGetValue(cacheKey, out object? cachedStats) && cachedStats != null)
|
||||
return cachedStats;
|
||||
|
||||
var total = await inquiryService.CountByDateRangeAsync(startDate, endDate, ct);
|
||||
var consulting = await inquiryService.CountByStatusAndDateAsync("consulting", startDate, endDate, ct);
|
||||
var completed = await inquiryService.CountByStatusAndDateAsync("contracted", startDate, endDate, ct);
|
||||
|
||||
var result = new
|
||||
{
|
||||
month = startDate.ToString("yyyy-MM"),
|
||||
totalInquiries = total,
|
||||
consultingCount = consulting,
|
||||
completedCount = completed,
|
||||
newCount = total - consulting - completed,
|
||||
completionRate = total > 0 ? (completed * 100.0 / total) : 0.0
|
||||
};
|
||||
|
||||
memoryCache.Set(cacheKey, result, TimeSpan.FromHours(1));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +60,12 @@ public class InquiryService(
|
||||
public Task<int> CountByStatusAsync(string status, CancellationToken ct = default)
|
||||
=> repository.CountByStatusAsync(status, ct);
|
||||
|
||||
public Task<int> CountByDateRangeAsync(DateTime startDate, DateTime endDate, CancellationToken ct = default)
|
||||
=> repository.CountByDateRangeAsync(startDate, endDate, ct);
|
||||
|
||||
public Task<int> CountByStatusAndDateAsync(string status, DateTime startDate, DateTime endDate, CancellationToken ct = default)
|
||||
=> repository.CountByStatusAndDateAsync(status, startDate, endDate, ct);
|
||||
|
||||
public async Task UpdateAdminMemoAsync(int id, string? adminMemo, CancellationToken ct = default) =>
|
||||
await repository.UpdateAdminMemoAsync(id, adminMemo, ct);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user