feat(blog): implement medical review gate for blog posts

- Added new fields to the Blog entity: sources, review_status, reviewer, reviewed_at, review_note, and topic_slug.
- Created API endpoints for reviewing blog posts: GET /api/v1/admin/blog/review-queue and POST /api/v1/admin/blog/{uuid}/review.
- Updated BlogController to handle review logic, including approval and rejection of posts.
- Introduced BlogReviewPage component for admin interface to manage blog reviews.
- Added migration to update the database schema for new fields.
- Implemented tests for review queue functionality and review decision handling.
This commit is contained in:
hamed
2026-07-23 21:01:58 +03:30
parent 2abf915f95
commit 14730e43ce
10 changed files with 746 additions and 0 deletions
+82
View File
@@ -12,12 +12,21 @@ use Symfony\Component\Uid\Uuid;
#[ORM\Table(name: 'blogs')]
#[ORM\Index(columns: ['status', 'created_at'], name: 'idx_blogs_status')]
#[ORM\Index(columns: ['city_id'], name: 'idx_blogs_city')]
#[ORM\Index(columns: ['review_status', 'created_at'], name: 'idx_blogs_review_status')]
class Blog
{
public const STATUS_DRAFT = 'draft';
public const STATUS_PUBLISHED = 'published';
public const STATUS_ARCHIVED = 'archived';
// Medical-review gate. NULL is the permanent meaning "not part of the review
// workflow" — a post created manually by an admin, which never needs a doctor's
// approval. The content pipeline sets REVIEW_PENDING on every generated draft;
// only REVIEW_APPROVED may be published by the pipeline.
public const REVIEW_PENDING = 'pending_review';
public const REVIEW_APPROVED = 'approved';
public const REVIEW_REJECTED = 'rejected';
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
@@ -58,9 +67,34 @@ class Blog
#[ORM\Column(type: 'json')]
private array $tags = [];
// Independent sources this article's facts were drawn from — the E-E-A-T
// signal shown on the published post. Each item: { url, title }.
#[ORM\Column(type: 'json')]
private array $sources = [];
#[ORM\Column(type: 'string', length: 20)]
private string $status = self::STATUS_DRAFT;
// NULL = manual admin post, outside the review workflow. Set by the pipeline.
#[ORM\Column(name: 'review_status', type: 'string', length: 20, nullable: true)]
private ?string $reviewStatus = null;
// The doctor who reviewed. Kept even if their user is later removed.
#[ORM\ManyToOne(targetEntity: User::class)]
#[ORM\JoinColumn(name: 'reviewer_id', referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
private ?User $reviewer = null;
#[ORM\Column(name: 'reviewed_at', type: 'integer', nullable: true)]
private ?int $reviewedAt = null;
#[ORM\Column(name: 'review_note', type: 'string', length: 500, nullable: true)]
private ?string $reviewNote = null;
// Stable identity of the pipeline topic (specialty + angle). Unique so a
// re-run is idempotent and never creates a duplicate post. NULL for manual posts.
#[ORM\Column(name: 'topic_slug', type: 'string', length: 255, nullable: true, unique: true)]
private ?string $topicSlug = null;
#[ORM\Column(name: 'created_at', type: 'integer')]
private int $createdAt;
@@ -88,7 +122,13 @@ class Blog
public function getImagePath(): ?string { return $this->imagePath; }
public function getAuthor(): User { return $this->author; }
public function getTags(): array { return $this->tags; }
public function getSources(): array { return $this->sources; }
public function getStatus(): string { return $this->status; }
public function getReviewStatus(): ?string { return $this->reviewStatus; }
public function getReviewer(): ?User { return $this->reviewer; }
public function getReviewedAt(): ?int { return $this->reviewedAt; }
public function getReviewNote(): ?string { return $this->reviewNote; }
public function getTopicSlug(): ?string { return $this->topicSlug; }
public function getCity(): ?City { return $this->city; }
public function setTitle(string $v): self { $this->title = $v; $this->touch(); return $this; }
@@ -98,10 +138,27 @@ class Blog
public function setImageUrl(?string $v): self { $this->imageUrl = $v; $this->touch(); return $this; }
public function setImagePath(?string $v): self { $this->imagePath = $v; $this->touch(); return $this; }
public function setTags(array $v): self { $this->tags = $v; $this->touch(); return $this; }
public function setSources(array $v): self { $this->sources = $v; $this->touch(); return $this; }
public function setStatus(string $v): self { $this->status = $v; $this->touch(); return $this; }
public function setReviewStatus(?string $v): self { $this->reviewStatus = $v; $this->touch(); return $this; }
public function setReviewer(?User $v): self { $this->reviewer = $v; $this->touch(); return $this; }
public function setReviewedAt(?int $v): self { $this->reviewedAt = $v; $this->touch(); return $this; }
public function setReviewNote(?string $v): self { $this->reviewNote = $v; $this->touch(); return $this; }
public function setTopicSlug(?string $v): self { $this->topicSlug = $v; $this->touch(); return $this; }
/** null = پست سراسری (روی همهٔ دامنه‌ها، canonical روی دامنهٔ اصلی) */
public function setCity(?City $v): self { $this->city = $v; $this->touch(); return $this; }
/** Record a doctor's review decision in one call. */
public function applyReview(string $decision, User $reviewer, ?string $note = null): self
{
$this->reviewStatus = $decision;
$this->reviewer = $reviewer;
$this->reviewedAt = time();
$this->reviewNote = $note;
$this->touch();
return $this;
}
private function touch(): void { $this->updatedAt = time(); }
private function generateSlug(string $title): string
@@ -122,7 +179,13 @@ class Blog
'body' => $this->body,
'image_url' => $this->imageUrl,
'tags' => $this->tags,
'sources' => $this->sources,
'status' => $this->status,
'review_status' => $this->reviewStatus,
'reviewer' => $this->reviewerToArray(),
'reviewed_at'=> $this->reviewedAt,
'review_note'=> $this->reviewNote,
'topic_slug' => $this->topicSlug,
'author' => $this->authorToArray(),
'city' => $this->cityToArray(),
'created_at' => $this->createdAt,
@@ -130,6 +193,22 @@ class Blog
];
}
/** The reviewing doctor, or null. Same defensive lazy-proxy handling as author. */
private function reviewerToArray(): ?array
{
if ($this->reviewer === null) {
return null;
}
try {
return [
'uuid' => $this->reviewer->getUuid(),
'name' => $this->reviewer->getRealName(),
];
} catch (\Doctrine\ORM\EntityNotFoundException) {
return null;
}
}
/** null = پست سراسری. مصرف‌کننده روی همین null تصمیم canonical می‌گیرد. */
private function cityToArray(): ?array
{
@@ -170,6 +249,9 @@ class Blog
'image_url' => $this->imageUrl,
'tags' => $this->tags,
'status' => $this->status,
'review_status' => $this->reviewStatus,
'reviewer' => $this->reviewerToArray(),
'topic_slug' => $this->topicSlug,
'city' => $this->cityToArray(),
'created_at' => $this->createdAt,
];