Refactored method in ShortUrlsRepository

This commit is contained in:
Alejandro Celaya
2022-01-17 20:21:35 +01:00
parent 661b07e12f
commit dc430bae10
6 changed files with 31 additions and 20 deletions

View File

@@ -127,7 +127,7 @@ class ShortUrlRepository extends EntitySpecificationRepository implements ShortU
return $qb;
}
public function findOneWithDomainFallback(string $shortCode, ?string $domain = null): ?ShortUrl
public function findOneWithDomainFallback(ShortUrlIdentifier $identifier): ?ShortUrl
{
// When ordering DESC, Postgres puts nulls at the beginning while the rest of supported DB engines put them at
// the bottom
@@ -146,8 +146,8 @@ class ShortUrlRepository extends EntitySpecificationRepository implements ShortU
$query = $this->getEntityManager()->createQuery($dql);
$query->setMaxResults(1)
->setParameters([
'shortCode' => $shortCode,
'domain' => $domain,
'shortCode' => $identifier->shortCode(),
'domain' => $identifier->domain(),
]);
// Since we ordered by domain, we will have first the URL matching provided domain, followed by the one

View File

@@ -20,8 +20,7 @@ interface ShortUrlRepositoryInterface extends ObjectRepository, EntitySpecificat
public function countList(ShortUrlsCountFiltering $filtering): int;
// TODO Use ShortUrlIdentifier here
public function findOneWithDomainFallback(string $shortCode, ?string $domain = null): ?ShortUrl;
public function findOneWithDomainFallback(ShortUrlIdentifier $identifier): ?ShortUrl;
public function findOne(ShortUrlIdentifier $identifier, ?Specification $spec = null): ?ShortUrl;