feat: add insurance and location management

- Introduced InsuranceType enum for insurance categorization.
- Created InsuranceRepository for managing insurance entities.
- Developed LocationController for handling provinces and cities, including CRUD operations.
- Implemented City and Province entities with necessary fields and relationships.
- Added CityRepository and ProvinceRepository for database interactions.
- Established Specialty management with SpecialtyController, including CRUD operations.
- Created Specialty and Tag entities with appropriate fields and relationships.
- Implemented TagController for managing tags, including CRUD operations.
- Added TagRepository for database interactions with tags.
This commit is contained in:
hamed
2026-06-10 14:22:26 +03:30
parent 4b8504df91
commit 5066fcbd91
36 changed files with 2937 additions and 1241 deletions
@@ -0,0 +1,132 @@
<?php
namespace App\DoctorService\Controller;
use App\DoctorService\Entity\DoctorService;
use App\DoctorService\Repository\DoctorServiceRepository;
use App\Shared\Constant\ErrorCodes;
use App\Shared\Controller\BaseController;
use App\Specialty\Repository\SpecialtyRepository;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
class DoctorServiceController extends BaseController
{
public function __construct(
private readonly DoctorServiceRepository $repo,
private readonly SpecialtyRepository $specialtyRepo,
) {}
#[Route('/api/v1/doctor-services', methods: ['GET'])]
public function list(Request $request): JsonResponse
{
$specialtyId = $request->query->get('specialty_id');
$items = array_map(
fn(DoctorService $ds) => $ds->toArray(),
$this->repo->findActive($specialtyId !== null ? (int) $specialtyId : null)
);
return $this->success(['data' => $items]);
}
// ── Admin CRUD ────────────────────────────────────────────────────────────
#[Route('/api/v1/admin/doctor-service', methods: ['POST'])]
#[IsGranted('ROLE_ADMIN')]
public function create(Request $request): JsonResponse
{
$data = json_decode($request->getContent(), true) ?? [];
$name = trim($data['name'] ?? '');
if ($name === '') {
return $this->error(ErrorCodes::ERR_VALIDATION_001, 'name الزامی است', 422, 'name');
}
$slug = $data['slug'] ?? $this->slugify($name);
$specialty = null;
if (!empty($data['specialty_id'])) {
$specialty = $this->specialtyRepo->find((int) $data['specialty_id']);
}
$service = new DoctorService($name, $slug, $specialty);
if (isset($data['status'])) $service->setStatus((int) $data['status']);
if (isset($data['weight'])) $service->setWeight((int) $data['weight']);
$this->repo->save($service);
return $this->success(['data' => $service->toArray()], 201);
}
#[Route('/api/v1/admin/doctor-service/{id}', methods: ['PATCH'])]
#[IsGranted('ROLE_ADMIN')]
public function update(int $id, Request $request): JsonResponse
{
$service = $this->repo->find($id);
if ($service === null) {
return $this->error(ErrorCodes::ERR_VALIDATION_002, 'خدمت یافت نشد', 404);
}
$data = json_decode($request->getContent(), true) ?? [];
if (isset($data['name'])) $service->setName($data['name']);
if (isset($data['slug'])) $service->setSlug($data['slug']);
if (isset($data['status'])) $service->setStatus((int) $data['status']);
if (isset($data['weight'])) $service->setWeight((int) $data['weight']);
if (array_key_exists('specialty_id', $data)) {
$specialty = $data['specialty_id'] ? $this->specialtyRepo->find((int) $data['specialty_id']) : null;
$service->setSpecialty($specialty);
}
$this->repo->save($service);
return $this->success(['data' => $service->toArray()]);
}
#[Route('/api/v1/admin/doctor-service/{id}', methods: ['DELETE'])]
#[IsGranted('ROLE_ADMIN')]
public function delete(int $id): JsonResponse
{
$service = $this->repo->find($id);
if ($service === null) {
return $this->error(ErrorCodes::ERR_VALIDATION_002, 'خدمت یافت نشد', 404);
}
$this->repo->remove($service);
return $this->success(['message' => 'خدمت با موفقیت حذف شد']);
}
#[Route('/api/v1/admin/doctor-services', methods: ['GET'])]
#[IsGranted('ROLE_ADMIN')]
public function adminList(Request $request): JsonResponse
{
$page = max(1, (int) $request->query->get('page', 1));
$limit = min(100, max(1, (int) $request->query->get('limit', 15)));
$search = trim((string) $request->query->get('search', ''));
$specialtyId = $request->query->get('specialty_id');
$qb = $this->repo->createQueryBuilder('ds')
->orderBy('ds.weight', 'ASC')
->addOrderBy('ds.name', 'ASC');
if ($search !== '') {
$qb->andWhere('ds.name LIKE :s')->setParameter('s', '%' . $search . '%');
}
if ($specialtyId !== null && $specialtyId !== '') {
$qb->andWhere('ds.specialty = :sp')->setParameter('sp', (int) $specialtyId);
}
$total = (clone $qb)->select('COUNT(ds.id)')->getQuery()->getSingleScalarResult();
$rows = $qb->setFirstResult(($page - 1) * $limit)->setMaxResults($limit)->getQuery()->getResult();
return $this->paginated(
array_map(fn(DoctorService $ds) => $ds->toArray(), $rows),
(int) $total, $page, $limit
);
}
private function slugify(string $text): string
{
$text = mb_strtolower(trim($text));
$text = preg_replace('/\s+/', '-', $text);
$text = preg_replace('/[^\p{L}\p{N}\-]/u', '', $text);
return $text ?: 'service-' . time();
}
}
@@ -0,0 +1,75 @@
<?php
namespace App\DoctorService\Entity;
use App\DoctorService\Repository\DoctorServiceRepository;
use App\Specialty\Entity\Specialty;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Uid\Uuid;
#[ORM\Entity(repositoryClass: DoctorServiceRepository::class)]
#[ORM\Table(name: 'doctor_services')]
#[ORM\UniqueConstraint(name: 'uq_doctor_services_slug', columns: ['slug'])]
#[ORM\Index(columns: ['status'], name: 'idx_doctor_services_status')]
#[ORM\Index(columns: ['specialty_id'], name: 'idx_doctor_services_specialty')]
class DoctorService
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private ?int $id = null;
#[ORM\Column(type: 'string', length: 36, unique: true)]
private string $uuid;
#[ORM\Column(type: 'string', length: 255)]
private string $name;
#[ORM\Column(type: 'string', length: 255, unique: true)]
private string $slug;
#[ORM\Column(type: 'smallint')]
private int $status = 1;
#[ORM\Column(type: 'integer')]
private int $weight = 0;
#[ORM\ManyToOne(targetEntity: Specialty::class)]
#[ORM\JoinColumn(name: 'specialty_id', referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
private ?Specialty $specialty = null;
public function __construct(string $name, string $slug, ?Specialty $specialty = null)
{
$this->uuid = Uuid::v4()->toRfc4122();
$this->name = $name;
$this->slug = $slug;
$this->specialty = $specialty;
}
public function getId(): ?int { return $this->id; }
public function getUuid(): string { return $this->uuid; }
public function getName(): string { return $this->name; }
public function getSlug(): string { return $this->slug; }
public function getStatus(): int { return $this->status; }
public function getWeight(): int { return $this->weight; }
public function getSpecialty(): ?Specialty { return $this->specialty; }
public function setName(string $v): self { $this->name = $v; return $this; }
public function setSlug(string $v): self { $this->slug = $v; return $this; }
public function setStatus(int $v): self { $this->status = $v; return $this; }
public function setWeight(int $v): self { $this->weight = $v; return $this; }
public function setSpecialty(?Specialty $v): self { $this->specialty = $v; return $this; }
public function toArray(): array
{
return [
'id' => $this->id,
'uuid' => $this->uuid,
'name' => $this->name,
'slug' => $this->slug,
'status' => $this->status,
'weight' => $this->weight,
'specialty_id' => $this->specialty?->getId(),
];
}
}
@@ -0,0 +1,42 @@
<?php
namespace App\DoctorService\Repository;
use App\DoctorService\Entity\DoctorService;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
class DoctorServiceRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, DoctorService::class);
}
/** @return DoctorService[] */
public function findActive(?int $specialtyId = null): array
{
$qb = $this->createQueryBuilder('ds')
->where('ds.status = 1')
->orderBy('ds.weight', 'ASC')
->addOrderBy('ds.name', 'ASC');
if ($specialtyId !== null) {
$qb->andWhere('ds.specialty = :specialty')->setParameter('specialty', $specialtyId);
}
return $qb->getQuery()->getResult();
}
public function save(DoctorService $service, bool $flush = true): void
{
$this->getEntityManager()->persist($service);
if ($flush) $this->getEntityManager()->flush();
}
public function remove(DoctorService $service, bool $flush = true): void
{
$this->getEntityManager()->remove($service);
if ($flush) $this->getEntityManager()->flush();
}
}