feat(blog): enhance blog identifier resolution to support multiple identifiers and improve URL handling

This commit is contained in:
hamed
2026-08-09 07:14:16 +03:30
parent f6ef086589
commit dcf9285467
4 changed files with 164 additions and 3 deletions
+4 -1
View File
@@ -193,7 +193,10 @@ class BlogController extends BaseController
#[Route('/api/v1/blog/{slug}', methods: ['GET'])]
public function detail(string $slug, Request $request): JsonResponse
{
$blog = $this->blogRepo->findBySlug($slug) ?? $this->blogRepo->findByUuid($slug);
// Any identifier the post has ever been addressed by: slug, uuid, topic_slug,
// or the uuid prefix carried in an outdated slug. The response always reports
// the canonical slug, so the site can redirect an outdated URL instead of 404.
$blog = $this->blogRepo->findByPublicIdentifier($slug);
if ($blog === null || $blog->getStatus() !== Blog::STATUS_PUBLISHED) {
return $this->error(ErrorCodes::ERR_NOT_FOUND_001, 'مقاله یافت نشد', 404);
}