feat(blog): add archived post restore workflow
TaxBaik CI/CD / build-and-deploy (push) Failing after 5m38s

This commit is contained in:
2026-07-02 11:08:39 +09:00
parent ad55bd1884
commit b06c0f99fb
7 changed files with 105 additions and 3 deletions
@@ -93,6 +93,13 @@ public class BlogServiceTests
return Task.FromResult<(IEnumerable<BlogPost>, int)>((items, items.Count));
}
public Task<(IEnumerable<BlogPost> Items, int Total)> GetArchivedPagedAsync(
int page, int pageSize, CancellationToken cancellationToken = default)
{
var items = Posts.Where(x => x.DeletedAt != null).ToList();
return Task.FromResult<(IEnumerable<BlogPost>, int)>((items, items.Count));
}
public Task<int> CreateAsync(BlogPost post, CancellationToken cancellationToken = default)
{
post.Id = Posts.Count + 1;
@@ -42,6 +42,10 @@ public class BlogService(IBlogPostRepository repository, IMemoryCache memoryCach
int page, int pageSize, CancellationToken ct = default) =>
await repository.GetAdminPagedAsync(NormalizePage(page), NormalizePageSize(pageSize), ct);
public async Task<(IEnumerable<BlogPost>, int)> GetArchivedPagedAsync(
int page, int pageSize, CancellationToken ct = default) =>
await repository.GetArchivedPagedAsync(NormalizePage(page), NormalizePageSize(pageSize), ct);
public async Task<int> CreateAsync(BlogPost post, CancellationToken ct = default)
{
ValidatePost(post);
@@ -12,6 +12,8 @@ public interface IBlogPostRepository
Task<IEnumerable<BlogPost>> GetAllForAdminAsync(CancellationToken cancellationToken = default);
Task<(IEnumerable<BlogPost> Items, int Total)> GetAdminPagedAsync(
int page, int pageSize, CancellationToken cancellationToken = default);
Task<(IEnumerable<BlogPost> Items, int Total)> GetArchivedPagedAsync(
int page, int pageSize, CancellationToken cancellationToken = default);
Task<int> CreateAsync(BlogPost post, CancellationToken cancellationToken = default);
Task UpdateAsync(BlogPost post, CancellationToken cancellationToken = default);
Task DeleteAsync(int id, CancellationToken cancellationToken = default);
@@ -111,6 +111,30 @@ public class BlogPostRepository(IDbConnectionFactory connectionFactory) : BaseRe
return (items, total);
}
public async Task<(IEnumerable<BlogPost> Items, int Total)> GetArchivedPagedAsync(
int page, int pageSize, CancellationToken cancellationToken = default)
{
using var conn = Conn();
var offset = (page - 1) * pageSize;
using var reader = await conn.QueryMultipleAsync(
@"SELECT bp.id, bp.title, bp.content, bp.slug, bp.category_id, bp.tags, bp.author_id,
bp.published_at, bp.view_count, bp.seo_title, bp.seo_description, bp.thumbnail_url,
bp.is_published, bp.created_at, bp.updated_at, bp.deleted_at, c.name AS category_name
FROM blog_posts bp
LEFT JOIN categories c ON bp.category_id = c.id
WHERE bp.deleted_at IS NOT NULL
ORDER BY bp.deleted_at DESC
LIMIT @PageSize OFFSET @Offset;
SELECT COUNT(*) FROM blog_posts WHERE deleted_at IS NOT NULL;",
new { PageSize = pageSize, Offset = offset });
var items = (await reader.ReadAsync<BlogPost>()).ToList();
var total = await reader.ReadFirstAsync<int>();
return (items, total);
}
public async Task<int> CreateAsync(BlogPost post, CancellationToken cancellationToken = default)
{
using var conn = Conn();
@@ -6,10 +6,12 @@ using TaxBaik.Application.DTOs;
public interface IBlogBrowserClient
{
Task<(IEnumerable<BlogPostResponseDto> Items, int Total)> GetAdminPagedAsync(int page = 1, int pageSize = 20, CancellationToken ct = default);
Task<(IEnumerable<BlogPostResponseDto> Items, int Total)> GetArchivedPagedAsync(int page = 1, int pageSize = 20, CancellationToken ct = default);
Task<BlogPostResponseDto?> GetByIdAsync(int id, CancellationToken ct = default);
Task<BlogPostResponseDto?> CreateAsync(CreateBlogPostDto dto, CancellationToken ct = default);
Task<BlogPostResponseDto?> UpdateAsync(int id, CreateBlogPostDto dto, CancellationToken ct = default);
Task<bool> DeleteAsync(int id, CancellationToken ct = default);
Task<bool> RestoreAsync(int id, CancellationToken ct = default);
Task<bool> TogglePublishAsync(int id, CreateBlogPostDto dto, CancellationToken ct = default);
}
@@ -41,6 +43,13 @@ public class BlogBrowserClient : IBlogBrowserClient
return result != null ? (result.Data, result.Total) : ([], 0);
}
public async Task<(IEnumerable<BlogPostResponseDto> Items, int Total)> GetArchivedPagedAsync(int page = 1, int pageSize = 20, CancellationToken ct = default)
{
EnsureAuthHeader();
var result = await _http.GetFromJsonAsync<PagedResponse>($"blog/admin/archived?page={page}&pageSize={pageSize}", ct);
return result != null ? (result.Data, result.Total) : ([], 0);
}
public async Task<BlogPostResponseDto?> GetByIdAsync(int id, CancellationToken ct = default)
{
EnsureAuthHeader();
@@ -74,6 +83,13 @@ public class BlogBrowserClient : IBlogBrowserClient
return response.IsSuccessStatusCode;
}
public async Task<bool> RestoreAsync(int id, CancellationToken ct = default)
{
EnsureAuthHeader();
var response = await _http.PostAsync($"blog/{id}/restore", null, ct);
return response.IsSuccessStatusCode;
}
public async Task<bool> TogglePublishAsync(int id, CreateBlogPostDto dto, CancellationToken ct = default)
{
var result = await UpdateAsync(id, dto, ct);
@@ -7,6 +7,14 @@
<AdminPageHeader Title="블로그 관리" Eyebrow="Content" Subtitle="검색 유입 콘텐츠의 발행 상태와 성과를 관리합니다.">
<ChildContent>
<MudButton Variant="Variant.Outlined" Color="Color.Secondary" StartIcon="@Icons.Material.Filled.Restore"
OnClick="ToggleArchiveView">
@(showArchived ? "전체 글 보기" : "숨김 글 보기")
</MudButton>
<MudButton Variant="Variant.Outlined" Color="Color.Secondary" StartIcon="@Icons.Material.Filled.Refresh"
OnClick="Reload">
새로고침
</MudButton>
<MudButton Variant="Variant.Filled" Color="Color.Primary" StartIcon="@Icons.Material.Filled.EditNote"
Href="/taxbaik/admin/blog/create">새 포스트 작성</MudButton>
</ChildContent>
@@ -39,8 +47,16 @@
<CellTemplate Context="cell">
<MudButton Variant="Variant.Outlined" Size="Size.Small" Color="Color.Primary"
Href="@($"/taxbaik/admin/blog/{cell.Item.Id}/edit")">수정하기</MudButton>
<MudButton Variant="Variant.Text" Size="Size.Small" Color="Color.Error"
@onclick="@(async () => await DeletePost(cell.Item.Id))">삭제</MudButton>
@if (showArchived)
{
<MudButton Variant="Variant.Text" Size="Size.Small" Color="Color.Success"
@onclick="@(async () => await RestorePost(cell.Item.Id))">복원</MudButton>
}
else
{
<MudButton Variant="Variant.Text" Size="Size.Small" Color="Color.Error"
@onclick="@(async () => await DeletePost(cell.Item.Id))">삭제</MudButton>
}
</CellTemplate>
</TemplateColumn>
</Columns>
@@ -61,6 +77,7 @@
private int currentPage = 1;
private int totalPages = 1;
private int totalPosts = 0;
private bool showArchived;
private const int PageSize = 20;
private IEnumerable<TaxBaik.Application.DTOs.BlogPostResponseDto> FilteredPosts => posts
@@ -85,7 +102,9 @@
isLoading = true;
try
{
var result = await BlogClient.GetAdminPagedAsync(currentPage, PageSize);
var result = showArchived
? await BlogClient.GetArchivedPagedAsync(currentPage, PageSize)
: await BlogClient.GetAdminPagedAsync(currentPage, PageSize);
posts = result.Items.ToList();
totalPosts = result.Total;
totalPages = Math.Max(1, (int)Math.Ceiling(totalPosts / (double)PageSize));
@@ -155,4 +174,26 @@
Snackbar.Add("포스트가 삭제되었습니다.", Severity.Success);
await LoadPosts();
}
private async Task RestorePost(int postId)
{
var restored = await BlogClient.RestoreAsync(postId);
if (!restored)
{
Snackbar.Add("포스트 복원에 실패했습니다.", Severity.Error);
return;
}
Snackbar.Add("포스트가 복원되었습니다.", Severity.Success);
await LoadPosts();
}
private async Task ToggleArchiveView()
{
showArchived = !showArchived;
currentPage = 1;
await LoadPosts();
}
private async Task Reload() => await LoadPosts();
}
@@ -58,6 +58,14 @@ public class BlogController : ControllerBase
return Ok(new { data = items, total, page, pageSize });
}
[HttpGet("admin/archived")]
[Authorize]
public async Task<IActionResult> GetArchivedPaged([FromQuery] int page = 1, [FromQuery] int pageSize = 20)
{
var (items, total) = await _blogService.GetArchivedPagedAsync(page, pageSize);
return Ok(new { data = items, total, page, pageSize });
}
[HttpPost]
[Authorize]
public async Task<IActionResult> Create([FromBody] CreateBlogPostDto dto)