Align admin list empty states and blog category guard
TaxBaik CI/CD / build-and-deploy (push) Failing after 35s

This commit is contained in:
2026-07-09 15:41:43 +09:00
parent 2f72834317
commit 44777f4a1f
3 changed files with 93 additions and 76 deletions
@@ -8,7 +8,11 @@ using TaxBaik.Domain.Interfaces;
using Microsoft.Extensions.Caching.Memory; 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) => public async Task<BlogPost?> GetByIdAsync(int id, CancellationToken ct = default) =>
await repository.GetByIdAsync(id, ct); 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) public async Task<BlogPost> CreateAsync(CreateBlogPostDto dto, CancellationToken ct = default)
{ {
validator.ValidateAndThrow(dto); validator.ValidateAndThrow(dto);
dto.CategoryId = await EnsureCategoryIdAsync(dto.CategoryId, ct);
var post = new BlogPost var post = new BlogPost
{ {
Title = dto.Title, 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) public async Task<BlogPost?> UpdateAsync(int id, CreateBlogPostDto dto, CancellationToken ct = default)
{ {
validator.ValidateAndThrow(dto); validator.ValidateAndThrow(dto);
dto.CategoryId = await EnsureCategoryIdAsync(dto.CategoryId, ct);
var post = await repository.GetByIdAsync(id, ct); var post = await repository.GetByIdAsync(id, ct);
if (post == null) if (post == null)
return 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 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) public async Task<(int TotalPosts, int PublishedPosts)> GetStatsAsync(CancellationToken ct = default)
{ {
var posts = (await repository.GetAllForAdminAsync(ct)).ToList(); var posts = (await repository.GetAllForAdminAsync(ct)).ToList();
@@ -5,6 +5,14 @@
<section class="admin-page-shell"> <section class="admin-page-shell">
@await Html.PartialAsync("_AdminPageHeader", new TaxBaik.Web.Models.AdminPageHeaderModel("Content", "공지사항 관리", "공지 목록을 서버 렌더링으로 표시합니다.", "/admin/announcements/create", "공지 작성")) @await Html.PartialAsync("_AdminPageHeader", new TaxBaik.Web.Models.AdminPageHeaderModel("Content", "공지사항 관리", "공지 목록을 서버 렌더링으로 표시합니다.", "/admin/announcements/create", "공지 작성"))
<div class="card"> <div class="card">
@if (Model.Items.Count == 0)
{
<div class="card-body">
@await Html.PartialAsync("_EmptyState", "공지사항이 없습니다.")
</div>
}
else
{
<div class="table-responsive"> <div class="table-responsive">
<table class="table table-vcenter card-table table-hover"> <table class="table table-vcenter card-table table-hover">
<thead> <thead>
@@ -17,13 +25,7 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@if (Model.Items.Count == 0) @foreach (var item in Model.Items)
{
<tr><td colspan="5">@await Html.PartialAsync("_EmptyState", "공지사항이 없습니다.")</td></tr>
}
else
{
foreach (var item in Model.Items)
{ {
<tr> <tr>
<td class="fw-semibold">@item.Title</td> <td class="fw-semibold">@item.Title</td>
@@ -38,10 +40,10 @@
</td> </td>
</tr> </tr>
} }
}
</tbody> </tbody>
</table> </table>
</div> </div>
}
</div> </div>
</section> </section>
+10 -10
View File
@@ -24,6 +24,14 @@
</form> </form>
<div class="card"> <div class="card">
@if (Model.Items.Count == 0)
{
<div class="card-body">
@await Html.PartialAsync("_EmptyState", "블로그 글이 없습니다.")
</div>
}
else
{
<div class="table-responsive"> <div class="table-responsive">
<table class="table table-vcenter card-table table-hover"> <table class="table table-vcenter card-table table-hover">
<thead> <thead>
@@ -36,15 +44,7 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@if (Model.Items.Count == 0) @foreach (var post in Model.Items)
{
<tr>
<td colspan="5">@await Html.PartialAsync("_EmptyState", "블로그 글이 없습니다.")</td>
</tr>
}
else
{
foreach (var post in Model.Items)
{ {
<tr> <tr>
<td> <td>
@@ -62,10 +62,10 @@
</td> </td>
</tr> </tr>
} }
}
</tbody> </tbody>
</table> </table>
</div> </div>
}
</div> </div>
</section> </section>