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();
|
||||
|
||||
@@ -5,43 +5,45 @@
|
||||
<section class="admin-page-shell">
|
||||
@await Html.PartialAsync("_AdminPageHeader", new TaxBaik.Web.Models.AdminPageHeaderModel("Content", "공지사항 관리", "공지 목록을 서버 렌더링으로 표시합니다.", "/admin/announcements/create", "공지 작성"))
|
||||
<div class="card">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-vcenter card-table table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>제목</th>
|
||||
<th>유형</th>
|
||||
<th>활성</th>
|
||||
<th>정렬</th>
|
||||
<th class="text-end">작업</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@if (Model.Items.Count == 0)
|
||||
{
|
||||
<tr><td colspan="5">@await Html.PartialAsync("_EmptyState", "공지사항이 없습니다.")</td></tr>
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var item in Model.Items)
|
||||
{
|
||||
@if (Model.Items.Count == 0)
|
||||
{
|
||||
<div class="card-body">
|
||||
@await Html.PartialAsync("_EmptyState", "공지사항이 없습니다.")
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="table-responsive">
|
||||
<table class="table table-vcenter card-table table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<td class="fw-semibold">@item.Title</td>
|
||||
<td>@item.DisplayType</td>
|
||||
<td>@await Html.PartialAsync("_StatusBadge", item.IsActive ? "active" : "inactive")</td>
|
||||
<td>@item.SortOrder</td>
|
||||
<td class="text-end">
|
||||
<div class="btn-list flex-nowrap justify-content-end">
|
||||
<a class="btn btn-sm btn-outline-secondary" href="/admin/announcements/@item.Id">상세</a>
|
||||
<a class="btn btn-sm btn-primary" href="/admin/announcements/@item.Id/edit">수정</a>
|
||||
</div>
|
||||
</td>
|
||||
<th>제목</th>
|
||||
<th>유형</th>
|
||||
<th>활성</th>
|
||||
<th>정렬</th>
|
||||
<th class="text-end">작업</th>
|
||||
</tr>
|
||||
}
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var item in Model.Items)
|
||||
{
|
||||
<tr>
|
||||
<td class="fw-semibold">@item.Title</td>
|
||||
<td>@item.DisplayType</td>
|
||||
<td>@await Html.PartialAsync("_StatusBadge", item.IsActive ? "active" : "inactive")</td>
|
||||
<td>@item.SortOrder</td>
|
||||
<td class="text-end">
|
||||
<div class="btn-list flex-nowrap justify-content-end">
|
||||
<a class="btn btn-sm btn-outline-secondary" href="/admin/announcements/@item.Id">상세</a>
|
||||
<a class="btn btn-sm btn-primary" href="/admin/announcements/@item.Id/edit">수정</a>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
||||
@@ -24,48 +24,48 @@
|
||||
</form>
|
||||
|
||||
<div class="card">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-vcenter card-table table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>제목</th>
|
||||
<th>발행</th>
|
||||
<th>조회수</th>
|
||||
<th>작성일</th>
|
||||
<th class="text-end">작업</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@if (Model.Items.Count == 0)
|
||||
{
|
||||
<tr>
|
||||
<td colspan="5">@await Html.PartialAsync("_EmptyState", "블로그 글이 없습니다.")</td>
|
||||
</tr>
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var post in Model.Items)
|
||||
{
|
||||
@if (Model.Items.Count == 0)
|
||||
{
|
||||
<div class="card-body">
|
||||
@await Html.PartialAsync("_EmptyState", "블로그 글이 없습니다.")
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="table-responsive">
|
||||
<table class="table table-vcenter card-table table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<td>
|
||||
<div class="fw-semibold">@post.Title</div>
|
||||
<div class="text-muted small">@post.Slug</div>
|
||||
</td>
|
||||
<td>@await Html.PartialAsync("_StatusBadge", post.IsPublished ? "active" : "inactive")</td>
|
||||
<td>@post.ViewCount</td>
|
||||
<td>@post.CreatedAt.ToString("yyyy-MM-dd")</td>
|
||||
<td class="text-end">
|
||||
<div class="btn-list flex-nowrap justify-content-end">
|
||||
<a class="btn btn-sm btn-primary" href="/admin/blog/@post.Id/edit">수정</a>
|
||||
<a class="btn btn-sm btn-outline-secondary" href="/blog/@post.Slug" target="_blank">보기</a>
|
||||
</div>
|
||||
</td>
|
||||
<th>제목</th>
|
||||
<th>발행</th>
|
||||
<th>조회수</th>
|
||||
<th>작성일</th>
|
||||
<th class="text-end">작업</th>
|
||||
</tr>
|
||||
}
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var post in Model.Items)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
<div class="fw-semibold">@post.Title</div>
|
||||
<div class="text-muted small">@post.Slug</div>
|
||||
</td>
|
||||
<td>@await Html.PartialAsync("_StatusBadge", post.IsPublished ? "active" : "inactive")</td>
|
||||
<td>@post.ViewCount</td>
|
||||
<td>@post.CreatedAt.ToString("yyyy-MM-dd")</td>
|
||||
<td class="text-end">
|
||||
<div class="btn-list flex-nowrap justify-content-end">
|
||||
<a class="btn btn-sm btn-primary" href="/admin/blog/@post.Id/edit">수정</a>
|
||||
<a class="btn btn-sm btn-outline-secondary" href="/blog/@post.Slug" target="_blank">보기</a>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user