fix(blog): auto-generate slug when admin leaves it empty
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:
masoodafar-web
2026-06-08 02:06:30 +03:30
parent d22eb1617f
commit 121291eeed
5 changed files with 109 additions and 9 deletions
@@ -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;