Skip to content

Commit 3c7f331

Browse files
committed
Adds get ownership urls count to url repository
1 parent 9b6f9f5 commit 3c7f331

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/Repositories/UrlRepository.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,25 @@ public static function findOwnershipUrls(string $owner_type, int $owner_id): Col
5050
}
5151
}
5252

53+
/**
54+
* @throws UrlRepositoryException
55+
*/
56+
public static function getOwnershipUrlsCount(string $owner_type, int $owner_id): int
57+
{
58+
try {
59+
return ShortUrl::whereIn('id', function ($query) use ($owner_type, $owner_id) {
60+
$query->from('short_url_ownerships');
61+
$query->where([
62+
'ownerable_type' => $owner_type,
63+
'ownerable_id' => $owner_id,
64+
]);
65+
$query->select('short_url_id');
66+
})->count();
67+
} catch (Exception $exception) {
68+
throw new UrlRepositoryException($exception->getMessage());
69+
}
70+
}
71+
5372
/**
5473
* @return mixed
5574
*

src/Services/UrlService.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,12 @@ public static function getAllByOwner(string $ownerable_type, string $ownerable_i
9797
{
9898
return UrlRepository::findOwnershipUrls($ownerable_type, $ownerable_id);
9999
}
100+
101+
/**
102+
* @throws UrlRepositoryException
103+
*/
104+
public static function getAllByOwnerCount(string $ownerable_type, string $ownerable_id): int
105+
{
106+
return UrlRepository::getOwnershipUrlsCount($ownerable_type,$ownerable_id);
107+
}
100108
}

0 commit comments

Comments
 (0)