fix(blog): auto-generate slug when admin leaves it empty
Build and Deploy to Kubernetes / build-and-deploy (push) Has been cancelled
Build and Deploy to Kubernetes / build-and-deploy (push) Has been cancelled
Allow optional slug on create/update, generate from title with unique fallback, so BackOffice can publish posts without manual slug entry. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+15
-2
@@ -1,3 +1,4 @@
|
||||
using CMSMicroservice.Application.Common;
|
||||
using CMSMicroservice.Application.Common.FileManager;
|
||||
using CMSMicroservice.Application.Common.Interfaces;
|
||||
using CMSMicroservice.Domain.Entities.Blog;
|
||||
@@ -29,9 +30,21 @@ public class UpdateBlogPostCommandHandler : IRequestHandler<UpdateBlogPostComman
|
||||
?? throw new KeyNotFoundException($"مقاله با شناسه {request.Id} یافت نشد");
|
||||
|
||||
post.Title = request.Title.Trim();
|
||||
// حفظ slug قبلی اگر مقدار جدید خالی باشد
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(request.Slug))
|
||||
post.Slug = request.Slug.Trim().ToLower();
|
||||
{
|
||||
post.Slug = await BlogSlugHelper.EnsureUniquePostSlugAsync(
|
||||
_context,
|
||||
BlogSlugHelper.NormalizeOptional(request.Slug)!,
|
||||
post.Id,
|
||||
cancellationToken);
|
||||
}
|
||||
else if (string.IsNullOrWhiteSpace(post.Slug))
|
||||
{
|
||||
var slug = BlogSlugHelper.ResolveForCreate(null, post.Title);
|
||||
post.Slug = await BlogSlugHelper.EnsureUniquePostSlugAsync(
|
||||
_context, slug, post.Id, cancellationToken);
|
||||
}
|
||||
post.Summary = request.Summary?.Trim();
|
||||
post.HtmlContent = request.HtmlContent;
|
||||
post.FeaturedImagePath = request.FeaturedImagePath;
|
||||
|
||||
Reference in New Issue
Block a user