Defined config and implementation to delete short URLs

This commit is contained in:
Alejandro Celaya
2018-09-15 11:01:23 +02:00
parent 07165f344f
commit 394d9ff4d2
9 changed files with 103 additions and 22 deletions

View File

@@ -27,13 +27,11 @@ class ShortUrlService implements ShortUrlServiceInterface
}
/**
* @param int $page
* @param string $searchQuery
* @param array $tags
* @param null $orderBy
* @param string[] $tags
* @param array|string|null $orderBy
* @return ShortUrl[]|Paginator
*/
public function listShortUrls($page = 1, $searchQuery = null, array $tags = [], $orderBy = null)
public function listShortUrls(int $page = 1, string $searchQuery = null, array $tags = [], $orderBy = null)
{
/** @var ShortUrlRepository $repo */
$repo = $this->em->getRepository(ShortUrl::class);
@@ -45,9 +43,7 @@ class ShortUrlService implements ShortUrlServiceInterface
}
/**
* @param string $shortCode
* @param string[] $tags
* @return ShortUrl
* @throws InvalidShortCodeException
*/
public function setTagsByShortCode(string $shortCode, array $tags = []): ShortUrl
@@ -60,9 +56,6 @@ class ShortUrlService implements ShortUrlServiceInterface
}
/**
* @param string $shortCode
* @param ShortUrlMeta $shortCodeMeta
* @return ShortUrl
* @throws InvalidShortCodeException
*/
public function updateMetadataByShortCode(string $shortCode, ShortUrlMeta $shortCodeMeta): ShortUrl
@@ -81,9 +74,19 @@ class ShortUrlService implements ShortUrlServiceInterface
/** @var ORM\EntityManager $em */
$em = $this->em;
$em->flush($shortUrl);
return $shortUrl;
}
/**
* @throws InvalidShortCodeException
*/
public function deleteByShortCode(string $shortCode): void
{
$this->em->remove($this->findByShortCode($shortCode));
$this->em->flush();
}
/**
* @param string $shortCode
* @return ShortUrl

View File

@@ -11,27 +11,25 @@ use Zend\Paginator\Paginator;
interface ShortUrlServiceInterface
{
/**
* @param int $page
* @param string $searchQuery
* @param array $tags
* @param null $orderBy
* @param string[] $tags
* @param array|string|null $orderBy
* @return ShortUrl[]|Paginator
*/
public function listShortUrls($page = 1, $searchQuery = null, array $tags = [], $orderBy = null);
public function listShortUrls(int $page = 1, string $searchQuery = null, array $tags = [], $orderBy = null);
/**
* @param string $shortCode
* @param string[] $tags
* @return ShortUrl
* @throws InvalidShortCodeException
*/
public function setTagsByShortCode(string $shortCode, array $tags = []): ShortUrl;
/**
* @param string $shortCode
* @param ShortUrlMeta $shortCodeMeta
* @return ShortUrl
* @throws InvalidShortCodeException
*/
public function updateMetadataByShortCode(string $shortCode, ShortUrlMeta $shortCodeMeta): ShortUrl;
/**
* @throws InvalidShortCodeException
*/
public function deleteByShortCode(string $shortCode): void;
}