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
+188
View File
@@ -0,0 +1,188 @@
<?php
namespace App\Rating\Controller;
use App\Auth\Entity\User;
use App\Doctor\Repository\DoctorRepository;
use App\Rating\Entity\Comment;
use App\Rating\Entity\Like;
use App\Rating\Entity\Rate;
use App\Rating\Repository\CommentRepository;
use App\Rating\Repository\LikeRepository;
use App\Rating\Repository\RateRepository;
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;
class RatingController extends BaseController
{
public function __construct(
private readonly RateRepository $rateRepo,
private readonly CommentRepository $commentRepo,
private readonly LikeRepository $likeRepo,
private readonly DoctorRepository $doctorRepo,
) {}
// ── Ratings ───────────────────────────────────────────────────────────────
#[IsGranted('IS_AUTHENTICATED_FULLY')]
#[Route('/api/v1/rate', methods: ['POST'])]
public function rate(Request $request, #[CurrentUser] User $user): JsonResponse
{
$data = json_decode($request->getContent(), true) ?? [];
$doctorUuid = trim($data['doctor_uuid'] ?? '');
$score = (int) ($data['score'] ?? 0);
if ($score < 1 || $score > 5) {
return $this->error(ErrorCodes::ERR_VALIDATION_001, 'امتیاز باید بین ۱ تا ۵ باشد', 422);
}
$doctor = $this->doctorRepo->findByUuid($doctorUuid);
if ($doctor === null) {
return $this->error(ErrorCodes::ERR_NOT_FOUND_001, 'دکتر یافت نشد', 404);
}
$existing = $this->rateRepo->findByUserAndDoctor($user, $doctor);
if ($existing !== null) {
$existing->setScore($score);
$this->rateRepo->save($existing);
return $this->success(['data' => $existing->toArray()]);
}
$rate = new Rate($user, $doctor, $score);
$this->rateRepo->save($rate);
return $this->success(['data' => $rate->toArray()], 201);
}
#[Route('/api/v1/rate/{doctorUuid}', methods: ['GET'])]
public function getAverage(string $doctorUuid): JsonResponse
{
$doctor = $this->doctorRepo->findByUuid($doctorUuid);
if ($doctor === null) {
return $this->error(ErrorCodes::ERR_NOT_FOUND_001, 'دکتر یافت نشد', 404);
}
return $this->success(['average' => $this->rateRepo->getAverageScore($doctor)]);
}
// ── Comments ──────────────────────────────────────────────────────────────
#[IsGranted('IS_AUTHENTICATED_FULLY')]
#[Route('/api/v1/comment', methods: ['POST'])]
public function createComment(Request $request, #[CurrentUser] User $user): JsonResponse
{
$data = json_decode($request->getContent(), true) ?? [];
$doctorUuid = trim($data['doctor_uuid'] ?? '');
$body = trim($data['body'] ?? '');
if (empty($body)) {
return $this->error(ErrorCodes::ERR_VALIDATION_002, 'متن نظر الزامی است', 422);
}
$doctor = $this->doctorRepo->findByUuid($doctorUuid);
if ($doctor === null) {
return $this->error(ErrorCodes::ERR_NOT_FOUND_001, 'دکتر یافت نشد', 404);
}
$comment = new Comment($user, $doctor, $body);
$this->commentRepo->save($comment);
return $this->success(['data' => $comment->toArray()], 201);
}
#[Route('/api/v1/comments/{doctorUuid}', methods: ['GET'])]
public function listComments(string $doctorUuid): JsonResponse
{
$doctor = $this->doctorRepo->findByUuid($doctorUuid);
if ($doctor === null) {
return $this->error(ErrorCodes::ERR_NOT_FOUND_001, 'دکتر یافت نشد', 404);
}
$comments = array_map(
fn(Comment $c) => $c->toArray(),
$this->commentRepo->findApprovedByDoctor($doctor)
);
return $this->success(['data' => $comments]);
}
#[IsGranted('IS_AUTHENTICATED_FULLY')]
#[Route('/api/v1/comment/{uuid}', methods: ['DELETE'])]
public function deleteComment(string $uuid, #[CurrentUser] User $user): JsonResponse
{
$comment = $this->commentRepo->findByUuid($uuid);
if ($comment === null) {
return $this->error(ErrorCodes::ERR_NOT_FOUND_001, 'نظر یافت نشد', 404);
}
if ($comment->getUser()->getId() !== $user->getId() && !$user->hasRole('ROLE_ADMIN')) {
return $this->error(ErrorCodes::ERR_AUTH_006, 'دسترسی ممنوع', 403);
}
$this->commentRepo->remove($comment);
return $this->success(['message' => 'نظر با موفقیت حذف شد']);
}
// ── Admin: comment moderation ─────────────────────────────────────────────
#[IsGranted('ROLE_ADMIN')]
#[Route('/api/v1/admin/comments/pending', methods: ['GET'])]
public function pendingComments(): JsonResponse
{
$comments = array_map(fn(Comment $c) => $c->toArray(), $this->commentRepo->findPending());
return $this->success(['data' => $comments]);
}
#[IsGranted('ROLE_ADMIN')]
#[Route('/api/v1/admin/comment/{uuid}/approve', methods: ['POST'])]
public function approveComment(string $uuid): JsonResponse
{
$comment = $this->commentRepo->findByUuid($uuid);
if ($comment === null) {
return $this->error(ErrorCodes::ERR_NOT_FOUND_001, 'نظر یافت نشد', 404);
}
$comment->approve();
$this->commentRepo->save($comment);
return $this->success(['data' => $comment->toArray()]);
}
#[IsGranted('ROLE_ADMIN')]
#[Route('/api/v1/admin/comment/{uuid}/reject', methods: ['POST'])]
public function rejectComment(string $uuid): JsonResponse
{
$comment = $this->commentRepo->findByUuid($uuid);
if ($comment === null) {
return $this->error(ErrorCodes::ERR_NOT_FOUND_001, 'نظر یافت نشد', 404);
}
$comment->reject();
$this->commentRepo->save($comment);
return $this->success(['data' => $comment->toArray()]);
}
// ── Likes (toggle) ────────────────────────────────────────────────────────
#[IsGranted('IS_AUTHENTICATED_FULLY')]
#[Route('/api/v1/like/{commentUuid}', methods: ['POST'])]
public function toggleLike(string $commentUuid, #[CurrentUser] User $user): JsonResponse
{
$comment = $this->commentRepo->findByUuid($commentUuid);
if ($comment === null) {
return $this->error(ErrorCodes::ERR_NOT_FOUND_001, 'نظر یافت نشد', 404);
}
$existing = $this->likeRepo->findByUserAndComment($user, $comment);
if ($existing !== null) {
$this->likeRepo->remove($existing);
return $this->success(['liked' => false, 'likes' => $comment->getLikes()->count() - 1]);
}
$like = new Like($user, $comment);
$this->likeRepo->save($like);
return $this->success(['liked' => true, 'likes' => $comment->getLikes()->count()], 201);
}
}