Align admin list empty states and blog category guard
TaxBaik CI/CD / build-and-deploy (push) Failing after 35s
TaxBaik CI/CD / build-and-deploy (push) Failing after 35s
This commit is contained in:
@@ -8,7 +8,11 @@ using TaxBaik.Domain.Interfaces;
|
||||
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
|
||||
public class BlogService(IBlogPostRepository repository, IMemoryCache memoryCache, IValidator<CreateBlogPostDto> validator)
|
||||
public class BlogService(
|
||||
IBlogPostRepository repository,
|
||||
ICategoryRepository categoryRepository,
|
||||
IMemoryCache memoryCache,
|
||||
IValidator<CreateBlogPostDto> validator)
|
||||
{
|
||||
public async Task<BlogPost?> GetByIdAsync(int id, CancellationToken ct = default) =>
|
||||
await repository.GetByIdAsync(id, ct);
|
||||
@@ -62,6 +66,7 @@ public class BlogService(IBlogPostRepository repository, IMemoryCache memoryCach
|
||||
public async Task<BlogPost> CreateAsync(CreateBlogPostDto dto, CancellationToken ct = default)
|
||||
{
|
||||
validator.ValidateAndThrow(dto);
|
||||
dto.CategoryId = await EnsureCategoryIdAsync(dto.CategoryId, ct);
|
||||
var post = new BlogPost
|
||||
{
|
||||
Title = dto.Title,
|
||||
@@ -90,6 +95,7 @@ public class BlogService(IBlogPostRepository repository, IMemoryCache memoryCach
|
||||
public async Task<BlogPost?> UpdateAsync(int id, CreateBlogPostDto dto, CancellationToken ct = default)
|
||||
{
|
||||
validator.ValidateAndThrow(dto);
|
||||
dto.CategoryId = await EnsureCategoryIdAsync(dto.CategoryId, ct);
|
||||
var post = await repository.GetByIdAsync(id, ct);
|
||||
if (post == null)
|
||||
return null;
|
||||
@@ -178,6 +184,15 @@ public class BlogService(IBlogPostRepository repository, IMemoryCache memoryCach
|
||||
|
||||
private static int NormalizePageSize(int pageSize) => Math.Clamp(pageSize, 1, 100);
|
||||
|
||||
private async Task<int> EnsureCategoryIdAsync(int categoryId, CancellationToken ct)
|
||||
{
|
||||
if (categoryId > 0)
|
||||
return categoryId;
|
||||
|
||||
var firstCategory = (await categoryRepository.GetAllAsync(ct)).FirstOrDefault();
|
||||
return firstCategory?.Id ?? throw new ValidationException("블로그 카테고리를 먼저 생성하세요.");
|
||||
}
|
||||
|
||||
public async Task<(int TotalPosts, int PublishedPosts)> GetStatsAsync(CancellationToken ct = default)
|
||||
{
|
||||
var posts = (await repository.GetAllForAdminAsync(ct)).ToList();
|
||||
|
||||
Reference in New Issue
Block a user