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,123 @@
<?php
namespace App\Category\Controller;
use App\Category\Entity\Category;
use App\Category\Repository\CategoryRepository;
use App\Category\Service\CategoryService;
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\IsGranted;
class CategoryController extends BaseController
{
public function __construct(
private readonly CategoryRepository $repository,
private readonly CategoryService $service,
) {}
#[Route('/api/v1/categorys/tag', methods: ['GET'])]
public function listTags(): JsonResponse
{
return $this->success(['data' => $this->service->listByBundle('tag')]);
}
#[Route('/api/v1/categorys/supplementary_insurance', methods: ['GET'])]
public function listSupplementaryInsurance(): JsonResponse
{
return $this->success(['data' => $this->service->listByBundle('supplementary_insurance')]);
}
#[Route('/api/v1/categorys/insurance_type', methods: ['GET'])]
public function listInsuranceType(): JsonResponse
{
return $this->success(['data' => $this->service->listByBundle('insurance_type')]);
}
#[Route('/api/v1/categorys/state', methods: ['GET'])]
public function listStates(): JsonResponse
{
return $this->success(['data' => $this->service->listByBundle('state')]);
}
#[Route('/api/v1/categorys/city', methods: ['GET'])]
public function listCities(Request $request): JsonResponse
{
$stateId = $request->query->get('state_id');
$parentId = $stateId !== null ? (int) $stateId : null;
return $this->success(['data' => $this->service->listByBundle('city', $parentId)]);
}
#[Route('/api/v1/categorys/specially_doctor', methods: ['GET'])]
public function listSpecialties(): JsonResponse
{
return $this->success(['data' => $this->service->listByBundle('specially_doctor')]);
}
#[Route('/api/v1/categorys/doctor_services', methods: ['GET'])]
public function listDoctorServices(): JsonResponse
{
return $this->success(['data' => $this->service->listByBundle('doctor_services')]);
}
#[Route('/api/v1/category', methods: ['POST'])]
#[IsGranted('ROLE_ADMIN')]
public function create(Request $request): JsonResponse
{
$data = json_decode($request->getContent(), true) ?? [];
$bundle = trim($data['bundle'] ?? '');
$label = trim($data['label'] ?? '');
if (!in_array($bundle, Category::BUNDLES, true)) {
return $this->error(ErrorCodes::ERR_VALIDATION_001, 'bundle نامعتبر است', 422, 'bundle');
}
if ($label === '') {
return $this->error(ErrorCodes::ERR_VALIDATION_001, 'label الزامی است', 422, 'label');
}
$category = $this->service->create($bundle, $label, $data);
return $this->success(['data' => $category->toArray()], 201);
}
#[Route('/api/v1/category/{id}', methods: ['PATCH'])]
#[IsGranted('ROLE_ADMIN')]
public function update(int $id, Request $request): JsonResponse
{
$category = $this->repository->find($id);
if ($category === null) {
return $this->error(ErrorCodes::ERR_VALIDATION_002, 'دسته‌بندی یافت نشد', 404);
}
$data = json_decode($request->getContent(), true) ?? [];
if (isset($data['bundle']) && !in_array($data['bundle'], Category::BUNDLES, true)) {
return $this->error(ErrorCodes::ERR_VALIDATION_001, 'bundle نامعتبر است', 422, 'bundle');
}
$category = $this->service->update($category, $data);
return $this->success(['data' => $category->toArray()]);
}
#[Route('/api/v1/category/{id}', methods: ['DELETE'])]
#[IsGranted('ROLE_ADMIN')]
public function delete(int $id): JsonResponse
{
$category = $this->repository->find($id);
if ($category === null) {
return $this->error(ErrorCodes::ERR_VALIDATION_002, 'دسته‌بندی یافت نشد', 404);
}
$this->service->delete($category);
return $this->success(['message' => 'دسته‌بندی با موفقیت حذف شد']);
}
}
+155
View File
@@ -0,0 +1,155 @@
<?php
namespace App\Category\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Uid\Uuid;
#[ORM\Entity]
#[ORM\Table(name: 'categories')]
#[ORM\Index(columns: ['bundle'], name: 'idx_categories_bundle')]
#[ORM\Index(columns: ['parent_id'], name: 'idx_categories_parent')]
#[ORM\Index(columns: ['status', 'bundle'], name: 'idx_categories_status')]
class Category
{
public const BUNDLES = [
'state', 'city', 'specially_doctor', 'doctor_services',
'insurance_type', 'supplementary_insurance', 'tag',
];
#[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: 32)]
private string $bundle;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $label = null;
#[ORM\Column(type: 'smallint')]
private int $status = 1;
#[ORM\Column(name: 'parent_id', type: 'integer', nullable: true)]
private ?int $parentId = null;
#[ORM\Column(type: 'integer')]
private int $weight = 0;
#[ORM\Column(name: 'logo_id', type: 'integer', nullable: true)]
private ?int $logoId = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $title = null;
#[ORM\Column(name: 'representation_id', type: 'integer', nullable: true)]
private ?int $representationId = null;
// City-specific fields
#[ORM\Column(name: 'contact_phone', type: 'string', length: 255, nullable: true)]
private ?string $contactPhone = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $email = null;
#[ORM\Column(type: 'text', nullable: true)]
private ?string $description = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $slogan = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $domain = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $keywords = null;
#[ORM\Column(name: 'footer_description', type: 'text', nullable: true)]
private ?string $footerDescription = null;
#[ORM\Column(name: 'footer_disclaimer', type: 'text', nullable: true)]
private ?string $footerDisclaimer = null;
#[ORM\Column(name: 'social_media', type: 'json', nullable: true)]
private ?array $socialMedia = null;
public function __construct(string $bundle, string $label)
{
$this->uuid = Uuid::v4()->toRfc4122();
$this->bundle = $bundle;
$this->label = $label;
}
public function getId(): ?int { return $this->id; }
public function getUuid(): string { return $this->uuid; }
public function getBundle(): string { return $this->bundle; }
public function getLabel(): ?string { return $this->label; }
public function getStatus(): int { return $this->status; }
public function getParentId(): ?int { return $this->parentId; }
public function getWeight(): int { return $this->weight; }
public function getLogoId(): ?int { return $this->logoId; }
public function getTitle(): ?string { return $this->title; }
public function getRepresentationId(): ?int { return $this->representationId; }
public function getContactPhone(): ?string { return $this->contactPhone; }
public function getEmail(): ?string { return $this->email; }
public function getDescription(): ?string { return $this->description; }
public function getSlogan(): ?string { return $this->slogan; }
public function getDomain(): ?string { return $this->domain; }
public function getKeywords(): ?string { return $this->keywords; }
public function getFooterDescription(): ?string { return $this->footerDescription; }
public function getFooterDisclaimer(): ?string { return $this->footerDisclaimer; }
public function getSocialMedia(): ?array { return $this->socialMedia; }
public function setBundle(string $bundle): self { $this->bundle = $bundle; return $this; }
public function setLabel(?string $label): self { $this->label = $label; return $this; }
public function setStatus(int $status): self { $this->status = $status; return $this; }
public function setParentId(?int $id): self { $this->parentId = $id; return $this; }
public function setWeight(int $weight): self { $this->weight = $weight; return $this; }
public function setLogoId(?int $id): self { $this->logoId = $id; return $this; }
public function setTitle(?string $title): self { $this->title = $title; return $this; }
public function setRepresentationId(?int $id): self { $this->representationId = $id; return $this; }
public function setContactPhone(?string $v): self { $this->contactPhone = $v; return $this; }
public function setEmail(?string $v): self { $this->email = $v; return $this; }
public function setDescription(?string $v): self { $this->description = $v; return $this; }
public function setSlogan(?string $v): self { $this->slogan = $v; return $this; }
public function setDomain(?string $v): self { $this->domain = $v; return $this; }
public function setKeywords(?string $v): self { $this->keywords = $v; return $this; }
public function setFooterDescription(?string $v): self { $this->footerDescription = $v; return $this; }
public function setFooterDisclaimer(?string $v): self { $this->footerDisclaimer = $v; return $this; }
public function setSocialMedia(?array $v): self { $this->socialMedia = $v; return $this; }
public function toArray(): array
{
$data = [
'id' => $this->id,
'uuid' => $this->uuid,
'bundle' => $this->bundle,
'label' => $this->label,
'status' => $this->status,
'weight' => $this->weight,
];
if ($this->parentId !== null) {
$data['parent_id'] = $this->parentId;
}
if ($this->title !== null) {
$data['title'] = $this->title;
}
if ($this->bundle === 'city') {
$data['contact_phone'] = $this->contactPhone;
$data['email'] = $this->email;
$data['description'] = $this->description;
$data['slogan'] = $this->slogan;
$data['domain'] = $this->domain;
$data['keywords'] = $this->keywords;
$data['footer_description'] = $this->footerDescription;
$data['social_media'] = $this->socialMedia;
}
return $data;
}
}
@@ -0,0 +1,48 @@
<?php
namespace App\Category\Repository;
use App\Category\Entity\Category;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
class CategoryRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Category::class);
}
/** @return Category[] */
public function findByBundle(string $bundle, ?int $parentId = null): array
{
$qb = $this->createQueryBuilder('c')
->where('c.bundle = :bundle')
->andWhere('c.status = 1')
->setParameter('bundle', $bundle)
->orderBy('c.weight', 'ASC')
->addOrderBy('c.label', 'ASC');
if ($parentId !== null) {
$qb->andWhere('c.parentId = :parentId')->setParameter('parentId', $parentId);
}
return $qb->getQuery()->getResult();
}
public function save(Category $category, bool $flush = true): void
{
$this->getEntityManager()->persist($category);
if ($flush) {
$this->getEntityManager()->flush();
}
}
public function remove(Category $category, bool $flush = true): void
{
$this->getEntityManager()->remove($category);
if ($flush) {
$this->getEntityManager()->flush();
}
}
}
+97
View File
@@ -0,0 +1,97 @@
<?php
namespace App\Category\Service;
use App\Category\Entity\Category;
use App\Category\Repository\CategoryRepository;
use Psr\Cache\CacheItemPoolInterface;
class CategoryService
{
private const TTL = 3600;
public function __construct(
private readonly CategoryRepository $repository,
private readonly CacheItemPoolInterface $cache,
) {}
/** @return array[] */
public function listByBundle(string $bundle, ?int $parentId = null): array
{
$cacheKey = 'cat_' . $bundle . ($parentId !== null ? '_p' . $parentId : '');
$item = $this->cache->getItem($cacheKey);
if ($item->isHit()) {
return $item->get();
}
$rows = array_map(fn(Category $c) => $c->toArray(), $this->repository->findByBundle($bundle, $parentId));
$item->set($rows)->expiresAfter(self::TTL);
$this->cache->save($item);
return $rows;
}
public function create(string $bundle, string $label, array $extra = []): Category
{
$category = new Category($bundle, $label);
$this->applyExtra($category, $extra);
$this->repository->save($category);
$this->invalidate($bundle);
return $category;
}
public function update(Category $category, array $data): Category
{
$bundle = $data['bundle'] ?? $category->getBundle();
if (isset($data['label'])) $category->setLabel($data['label']);
if (isset($data['status'])) $category->setStatus((int) $data['status']);
if (isset($data['weight'])) $category->setWeight((int) $data['weight']);
if (isset($data['title'])) $category->setTitle($data['title']);
if (isset($data['bundle'])) $category->setBundle($data['bundle']);
if (array_key_exists('parent_id', $data)) $category->setParentId($data['parent_id']);
$this->applyExtra($category, $data);
$this->repository->save($category);
$this->invalidate($bundle);
$this->invalidate($category->getBundle());
return $category;
}
public function delete(Category $category): void
{
$bundle = $category->getBundle();
$this->repository->remove($category);
$this->invalidate($bundle);
}
private function applyExtra(Category $category, array $data): void
{
if (array_key_exists('parent_id', $data)) $category->setParentId($data['parent_id']);
if (array_key_exists('weight', $data)) $category->setWeight((int) $data['weight']);
if (array_key_exists('logo_id', $data)) $category->setLogoId($data['logo_id']);
if (array_key_exists('title', $data)) $category->setTitle($data['title']);
if (array_key_exists('contact_phone', $data)) $category->setContactPhone($data['contact_phone']);
if (array_key_exists('email', $data)) $category->setEmail($data['email']);
if (array_key_exists('description', $data)) $category->setDescription($data['description']);
if (array_key_exists('slogan', $data)) $category->setSlogan($data['slogan']);
if (array_key_exists('domain', $data)) $category->setDomain($data['domain']);
if (array_key_exists('keywords', $data)) $category->setKeywords($data['keywords']);
if (array_key_exists('footer_description', $data)) $category->setFooterDescription($data['footer_description']);
if (array_key_exists('footer_disclaimer', $data)) $category->setFooterDisclaimer($data['footer_disclaimer']);
if (array_key_exists('social_media', $data)) $category->setSocialMedia($data['social_media']);
}
private function invalidate(string $bundle): void
{
$this->cache->deleteItem('cat_' . $bundle);
// Also delete any parent-filtered variants
foreach (range(1, 50) as $id) {
$this->cache->deleteItem('cat_' . $bundle . '_p' . $id);
}
}
}