feat(blog): refactor author data retrieval to handle potential missing authors
This commit is contained in:
@@ -33,7 +33,7 @@ security:
|
|||||||
provider: api_doc_provider
|
provider: api_doc_provider
|
||||||
|
|
||||||
public_endpoints:
|
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
|
stateless: true
|
||||||
security: false
|
security: false
|
||||||
|
|
||||||
|
|||||||
@@ -110,15 +110,29 @@ class Blog
|
|||||||
'image_url' => $this->imageUrl,
|
'image_url' => $this->imageUrl,
|
||||||
'tags' => $this->tags,
|
'tags' => $this->tags,
|
||||||
'status' => $this->status,
|
'status' => $this->status,
|
||||||
'author' => [
|
'author' => $this->authorToArray(),
|
||||||
'uuid' => $this->author->getUuid(),
|
|
||||||
'name' => $this->author->getRealName(),
|
|
||||||
],
|
|
||||||
'created_at' => $this->createdAt,
|
'created_at' => $this->createdAt,
|
||||||
'updated_at' => $this->updatedAt,
|
'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
|
public function toListArray(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
|||||||
Reference in New Issue
Block a user