From ad55bd188413d2c72587acff0174f5614b0dbaaf Mon Sep 17 00:00:00 2001 From: kjh2064 Date: Thu, 2 Jul 2026 11:05:53 +0900 Subject: [PATCH] fix(blog): add restore path for archived posts --- TaxBaik.Application.Tests/BlogServiceTests.cs | 8 ++++++++ TaxBaik.Application/Services/BlogService.cs | 6 ++++++ TaxBaik.Domain/Interfaces/IBlogPostRepository.cs | 1 + TaxBaik.Infrastructure/Repositories/BlogPostRepository.cs | 8 ++++++++ TaxBaik.Web/Controllers/BlogController.cs | 8 ++++++++ docs/ops/RESTORE_ARCHIVED_BLOG_POSTS.sql | 7 +++++++ 6 files changed, 38 insertions(+) create mode 100644 docs/ops/RESTORE_ARCHIVED_BLOG_POSTS.sql diff --git a/TaxBaik.Application.Tests/BlogServiceTests.cs b/TaxBaik.Application.Tests/BlogServiceTests.cs index 42fbc49..72f5ca1 100644 --- a/TaxBaik.Application.Tests/BlogServiceTests.cs +++ b/TaxBaik.Application.Tests/BlogServiceTests.cs @@ -112,6 +112,14 @@ public class BlogServiceTests public Task ArchiveAsync(int id, CancellationToken cancellationToken = default) => DeleteAsync(id, cancellationToken); + public Task RestoreAsync(int id, CancellationToken cancellationToken = default) + { + var post = Posts.FirstOrDefault(x => x.Id == id); + if (post != null) + post.DeletedAt = null; + return Task.CompletedTask; + } + public Task IncrementViewCountAsync(int id, CancellationToken cancellationToken = default) => Task.CompletedTask; } } diff --git a/TaxBaik.Application/Services/BlogService.cs b/TaxBaik.Application/Services/BlogService.cs index c7829a0..89b7e91 100644 --- a/TaxBaik.Application/Services/BlogService.cs +++ b/TaxBaik.Application/Services/BlogService.cs @@ -116,6 +116,12 @@ public class BlogService(IBlogPostRepository repository, IMemoryCache memoryCach memoryCache.Remove(AdminDashboardService.CacheKey); } + public async Task RestoreAsync(int id, CancellationToken ct = default) + { + await repository.RestoreAsync(id, ct); + memoryCache.Remove(AdminDashboardService.CacheKey); + } + public async Task IncrementViewCountAsync(int id, CancellationToken ct = default) => await repository.IncrementViewCountAsync(id, ct); diff --git a/TaxBaik.Domain/Interfaces/IBlogPostRepository.cs b/TaxBaik.Domain/Interfaces/IBlogPostRepository.cs index bcc5526..48ebce5 100644 --- a/TaxBaik.Domain/Interfaces/IBlogPostRepository.cs +++ b/TaxBaik.Domain/Interfaces/IBlogPostRepository.cs @@ -16,5 +16,6 @@ public interface IBlogPostRepository Task UpdateAsync(BlogPost post, CancellationToken cancellationToken = default); Task DeleteAsync(int id, CancellationToken cancellationToken = default); Task ArchiveAsync(int id, CancellationToken cancellationToken = default); + Task RestoreAsync(int id, CancellationToken cancellationToken = default); Task IncrementViewCountAsync(int id, CancellationToken cancellationToken = default); } diff --git a/TaxBaik.Infrastructure/Repositories/BlogPostRepository.cs b/TaxBaik.Infrastructure/Repositories/BlogPostRepository.cs index dce059a..79b08f5 100644 --- a/TaxBaik.Infrastructure/Repositories/BlogPostRepository.cs +++ b/TaxBaik.Infrastructure/Repositories/BlogPostRepository.cs @@ -149,6 +149,14 @@ public class BlogPostRepository(IDbConnectionFactory connectionFactory) : BaseRe new { Id = id }); } + public async Task RestoreAsync(int id, CancellationToken cancellationToken = default) + { + using var conn = Conn(); + await conn.ExecuteAsync( + "UPDATE blog_posts SET deleted_at = NULL, updated_at = NOW() WHERE id = @Id AND deleted_at IS NOT NULL", + new { Id = id }); + } + public async Task IncrementViewCountAsync(int id, CancellationToken cancellationToken = default) { using var conn = Conn(); diff --git a/TaxBaik.Web/Controllers/BlogController.cs b/TaxBaik.Web/Controllers/BlogController.cs index 55b870d..60c6c15 100644 --- a/TaxBaik.Web/Controllers/BlogController.cs +++ b/TaxBaik.Web/Controllers/BlogController.cs @@ -97,4 +97,12 @@ public class BlogController : ControllerBase await _blogService.ArchiveAsync(id); return NoContent(); } + + [HttpPost("{id}/restore")] + [Authorize] + public async Task Restore(int id) + { + await _blogService.RestoreAsync(id); + return NoContent(); + } } diff --git a/docs/ops/RESTORE_ARCHIVED_BLOG_POSTS.sql b/docs/ops/RESTORE_ARCHIVED_BLOG_POSTS.sql new file mode 100644 index 0000000..dc3fec9 --- /dev/null +++ b/docs/ops/RESTORE_ARCHIVED_BLOG_POSTS.sql @@ -0,0 +1,7 @@ +-- Restore archived blog posts that were hidden by soft delete. +-- Use only when the goal is to bring back previously archived posts. + +UPDATE blog_posts +SET deleted_at = NULL, + updated_at = NOW() +WHERE deleted_at IS NOT NULL;