mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Create REST action to delete short URL visits
This commit is contained in:
17
module/Core/src/Model/BulkDeleteResult.php
Normal file
17
module/Core/src/Model/BulkDeleteResult.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\Core\Model;
|
||||
|
||||
final class BulkDeleteResult
|
||||
{
|
||||
public function __construct(public readonly int $affectedItems)
|
||||
{
|
||||
}
|
||||
|
||||
public function toArray(string $fieldName): array
|
||||
{
|
||||
return [$fieldName => $this->affectedItems];
|
||||
}
|
||||
}
|
||||
25
module/Core/src/ShortUrl/ShortUrlVisitsDeleter.php
Normal file
25
module/Core/src/ShortUrl/ShortUrlVisitsDeleter.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\Core\ShortUrl;
|
||||
|
||||
use Shlinkio\Shlink\Core\Model\BulkDeleteResult;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlIdentifier;
|
||||
use Shlinkio\Shlink\Core\Visit\Repository\VisitDeleterRepositoryInterface;
|
||||
use Shlinkio\Shlink\Rest\Entity\ApiKey;
|
||||
|
||||
class ShortUrlVisitsDeleter implements ShortUrlVisitsDeleterInterface
|
||||
{
|
||||
public function __construct(
|
||||
private readonly VisitDeleterRepositoryInterface $repository,
|
||||
private readonly ShortUrlResolverInterface $resolver,
|
||||
) {
|
||||
}
|
||||
|
||||
public function deleteShortUrlVisits(ShortUrlIdentifier $identifier, ?ApiKey $apiKey): BulkDeleteResult
|
||||
{
|
||||
$this->resolver->resolveShortUrl($identifier, $apiKey);
|
||||
return new BulkDeleteResult($this->repository->deleteShortUrlVisits($identifier, $apiKey));
|
||||
}
|
||||
}
|
||||
14
module/Core/src/ShortUrl/ShortUrlVisitsDeleterInterface.php
Normal file
14
module/Core/src/ShortUrl/ShortUrlVisitsDeleterInterface.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\Core\ShortUrl;
|
||||
|
||||
use Shlinkio\Shlink\Core\Model\BulkDeleteResult;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlIdentifier;
|
||||
use Shlinkio\Shlink\Rest\Entity\ApiKey;
|
||||
|
||||
interface ShortUrlVisitsDeleterInterface
|
||||
{
|
||||
public function deleteShortUrlVisits(ShortUrlIdentifier $identifier, ?ApiKey $apiKey): BulkDeleteResult;
|
||||
}
|
||||
18
module/Core/src/Visit/Repository/VisitDeleterRepository.php
Normal file
18
module/Core/src/Visit/Repository/VisitDeleterRepository.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\Core\Visit\Repository;
|
||||
|
||||
use Happyr\DoctrineSpecification\Repository\EntitySpecificationRepository;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlIdentifier;
|
||||
use Shlinkio\Shlink\Rest\Entity\ApiKey;
|
||||
|
||||
class VisitDeleterRepository extends EntitySpecificationRepository implements VisitDeleterRepositoryInterface
|
||||
{
|
||||
public function deleteShortUrlVisits(ShortUrlIdentifier $identifier, ?ApiKey $apiKey): int
|
||||
{
|
||||
// TODO: Implement deleteShortUrlVisits() method.
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\Core\Visit\Repository;
|
||||
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlIdentifier;
|
||||
use Shlinkio\Shlink\Rest\Entity\ApiKey;
|
||||
|
||||
interface VisitDeleterRepositoryInterface
|
||||
{
|
||||
public function deleteShortUrlVisits(ShortUrlIdentifier $identifier, ?ApiKey $apiKey): int;
|
||||
}
|
||||
Reference in New Issue
Block a user