feat(blog): enhance blog identifier resolution to support multiple identifiers and improve URL handling
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user