fix(blog): add restore path for archived posts
TaxBaik CI/CD / build-and-deploy (push) Successful in 4m57s
TaxBaik CI/CD / build-and-deploy (push) Successful in 4m57s
This commit is contained in:
@@ -112,6 +112,14 @@ public class BlogServiceTests
|
|||||||
|
|
||||||
public Task ArchiveAsync(int id, CancellationToken cancellationToken = default) => DeleteAsync(id, cancellationToken);
|
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;
|
public Task IncrementViewCountAsync(int id, CancellationToken cancellationToken = default) => Task.CompletedTask;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -116,6 +116,12 @@ public class BlogService(IBlogPostRepository repository, IMemoryCache memoryCach
|
|||||||
memoryCache.Remove(AdminDashboardService.CacheKey);
|
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) =>
|
public async Task IncrementViewCountAsync(int id, CancellationToken ct = default) =>
|
||||||
await repository.IncrementViewCountAsync(id, ct);
|
await repository.IncrementViewCountAsync(id, ct);
|
||||||
|
|
||||||
|
|||||||
@@ -16,5 +16,6 @@ public interface IBlogPostRepository
|
|||||||
Task UpdateAsync(BlogPost post, CancellationToken cancellationToken = default);
|
Task UpdateAsync(BlogPost post, CancellationToken cancellationToken = default);
|
||||||
Task DeleteAsync(int id, CancellationToken cancellationToken = default);
|
Task DeleteAsync(int id, CancellationToken cancellationToken = default);
|
||||||
Task ArchiveAsync(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);
|
Task IncrementViewCountAsync(int id, CancellationToken cancellationToken = default);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -149,6 +149,14 @@ public class BlogPostRepository(IDbConnectionFactory connectionFactory) : BaseRe
|
|||||||
new { Id = id });
|
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)
|
public async Task IncrementViewCountAsync(int id, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
using var conn = Conn();
|
using var conn = Conn();
|
||||||
|
|||||||
@@ -97,4 +97,12 @@ public class BlogController : ControllerBase
|
|||||||
await _blogService.ArchiveAsync(id);
|
await _blogService.ArchiveAsync(id);
|
||||||
return NoContent();
|
return NoContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpPost("{id}/restore")]
|
||||||
|
[Authorize]
|
||||||
|
public async Task<IActionResult> Restore(int id)
|
||||||
|
{
|
||||||
|
await _blogService.RestoreAsync(id);
|
||||||
|
return NoContent();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
Reference in New Issue
Block a user