pwa setting
This commit is contained in:
@@ -3,9 +3,11 @@
|
||||
namespace App\ClinicInvitation\Controller;
|
||||
|
||||
use App\Auth\Entity\User;
|
||||
use App\ClinicInvitation\Entity\ClinicDoctorInvitation;
|
||||
use App\ClinicInvitation\Repository\ClinicDoctorInvitationRepository;
|
||||
use App\ClinicInvitation\Service\ClinicInvitationService;
|
||||
use App\Clinic\Repository\ClinicRepository;
|
||||
use App\Doctor\Repository\DoctorRepository;
|
||||
use App\Shared\Controller\BaseController;
|
||||
use App\Shared\Exception\AppException;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
@@ -20,6 +22,7 @@ class ClinicInvitationController extends BaseController
|
||||
private readonly ClinicInvitationService $invitationService,
|
||||
private readonly ClinicDoctorInvitationRepository $invRepo,
|
||||
private readonly ClinicRepository $clinicRepo,
|
||||
private readonly DoctorRepository $doctorRepo,
|
||||
) {}
|
||||
|
||||
// ── Admin endpoints ──────────────────────────────────────────────────────
|
||||
@@ -130,6 +133,63 @@ class ClinicInvitationController extends BaseController
|
||||
return $this->success(null, 204);
|
||||
}
|
||||
|
||||
// ── Doctor-facing endpoints ──────────────────────────────────────────────
|
||||
|
||||
#[Route('/api/v1/doctor/invitations', methods: ['GET'])]
|
||||
#[IsGranted('ROLE_DOCTOR')]
|
||||
public function myInvitations(#[CurrentUser] User $user): JsonResponse
|
||||
{
|
||||
$doctor = $this->doctorRepo->findByUser($user);
|
||||
if (!$doctor) {
|
||||
throw new AppException('ERR_NOT_FOUND_001', 'پروفایل پزشک یافت نشد', 404);
|
||||
}
|
||||
|
||||
$invitations = $this->invRepo->findPendingByDoctor($doctor);
|
||||
|
||||
$data = array_map(function (ClinicDoctorInvitation $inv): array {
|
||||
$clinic = $inv->getClinic();
|
||||
$arr = $inv->toArray();
|
||||
$arr['clinic'] = [
|
||||
'uuid' => $clinic->getUuid(),
|
||||
'name' => $clinic->getName(),
|
||||
'logo' => $clinic->getClinicLogo(),
|
||||
];
|
||||
return $arr;
|
||||
}, $invitations);
|
||||
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
#[Route('/api/v1/doctor/invitation/{invUuid}/respond', methods: ['POST'])]
|
||||
#[IsGranted('ROLE_DOCTOR')]
|
||||
public function respondToInvitation(string $invUuid, Request $request, #[CurrentUser] User $user): JsonResponse
|
||||
{
|
||||
$doctor = $this->doctorRepo->findByUser($user);
|
||||
if (!$doctor) {
|
||||
throw new AppException('ERR_NOT_FOUND_001', 'پروفایل پزشک یافت نشد', 404);
|
||||
}
|
||||
|
||||
$inv = $this->invRepo->findOneBy(['uuid' => $invUuid]);
|
||||
if (!$inv || $inv->getDoctor()?->getId() !== $doctor->getId()) {
|
||||
throw new AppException('ERR_NOT_FOUND_001', 'دعوتنامه یافت نشد', 404);
|
||||
}
|
||||
|
||||
$body = json_decode($request->getContent(), true) ?? [];
|
||||
$action = $body['action'] ?? '';
|
||||
|
||||
if ($action === 'accept') {
|
||||
$this->invitationService->accept($inv);
|
||||
return $this->success(['message' => 'دعوتنامه پذیرفته شد']);
|
||||
}
|
||||
|
||||
if ($action === 'reject') {
|
||||
$this->invitationService->reject($inv);
|
||||
return $this->success(['message' => 'دعوتنامه رد شد']);
|
||||
}
|
||||
|
||||
throw new AppException('ERR_VALIDATION_001', 'action باید accept یا reject باشد', 422);
|
||||
}
|
||||
|
||||
private function assertClinicAccess(\App\Clinic\Entity\Clinic $clinic, User $user): void
|
||||
{
|
||||
if ($user->hasRole('ROLE_ADMIN')) {
|
||||
|
||||
Reference in New Issue
Block a user