Create DeleteShortUrlVisitsCommand

This commit is contained in:
Alejandro Celaya
2023-05-15 09:43:05 +02:00
parent 6bb8c1b2f5
commit 02a8ef7dd9
34 changed files with 163 additions and 99 deletions

View File

@@ -8,6 +8,8 @@ use Psr\Http\Message\ServerRequestInterface;
use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl;
use Symfony\Component\Console\Input\InputInterface;
use function sprintf;
final class ShortUrlIdentifier
{
private function __construct(public readonly string $shortCode, public readonly ?string $domain = null)
@@ -54,4 +56,13 @@ final class ShortUrlIdentifier
{
return new self($shortCode, $domain);
}
public function __toString(): string
{
if ($this->domain === null) {
return $this->shortCode;
}
return sprintf('%s/%s', $this->domain, $this->shortCode);
}
}

View File

@@ -21,7 +21,7 @@ class ShortUrlVisitsDeleter implements ShortUrlVisitsDeleterInterface
/**
* @throws ShortUrlNotFoundException
*/
public function deleteShortUrlVisits(ShortUrlIdentifier $identifier, ?ApiKey $apiKey): BulkDeleteResult
public function deleteShortUrlVisits(ShortUrlIdentifier $identifier, ?ApiKey $apiKey = null): BulkDeleteResult
{
$shortUrl = $this->resolver->resolveShortUrl($identifier, $apiKey);
return new BulkDeleteResult($this->repository->deleteShortUrlVisits($shortUrl));

View File

@@ -14,5 +14,5 @@ interface ShortUrlVisitsDeleterInterface
/**
* @throws ShortUrlNotFoundException
*/
public function deleteShortUrlVisits(ShortUrlIdentifier $identifier, ?ApiKey $apiKey): BulkDeleteResult;
public function deleteShortUrlVisits(ShortUrlIdentifier $identifier, ?ApiKey $apiKey = null): BulkDeleteResult;
}

View File

@@ -52,7 +52,6 @@ class VisitDeleterRepositoryTest extends DatabaseTestCase
$this->getEntityManager()->flush();
self::assertEquals(0, $this->repo->deleteShortUrlVisits(ShortUrl::withLongUrl('https://invalid')->setId('99')));
self::assertEquals(2, $this->repo->deleteShortUrlVisits($shortUrl1));
self::assertEquals(0, $this->repo->deleteShortUrlVisits($shortUrl1));
self::assertEquals(4, $this->repo->deleteShortUrlVisits($shortUrl2));