개선: 배포 검증과 관리자 UX 안정화
This commit is contained in:
@@ -5,7 +5,9 @@ using TaxBaik.Application.DTOs;
|
||||
using TaxBaik.Domain.Entities;
|
||||
using TaxBaik.Domain.Interfaces;
|
||||
|
||||
public class BlogService(IBlogPostRepository repository)
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
|
||||
public class BlogService(IBlogPostRepository repository, IMemoryCache memoryCache)
|
||||
{
|
||||
public async Task<BlogPost?> GetBySlugAsync(string slug, CancellationToken ct = default) =>
|
||||
await repository.GetBySlugAsync(slug, ct);
|
||||
@@ -20,6 +22,10 @@ public class BlogService(IBlogPostRepository repository)
|
||||
public async Task<IEnumerable<BlogPost>> GetAllForAdminAsync(CancellationToken ct = default) =>
|
||||
await repository.GetAllForAdminAsync(ct);
|
||||
|
||||
public async Task<(IEnumerable<BlogPost>, int)> GetAdminPagedAsync(
|
||||
int page, int pageSize, CancellationToken ct = default) =>
|
||||
await repository.GetAdminPagedAsync(NormalizePage(page), NormalizePageSize(pageSize), ct);
|
||||
|
||||
public async Task<int> CreateAsync(BlogPost post, CancellationToken ct = default)
|
||||
{
|
||||
ValidatePost(post);
|
||||
@@ -27,7 +33,9 @@ public class BlogService(IBlogPostRepository repository)
|
||||
post.Content = post.Content.Trim();
|
||||
post.Slug = await GenerateUniqueSlugAsync(post.Title, ct: ct);
|
||||
post.PublishedAt = post.IsPublished ? DateTime.UtcNow : null;
|
||||
return await repository.CreateAsync(post, ct);
|
||||
var result = await repository.CreateAsync(post, ct);
|
||||
memoryCache.Remove(AdminDashboardService.CacheKey);
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<BlogPost> CreateAsync(CreateBlogPostDto dto, CancellationToken ct = default)
|
||||
@@ -51,8 +59,11 @@ public class BlogService(IBlogPostRepository repository)
|
||||
return post;
|
||||
}
|
||||
|
||||
public async Task UpdateAsync(BlogPost post, CancellationToken ct = default) =>
|
||||
public async Task UpdateAsync(BlogPost post, CancellationToken ct = default)
|
||||
{
|
||||
await repository.UpdateAsync(post, ct);
|
||||
memoryCache.Remove(AdminDashboardService.CacheKey);
|
||||
}
|
||||
|
||||
public async Task<BlogPost?> UpdateAsync(int id, CreateBlogPostDto dto, CancellationToken ct = default)
|
||||
{
|
||||
@@ -77,8 +88,11 @@ public class BlogService(IBlogPostRepository repository)
|
||||
return post;
|
||||
}
|
||||
|
||||
public async Task DeleteAsync(int id, CancellationToken ct = default) =>
|
||||
public async Task DeleteAsync(int id, CancellationToken ct = default)
|
||||
{
|
||||
await repository.DeleteAsync(id, ct);
|
||||
memoryCache.Remove(AdminDashboardService.CacheKey);
|
||||
}
|
||||
|
||||
public async Task IncrementViewCountAsync(int id, CancellationToken ct = default) =>
|
||||
await repository.IncrementViewCountAsync(id, ct);
|
||||
|
||||
Reference in New Issue
Block a user