feat(payment): add GET /api/v1/my/payments for the logged-in user

Add PaymentRepository::findByUser/countByUser and a paginated
my/payments endpoint that returns the authenticated user's own payments
(derived from the token, never a userId in the URL). Public dashboard's
transactions tab can now list payments instead of hitting a nonexistent
route.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
hamed
2026-06-15 19:21:31 +03:30
co-authored by Claude Opus 4.8
parent 5d204d7460
commit 038cb73ea7
3 changed files with 180 additions and 0 deletions
@@ -518,6 +518,23 @@ class PaymentController extends BaseController
]);
}
#[IsGranted('IS_AUTHENTICATED_FULLY')]
#[Route('/api/v1/my/payments', methods: ['GET'])]
public function myPayments(Request $request, #[CurrentUser] User $user): JsonResponse
{
$page = max(1, (int) $request->query->get('page', 1));
$limit = min(100, max(1, (int) $request->query->get('limit', 20)));
$status = $request->query->get('status');
$items = array_map(
fn(Payment $p) => $p->toArray(),
$this->paymentRepo->findByUser($user, $status, $page, $limit)
);
$total = $this->paymentRepo->countByUser($user, $status);
return $this->paginated($items, $total, $page, $limit);
}
#[IsGranted('IS_AUTHENTICATED_FULLY')]
#[Route('/api/v1/payment/{uuid}', methods: ['GET'])]
public function getStatus(string $uuid, #[CurrentUser] User $user): JsonResponse
@@ -2,6 +2,7 @@
namespace App\Payment\Repository;
use App\Auth\Entity\User;
use App\Payment\Entity\Payment;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
@@ -18,6 +19,35 @@ class PaymentRepository extends ServiceEntityRepository
return $this->findOneBy(['uuid' => $uuid]);
}
/** @return Payment[] */
public function findByUser(User $user, ?string $status = null, int $page = 1, int $limit = 20): array
{
$qb = $this->createQueryBuilder('p')
->where('p.user = :user')->setParameter('user', $user)
->orderBy('p.createdAt', 'DESC')
->setFirstResult(($page - 1) * $limit)
->setMaxResults($limit);
if ($status !== null) {
$qb->andWhere('p.status = :status')->setParameter('status', $status);
}
return $qb->getQuery()->getResult();
}
public function countByUser(User $user, ?string $status = null): int
{
$qb = $this->createQueryBuilder('p')
->select('COUNT(p.id)')
->where('p.user = :user')->setParameter('user', $user);
if ($status !== null) {
$qb->andWhere('p.status = :status')->setParameter('status', $status);
}
return (int) $qb->getQuery()->getSingleScalarResult();
}
public function findByOrderId(string $orderId): ?Payment
{
return $this->findOneBy(['orderId' => $orderId]);