개선: 배포 검증과 관리자 UX 안정화
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
namespace TaxBaik.Application.Services;
|
||||
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using TaxBaik.Domain.Entities;
|
||||
|
||||
public record AdminDashboardSummary(
|
||||
int ThisMonthInquiries,
|
||||
int NewInquiries,
|
||||
int TotalPosts,
|
||||
int PublishedPosts,
|
||||
IReadOnlyList<Inquiry> RecentInquiries);
|
||||
|
||||
public class AdminDashboardService(
|
||||
InquiryService inquiryService,
|
||||
BlogService blogService,
|
||||
IMemoryCache memoryCache)
|
||||
{
|
||||
private static readonly TimeSpan CacheDuration = TimeSpan.FromSeconds(30);
|
||||
public const string CacheKey = "admin-dashboard-summary";
|
||||
|
||||
public async Task<AdminDashboardSummary> GetSummaryAsync(CancellationToken ct = default)
|
||||
{
|
||||
if (memoryCache.TryGetValue(CacheKey, out AdminDashboardSummary? cached) && cached != null)
|
||||
return cached;
|
||||
|
||||
var recentTask = inquiryService.GetPagedAsync(1, 5, ct: ct);
|
||||
var thisMonthTask = inquiryService.CountThisMonthAsync(ct);
|
||||
var newTask = inquiryService.CountByStatusAsync("new", ct);
|
||||
var statsTask = blogService.GetStatsAsync(ct);
|
||||
|
||||
var (recentInquiries, _) = await recentTask;
|
||||
var stats = await statsTask;
|
||||
var summary = new AdminDashboardSummary(
|
||||
ThisMonthInquiries: await thisMonthTask,
|
||||
NewInquiries: await newTask,
|
||||
TotalPosts: stats.TotalPosts,
|
||||
PublishedPosts: stats.PublishedPosts,
|
||||
RecentInquiries: recentInquiries.OrderByDescending(x => x.CreatedAt).Take(5).ToList());
|
||||
|
||||
memoryCache.Set(CacheKey, summary, CacheDuration);
|
||||
return summary;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user