feat: Implement SMS sending functionality with KavehNegar and Rangineh providers

- Add SendSmsMessage class for encapsulating SMS message data.
- Create KavehNegarProvider and RanginehProvider classes implementing SmsProviderInterface for sending SMS.
- Implement SmsLogRepository and SmsTemplateRepository for managing SMS logs and templates.
- Develop SendSmsHandler for handling SMS sending messages.
- Create SmsService to manage SMS dispatching and logging.
- Add UserProfileController for managing user profiles with CRUD operations.
- Implement UserProfile entity and repository for user profile data management.
- Update symfony.lock and bootstrap.php for project dependencies and environment setup.
This commit is contained in:
hamed
2026-06-09 22:00:34 +03:30
commit de1a78a235
222 changed files with 36388 additions and 0 deletions
@@ -0,0 +1,118 @@
<?php
namespace App\Insurance\Controller;
use App\Auth\Entity\User;
use App\Category\Repository\CategoryRepository;
use App\Doctor\Repository\DoctorRepository;
use App\Insurance\Entity\DoctorInsurance;
use App\Insurance\Repository\DoctorInsuranceRepository;
use App\Shared\Constant\ErrorCodes;
use App\Shared\Controller\BaseController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\CurrentUser;
use Symfony\Component\Security\Http\Attribute\IsGranted;
#[IsGranted('IS_AUTHENTICATED_FULLY')]
class InsuranceController extends BaseController
{
public function __construct(
private readonly DoctorInsuranceRepository $repository,
private readonly DoctorRepository $doctorRepo,
private readonly CategoryRepository $categoryRepo,
) {}
#[Route('/api/v1/insurance/', methods: ['POST'])]
public function create(Request $request, #[CurrentUser] User $user): JsonResponse
{
$data = json_decode($request->getContent(), true) ?? [];
$doctorId = $data['doctor_id'] ?? null;
$categoryId = $data['category_id'] ?? null;
if (!$doctorId || !$categoryId) {
return $this->error(ErrorCodes::ERR_VALIDATION_001, 'doctor_id و category_id الزامی است', 422);
}
$doctor = $this->doctorRepo->find((int) $doctorId);
if ($doctor === null) {
return $this->error(ErrorCodes::ERR_VALIDATION_002, 'دکتر یافت نشد', 404);
}
// Only the doctor owner or admin can add insurance
if ($doctor->getUser()->getId() !== $user->getId() && !$user->hasRole('ROLE_ADMIN')) {
return $this->error(ErrorCodes::ERR_AUTH_006, 'دسترسی ممنوع', 403);
}
$category = $this->categoryRepo->find((int) $categoryId);
if ($category === null) {
return $this->error(ErrorCodes::ERR_VALIDATION_002, 'دسته‌بندی بیمه یافت نشد', 404);
}
// Check duplicate
$existing = $this->repository->findOneBy(['doctor' => $doctor, 'category' => $category]);
if ($existing !== null) {
return $this->error(ErrorCodes::ERR_VALIDATION_001, 'این بیمه قبلاً اضافه شده است', 409);
}
$insurance = new DoctorInsurance($doctor, $category);
if (isset($data['price'])) {
$insurance->setPrice((int) $data['price']);
}
$this->repository->save($insurance);
return $this->success(['data' => $insurance->toArray()], 201);
}
#[Route('/api/v1/insurance/{id}', methods: ['GET'])]
public function show(int $id): JsonResponse
{
$insurance = $this->repository->find($id);
if ($insurance === null) {
return $this->error(ErrorCodes::ERR_VALIDATION_002, 'بیمه یافت نشد', 404);
}
return $this->success(['data' => $insurance->toArray()]);
}
#[Route('/api/v1/insurance/{id}', methods: ['PATCH'])]
public function update(int $id, Request $request, #[CurrentUser] User $user): JsonResponse
{
$insurance = $this->repository->find($id);
if ($insurance === null) {
return $this->error(ErrorCodes::ERR_VALIDATION_002, 'بیمه یافت نشد', 404);
}
if ($insurance->getDoctor()->getUser()->getId() !== $user->getId() && !$user->hasRole('ROLE_ADMIN')) {
return $this->error(ErrorCodes::ERR_AUTH_006, 'دسترسی ممنوع', 403);
}
$data = json_decode($request->getContent(), true) ?? [];
if (array_key_exists('price', $data)) {
$insurance->setPrice($data['price'] !== null ? (int) $data['price'] : null);
}
$this->repository->save($insurance);
return $this->success(['data' => $insurance->toArray()]);
}
#[Route('/api/v1/insurance/{id}', methods: ['DELETE'])]
public function delete(int $id, #[CurrentUser] User $user): JsonResponse
{
$insurance = $this->repository->find($id);
if ($insurance === null) {
return $this->error(ErrorCodes::ERR_VALIDATION_002, 'بیمه یافت نشد', 404);
}
if ($insurance->getDoctor()->getUser()->getId() !== $user->getId() && !$user->hasRole('ROLE_ADMIN')) {
return $this->error(ErrorCodes::ERR_AUTH_006, 'دسترسی ممنوع', 403);
}
$this->repository->remove($insurance);
return $this->success(['message' => 'بیمه با موفقیت حذف شد']);
}
}
+55
View File
@@ -0,0 +1,55 @@
<?php
namespace App\Insurance\Entity;
use App\Category\Entity\Category;
use App\Doctor\Entity\Doctor;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity]
#[ORM\Table(name: 'doctor_insurances')]
#[ORM\UniqueConstraint(name: 'idx_doctor_insurance', columns: ['doctor_id', 'category_id'])]
#[ORM\Index(columns: ['category_id'], name: 'idx_doctor_insurance_cat')]
class DoctorInsurance
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private ?int $id = null;
#[ORM\ManyToOne(targetEntity: Doctor::class)]
#[ORM\JoinColumn(name: 'doctor_id', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')]
private Doctor $doctor;
#[ORM\ManyToOne(targetEntity: Category::class)]
#[ORM\JoinColumn(name: 'category_id', referencedColumnName: 'id', nullable: false)]
private Category $category;
#[ORM\Column(type: 'integer', nullable: true)]
private ?int $price = null;
public function __construct(Doctor $doctor, Category $category)
{
$this->doctor = $doctor;
$this->category = $category;
}
public function getId(): ?int { return $this->id; }
public function getDoctor(): Doctor { return $this->doctor; }
public function getCategory(): Category { return $this->category; }
public function getPrice(): ?int { return $this->price; }
public function setPrice(?int $v): self { $this->price = $v; return $this; }
public function toArray(): array
{
return [
'id' => $this->id,
'doctor_id' => $this->doctor->getId(),
'category_id' => $this->category->getId(),
'category_name' => $this->category->getLabel(),
'bundle' => $this->category->getBundle(),
'price' => $this->price,
];
}
}
@@ -0,0 +1,31 @@
<?php
namespace App\Insurance\Repository;
use App\Insurance\Entity\DoctorInsurance;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
class DoctorInsuranceRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, DoctorInsurance::class);
}
public function save(DoctorInsurance $entity, bool $flush = true): void
{
$this->getEntityManager()->persist($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
public function remove(DoctorInsurance $entity, bool $flush = true): void
{
$this->getEntityManager()->remove($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
}