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:
@@ -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' => 'بیمه با موفقیت حذف شد']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user