feat: add holiday management endpoints and jalaali-js dependency
- Added a new endpoint to list holidays for a specific doctor. - Added a new endpoint to delete a holiday, with access control for doctors and admins. - Implemented a repository method to retrieve all holidays for a doctor. - Added jalaali-js library to handle date conversions.
This commit is contained in:
@@ -223,6 +223,36 @@ class AppointmentSettingsController extends BaseController
|
||||
|
||||
// ── Holidays ──────────────────────────────────────────────────────────────
|
||||
|
||||
#[Route('/api/v1/appointment-settings/holidays/list/{doctorUuid}', methods: ['GET'])]
|
||||
public function listHolidays(string $doctorUuid): JsonResponse
|
||||
{
|
||||
$doctor = $this->doctorRepo->findByUuid($doctorUuid);
|
||||
if ($doctor === null) {
|
||||
return $this->error(ErrorCodes::ERR_VALIDATION_002, 'دکتر یافت نشد', 404);
|
||||
}
|
||||
|
||||
$items = array_map(fn(Holiday $h) => $h->toArray(), $this->holidayRepo->findAllByDoctor($doctor));
|
||||
|
||||
return $this->success(['data' => $items]);
|
||||
}
|
||||
|
||||
#[Route('/api/v1/appointment-settings/holidays/{uuid}', methods: ['DELETE'])]
|
||||
public function deleteHoliday(string $uuid, #[CurrentUser] User $user): JsonResponse
|
||||
{
|
||||
$holiday = $this->holidayRepo->findByUuid($uuid);
|
||||
if ($holiday === null) {
|
||||
return $this->error(ErrorCodes::ERR_VALIDATION_002, 'تعطیلات یافت نشد', 404);
|
||||
}
|
||||
|
||||
if ($holiday->getDoctor()->getUser()->getId() !== $user->getId() && !$user->hasRole('ROLE_ADMIN')) {
|
||||
return $this->error(ErrorCodes::ERR_AUTH_006, 'دسترسی ممنوع', 403);
|
||||
}
|
||||
|
||||
$this->holidayRepo->remove($holiday);
|
||||
|
||||
return $this->success(['message' => 'تعطیلات حذف شد']);
|
||||
}
|
||||
|
||||
#[Route('/api/v1/appointment-settings/holidays', methods: ['POST'])]
|
||||
public function createHoliday(Request $request, #[CurrentUser] User $user): JsonResponse
|
||||
{
|
||||
|
||||
@@ -19,6 +19,17 @@ class HolidayRepository extends ServiceEntityRepository
|
||||
return $this->findOneBy(['uuid' => $uuid]);
|
||||
}
|
||||
|
||||
/** @return Holiday[] */
|
||||
public function findAllByDoctor(Doctor $doctor): array
|
||||
{
|
||||
return $this->createQueryBuilder('h')
|
||||
->where('h.doctor = :doctor')
|
||||
->setParameter('doctor', $doctor)
|
||||
->orderBy('h.startDate', 'DESC')
|
||||
->getQuery()
|
||||
->getResult();
|
||||
}
|
||||
|
||||
/** @return Holiday[] */
|
||||
public function findActiveByDoctor(Doctor $doctor, int $from, int $to): array
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user