@page "/admin/blog"
@attribute [Authorize]
@inject IApiClient ApiClient
@inject DialogService DialogService
@inject ISnackbar Snackbar
블로그 관리
📝 블로그 관리
새 포스트
수정
await DeletePost(cell.Item.Id))">삭제
@code {
private List posts = [];
private bool isLoading = true;
protected override async Task OnInitializedAsync()
{
await LoadPosts();
}
private async Task LoadPosts()
{
isLoading = true;
try
{
var items = await ApiClient.GetAsync>("blog/admin/all");
posts = items ?? [];
}
catch { }
isLoading = false;
}
private async Task TogglePublish(TaxBaik.Domain.Entities.BlogPost post, bool isPublished)
{
var previous = post.IsPublished;
post.IsPublished = isPublished;
var result = await ApiClient.PutAsync($"blog/{post.Id}", new
{
post.Title,
post.Content,
post.CategoryId,
post.Tags,
post.SeoTitle,
post.SeoDescription,
post.ThumbnailUrl,
IsPublished = isPublished,
post.AuthorId
});
if (result == null)
{
post.IsPublished = previous;
Snackbar.Add("발행 상태 변경에 실패했습니다.", Severity.Error);
return;
}
Snackbar.Add("발행 상태가 변경되었습니다.", Severity.Success);
}
private async Task DeletePost(int postId)
{
await ApiClient.DeleteAsync($"blog/{postId}");
Snackbar.Add("포스트가 삭제되었습니다.", Severity.Success);
await LoadPosts();
}
}