diff --git a/src/Moonglade.Core/PostFeature/UpdatePostCommand.cs b/src/Moonglade.Core/PostFeature/UpdatePostCommand.cs index 1c1a5e4bc..b7a5ccf37 100644 --- a/src/Moonglade.Core/PostFeature/UpdatePostCommand.cs +++ b/src/Moonglade.Core/PostFeature/UpdatePostCommand.cs @@ -54,10 +54,23 @@ public async Task Handle(UpdatePostCommand request, CancellationToke UpdatePostDetails(post, postEditModel, utcNow); + await UpdateTags(post, postEditModel.Tags, ct); + await UpdateCats(post, postEditModel.SelectedCatIds, ct); + + await _postRepo.UpdateAsync(post, ct); + + _cache.Remove(BlogCachePartition.Post.ToString(), post.RouteLink); + + _logger.LogInformation($"Post updated: {post.Id}"); + return post; + } + + private async Task UpdateTags(PostEntity post, string tagString, CancellationToken ct) + { // 1. Add new tags to tag lib - var tags = string.IsNullOrWhiteSpace(postEditModel.Tags) ? + var tags = string.IsNullOrWhiteSpace(tagString) ? [] : - postEditModel.Tags.Split(',').ToArray(); + tagString.Split(',').ToArray(); foreach (var item in tags) { @@ -92,15 +105,6 @@ await _tagRepo.AddAsync(new() if (tag is not null) post.Tags.Add(tag); } } - - await UpdateCats(post, postEditModel.SelectedCatIds, ct); - - await _postRepo.UpdateAsync(post, ct); - - _cache.Remove(BlogCachePartition.Post.ToString(), post.RouteLink); - - _logger.LogInformation($"Post updated: {post.Id}"); - return post; } private void UpdatePostDetails(PostEntity post, PostEditModel postEditModel, DateTime utcNow)