feat(blog): refactor author data retrieval to handle potential missing authors

This commit is contained in:
hamed
2026-06-19 00:35:07 +03:30
parent 1e45b12aec
commit 0f3bf68fdd
2 changed files with 19 additions and 5 deletions
+1 -1
View File
@@ -33,7 +33,7 @@ security:
provider: api_doc_provider
public_endpoints:
pattern: ^/(api/v1/user/(send-code|verify-code|register|otp-login|reset-password)|oauth/token$|session/token|api/v1/categorys/|api/v1/doctors$|api/v1/clinics$|api/v1/clinic/doctor-list/|api/v1/clinic/[^/]+/addresses$|api/v1/clinic-pro/doctor-addresses/|api/v1/appointment-slots|api/v1/appointment-settings/month-availability/|api/v1/comments/|api/v1/rate/[^/]+$|api/v1/specialties|api/v1/blogs$|api/v1/clinic-invitation/|api/v1/pre-registration$)
pattern: ^/(api/v1/user/(send-code|verify-code|register|otp-login|reset-password)|oauth/token$|session/token|api/v1/categorys/|api/v1/doctors$|api/v1/clinics$|api/v1/clinic/doctor-list/|api/v1/clinic/[^/]+/addresses$|api/v1/clinic-pro/doctor-addresses/|api/v1/appointment-slots|api/v1/appointment-settings/month-availability/|api/v1/comments/|api/v1/rate/[^/]+$|api/v1/specialties|api/v1/blogs$|api/v1/tags$|api/v1/clinic-invitation/|api/v1/pre-registration$)
stateless: true
security: false
+18 -4
View File
@@ -110,15 +110,29 @@ class Blog
'image_url' => $this->imageUrl,
'tags' => $this->tags,
'status' => $this->status,
'author' => [
'uuid' => $this->author->getUuid(),
'name' => $this->author->getRealName(),
],
'author' => $this->authorToArray(),
'created_at' => $this->createdAt,
'updated_at' => $this->updatedAt,
];
}
private function authorToArray(): ?array
{
if ($this->author === null) {
return null;
}
// The referenced user may have been deleted; a lazy proxy then throws
// EntityNotFoundException on access. Treat a missing author as null.
try {
return [
'uuid' => $this->author->getUuid(),
'name' => $this->author->getRealName(),
];
} catch (\Doctrine\ORM\EntityNotFoundException) {
return null;
}
}
public function toListArray(): array
{
return [