Skip to content

Commit

Permalink
Adds get ownership urls count to url repository
Browse files Browse the repository at this point in the history
  • Loading branch information
yordadev committed Aug 29, 2024
1 parent 9b6f9f5 commit 3c7f331
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/Repositories/UrlRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,25 @@ public static function findOwnershipUrls(string $owner_type, int $owner_id): Col
}
}

/**
* @throws UrlRepositoryException
*/
public static function getOwnershipUrlsCount(string $owner_type, int $owner_id): int
{
try {
return ShortUrl::whereIn('id', function ($query) use ($owner_type, $owner_id) {
$query->from('short_url_ownerships');
$query->where([
'ownerable_type' => $owner_type,
'ownerable_id' => $owner_id,
]);
$query->select('short_url_id');
})->count();
} catch (Exception $exception) {
throw new UrlRepositoryException($exception->getMessage());
}
}

/**
* @return mixed
*
Expand Down
8 changes: 8 additions & 0 deletions src/Services/UrlService.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,12 @@ public static function getAllByOwner(string $ownerable_type, string $ownerable_i
{
return UrlRepository::findOwnershipUrls($ownerable_type, $ownerable_id);
}

/**
* @throws UrlRepositoryException
*/
public static function getAllByOwnerCount(string $ownerable_type, string $ownerable_id): int
{
return UrlRepository::getOwnershipUrlsCount($ownerable_type,$ownerable_id);
}
}

0 comments on commit 3c7f331

Please sign in to comment.