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
@@ -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]);