diff --git a/src/TaxBaik.Application/Services/BlogService.cs b/src/TaxBaik.Application/Services/BlogService.cs index a202cc7..b7010c6 100644 --- a/src/TaxBaik.Application/Services/BlogService.cs +++ b/src/TaxBaik.Application/Services/BlogService.cs @@ -8,7 +8,11 @@ using TaxBaik.Domain.Interfaces; using Microsoft.Extensions.Caching.Memory; -public class BlogService(IBlogPostRepository repository, IMemoryCache memoryCache, IValidator validator) +public class BlogService( + IBlogPostRepository repository, + ICategoryRepository categoryRepository, + IMemoryCache memoryCache, + IValidator validator) { public async Task 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 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 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 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(); diff --git a/src/TaxBaik.Web/Pages/Admin/Announcements/Index.cshtml b/src/TaxBaik.Web/Pages/Admin/Announcements/Index.cshtml index 7043faf..f25dcf8 100644 --- a/src/TaxBaik.Web/Pages/Admin/Announcements/Index.cshtml +++ b/src/TaxBaik.Web/Pages/Admin/Announcements/Index.cshtml @@ -5,43 +5,45 @@
@await Html.PartialAsync("_AdminPageHeader", new TaxBaik.Web.Models.AdminPageHeaderModel("Content", "공지사항 관리", "공지 목록을 서버 렌더링으로 표시합니다.", "/admin/announcements/create", "공지 작성"))
-
- - - - - - - - - - - - @if (Model.Items.Count == 0) - { - - } - else - { - foreach (var item in Model.Items) - { + @if (Model.Items.Count == 0) + { +
+ @await Html.PartialAsync("_EmptyState", "공지사항이 없습니다.") +
+ } + else + { +
+
제목유형활성정렬작업
@await Html.PartialAsync("_EmptyState", "공지사항이 없습니다.")
+ - - - - - + + + + + - } - } - -
@item.Title@item.DisplayType@await Html.PartialAsync("_StatusBadge", item.IsActive ? "active" : "inactive")@item.SortOrder -
- 상세 - 수정 -
-
제목유형활성정렬작업
-
+ + + @foreach (var item in Model.Items) + { + + @item.Title + @item.DisplayType + @await Html.PartialAsync("_StatusBadge", item.IsActive ? "active" : "inactive") + @item.SortOrder + +
+ 상세 + 수정 +
+ + + } + + +
+ }
diff --git a/src/TaxBaik.Web/Pages/Admin/Blog/Index.cshtml b/src/TaxBaik.Web/Pages/Admin/Blog/Index.cshtml index 509b4ef..7d5524b 100644 --- a/src/TaxBaik.Web/Pages/Admin/Blog/Index.cshtml +++ b/src/TaxBaik.Web/Pages/Admin/Blog/Index.cshtml @@ -24,48 +24,48 @@
-
- - - - - - - - - - - - @if (Model.Items.Count == 0) - { - - - - } - else - { - foreach (var post in Model.Items) - { + @if (Model.Items.Count == 0) + { +
+ @await Html.PartialAsync("_EmptyState", "블로그 글이 없습니다.") +
+ } + else + { +
+
제목발행조회수작성일작업
@await Html.PartialAsync("_EmptyState", "블로그 글이 없습니다.")
+ - - - - - + + + + + - } - } - -
-
@post.Title
-
@post.Slug
-
@await Html.PartialAsync("_StatusBadge", post.IsPublished ? "active" : "inactive")@post.ViewCount@post.CreatedAt.ToString("yyyy-MM-dd") -
- 수정 - 보기 -
-
제목발행조회수작성일작업
-
+ + + @foreach (var post in Model.Items) + { + + +
@post.Title
+
@post.Slug
+ + @await Html.PartialAsync("_StatusBadge", post.IsPublished ? "active" : "inactive") + @post.ViewCount + @post.CreatedAt.ToString("yyyy-MM-dd") + +
+ 수정 + 보기 +
+ + + } + + +
+ }