mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Create DeleteShortUrlVisitsCommand
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user