feat(blog): add admin endpoint for blog details and cache invalidation

- Implemented `adminDetail()` method in `BlogController` to retrieve blog posts of any status for admin editing.
- Introduced `BlogCacheInvalidator` service to handle cache invalidation after blog create/update/delete actions.
- Updated existing methods in `BlogController` and `RepresentationBlogController` to call cache invalidation on blog modifications.
- Enhanced `BlogFormPage` and `RepresentationBlogFormPage` to utilize the new admin endpoint for fetching blog data.
- Added tests for `BlogCacheInvalidator` to ensure proper functionality and error handling.
- Updated documentation to reflect new API endpoint and cache invalidation behavior.
This commit is contained in:
hamed
2026-07-27 18:54:35 +03:30
parent e4edaea9b8
commit 15abcb5c8a
12 changed files with 972 additions and 47 deletions
@@ -5,6 +5,7 @@ namespace App\Blog\Controller;
use App\Auth\Entity\User;
use App\Blog\Entity\Blog;
use App\Blog\Repository\BlogRepository;
use App\Blog\Service\BlogCacheInvalidator;
use App\Blog\Service\BlogWriter;
use App\Location\Entity\City;
use App\Location\Repository\CityRepository;
@@ -33,6 +34,7 @@ class RepresentationBlogController extends BaseController
private readonly RepresentationRepository $repRepo,
private readonly CityRepository $cityRepo,
private readonly BlogWriter $writer,
private readonly BlogCacheInvalidator $cacheInvalidator,
) {}
private function currentRepresentation(User $user): Representation
@@ -124,6 +126,7 @@ class RepresentationBlogController extends BaseController
$blog->setSlug($blog->getSlug() . '-' . substr(uniqid(), -4));
}
$this->blogRepo->save($blog);
$this->cacheInvalidator->invalidate($blog);
return $this->success(['data' => $blog->toArray()], 201);
}
@@ -149,6 +152,7 @@ class RepresentationBlogController extends BaseController
}
$this->writer->applySeoFields($blog, $data);
$this->blogRepo->save($blog);
$this->cacheInvalidator->invalidate($blog);
return $this->success(['data' => $blog->toArray()]);
}
@@ -159,7 +163,9 @@ class RepresentationBlogController extends BaseController
{
$rep = $this->currentRepresentation($user);
$blog = $this->ownedBlogOr404($uuid, $rep);
$this->cacheInvalidator->invalidate($blog);
$this->blogRepo->remove($blog);
return $this->success(['message' => 'مقاله حذف شد']);
}
}