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
+268
View File
@@ -0,0 +1,268 @@
<?php
namespace App\Clinic\Controller;
use App\Auth\Entity\User;
use App\Auth\Repository\UserRepository;
use App\Category\Repository\CategoryRepository;
use App\Clinic\Entity\Clinic;
use App\Clinic\Repository\ClinicRepository;
use App\Doctor\Entity\Doctor;
use App\Doctor\Repository\DoctorRepository;
use App\Shared\Constant\ErrorCodes;
use App\Shared\Controller\BaseController;
use App\Shared\Service\FileValidatorService;
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;
use Symfony\Component\Uid\Uuid;
class ClinicController extends BaseController
{
public function __construct(
private readonly ClinicRepository $clinicRepo,
private readonly DoctorRepository $doctorRepo,
private readonly CategoryRepository $categoryRepo,
private readonly UserRepository $userRepo,
private readonly FileValidatorService $fileValidator,
private readonly string $projectDir,
) {}
#[Route('/api/v1/clinic', methods: ['POST'])]
#[IsGranted('IS_AUTHENTICATED_FULLY')]
public function create(Request $request, #[CurrentUser] User $user): JsonResponse
{
$data = json_decode($request->getContent(), true) ?? [];
$clinic = new Clinic($user);
$this->hydrateClinic($clinic, $data);
$this->clinicRepo->save($clinic);
// Grant ROLE_CLINIC to user
$roles = $user->getRoles();
if (!in_array('ROLE_CLINIC', $roles, true)) {
$roles[] = 'ROLE_CLINIC';
$user->setRoles(array_values(array_unique($roles)));
$this->userRepo->save($user);
}
return $this->success(['data' => $clinic->toDetailArray()], 201);
}
#[Route('/api/v1/clinic/{uuid}', methods: ['GET'])]
public function show(string $uuid): JsonResponse
{
$clinic = $this->clinicRepo->findByUuid($uuid);
if ($clinic === null) {
return $this->error(ErrorCodes::ERR_VALIDATION_002, 'کلینیک یافت نشد', 404);
}
[$stateData, $cityData] = $this->loadLocationData($clinic);
return $this->success(['data' => $clinic->toDetailArray($stateData, $cityData)]);
}
#[Route('/api/v1/clinic/{uuid}', methods: ['PATCH'])]
#[IsGranted('IS_AUTHENTICATED_FULLY')]
public function update(string $uuid, Request $request, #[CurrentUser] User $user): JsonResponse
{
$clinic = $this->clinicRepo->findByUuid($uuid);
if ($clinic === null) {
return $this->error(ErrorCodes::ERR_VALIDATION_002, 'کلینیک یافت نشد', 404);
}
if ($clinic->getUser()->getId() !== $user->getId() && !$user->hasRole('ROLE_ADMIN')) {
return $this->error(ErrorCodes::ERR_AUTH_006, 'دسترسی ممنوع', 403);
}
$data = json_decode($request->getContent(), true) ?? [];
$this->hydrateClinic($clinic, $data);
$this->clinicRepo->save($clinic);
[$stateData, $cityData] = $this->loadLocationData($clinic);
return $this->success(['data' => $clinic->toDetailArray($stateData, $cityData)]);
}
#[Route('/api/v1/clinics', methods: ['GET'])]
public function list(Request $request): JsonResponse
{
$filters = $request->query->all();
$result = $this->clinicRepo->findWithFilters($filters);
return $this->paginated(
array_map(fn(Clinic $c) => $c->toListArray(), $result['items']),
$result['total'],
$result['page'],
$result['limit']
);
}
#[Route('/api/v1/clinic/doctor-list/{clinicUuid}', methods: ['GET'])]
public function doctorList(string $clinicUuid): JsonResponse
{
$clinic = $this->clinicRepo->findByUuid($clinicUuid);
if ($clinic === null) {
return $this->error(ErrorCodes::ERR_VALIDATION_002, 'کلینیک یافت نشد', 404);
}
$doctors = array_map(
fn(Doctor $d) => $d->toListArray(),
$clinic->getDoctors()->toArray()
);
return $this->success(['data' => $doctors]);
}
#[Route('/file/upload/clinic_pro/clinic/field_image_clinic', methods: ['POST'])]
#[IsGranted('IS_AUTHENTICATED_FULLY')]
public function uploadImage(Request $request): JsonResponse
{
return $this->handleFileUpload($request, 'clinics/gallery');
}
#[Route('/file/upload/clinic_pro/clinic/field_clinic_logo', methods: ['POST'])]
#[IsGranted('IS_AUTHENTICATED_FULLY')]
public function uploadLogo(Request $request): JsonResponse
{
return $this->handleFileUpload($request, 'clinics/logo');
}
// ── Helpers ───────────────────────────────────────────────────────────────
private function hydrateClinic(Clinic $clinic, array $data): void
{
if (array_key_exists('name', $data)) $clinic->setName($data['name']);
if (array_key_exists('info', $data)) $clinic->setInfo($data['info']);
if (array_key_exists('address', $data)) $clinic->setAddress($data['address']);
if (array_key_exists('telephone', $data)) $clinic->setTelephone($data['telephone']);
if (array_key_exists('working_days', $data)) $clinic->setWorkingDays($data['working_days']);
if (array_key_exists('24_7', $data)) $clinic->setIs247((bool) $data['24_7']);
if (array_key_exists('latitude', $data)) $clinic->setLatitude((float) $data['latitude']);
if (array_key_exists('longitude', $data)) $clinic->setLongitude((float) $data['longitude']);
// Location
if (!empty($data['state']) && is_array($data['state'])) {
$clinic->setStateId((int) $data['state'][0]);
}
if (!empty($data['city']) && is_array($data['city'])) {
$clinic->setCityId((int) $data['city'][0]);
}
// Images stored as JSON (from upload response)
if (array_key_exists('image_clinic', $data) && is_array($data['image_clinic'])) {
$clinic->setImagesClinic($data['image_clinic']);
}
if (array_key_exists('clinic_logo', $data) && is_array($data['clinic_logo'])) {
$clinic->setClinicLogo($data['clinic_logo']);
}
// ManyToMany: doctors
if (array_key_exists('doctors', $data) && is_array($data['doctors'])) {
$clinic->getDoctors()->clear();
foreach ($data['doctors'] as $doctorId) {
$doctor = $this->doctorRepo->find((int) $doctorId);
if ($doctor !== null) {
$clinic->getDoctors()->add($doctor);
}
}
}
// ManyToMany: specialties
if (array_key_exists('specialties', $data) && is_array($data['specialties'])) {
$clinic->getSpecialties()->clear();
foreach ($data['specialties'] as $catId) {
$cat = $this->categoryRepo->find((int) $catId);
if ($cat !== null) {
$clinic->getSpecialties()->add($cat);
}
}
}
// ManyToMany: services (doctor_services)
if (array_key_exists('doctor_services', $data) && is_array($data['doctor_services'])) {
$clinic->getServices()->clear();
foreach ($data['doctor_services'] as $catId) {
$cat = $this->categoryRepo->find((int) $catId);
if ($cat !== null) {
$clinic->getServices()->add($cat);
}
}
}
// ManyToMany: insurances
if (array_key_exists('insurance', $data) && is_array($data['insurance'])) {
$clinic->getInsurances()->clear();
foreach ($data['insurance'] as $catId) {
$cat = $this->categoryRepo->find((int) $catId);
if ($cat !== null) {
$clinic->getInsurances()->add($cat);
}
}
}
}
private function loadLocationData(Clinic $clinic): array
{
$stateData = [];
$cityData = [];
if ($clinic->getStateId() !== null) {
$state = $this->categoryRepo->find($clinic->getStateId());
if ($state !== null) {
$stateData = ['uuid' => $state->getUuid(), 'id' => (string) $state->getId(), 'name' => $state->getLabel()];
}
}
if ($clinic->getCityId() !== null) {
$city = $this->categoryRepo->find($clinic->getCityId());
if ($city !== null) {
$cityData = [
'uuid' => $city->getUuid(),
'id' => (string) $city->getId(),
'name' => $city->getLabel(),
'parent' => $city->getParentId() !== null ? (string) $city->getParentId() : null,
];
}
}
return [$stateData, $cityData];
}
private function handleFileUpload(Request $request, string $subDir): JsonResponse
{
$content = $request->getContent();
$disposition = $request->headers->get('Content-Disposition', '');
preg_match('/filename=["\']?([^"\';\s]+)["\']?/i', $disposition, $m);
$filename = $m[1] ?? 'upload.jpg';
$tmpPath = sys_get_temp_dir() . '/' . uniqid('upload_', true);
file_put_contents($tmpPath, $content);
try {
$safeFilename = $this->fileValidator->sanitizeFilename($filename);
$mime = $this->fileValidator->detectMimeType($tmpPath);
$year = date('Y'); $month = date('m');
$dir = $this->projectDir . '/public/uploads/' . $subDir . '/' . $year . '-' . $month;
if (!is_dir($dir)) mkdir($dir, 0755, true);
$storedName = uniqid('', true) . '_' . $safeFilename;
rename($tmpPath, $dir . '/' . $storedName);
$url = '/uploads/' . $subDir . '/' . $year . '-' . $month . '/' . $storedName;
return $this->success([
'fid' => time(),
'uuid' => Uuid::v4()->toRfc4122(),
'url' => $url,
'filename' => $safeFilename,
'filemime' => $mime,
'filesize' => strlen($content),
]);
} catch (\Throwable $e) {
if (file_exists($tmpPath)) unlink($tmpPath);
return $this->error(ErrorCodes::ERR_VALIDATION_001, $e->getMessage(), 422);
}
}
}