Skip to content

Commit

Permalink
Expose local subscriber count to the API (#1251)
Browse files Browse the repository at this point in the history
Co-authored-by: Melroy van den Berg <[email protected]>
  • Loading branch information
BentiGorlich and melroy89 authored Nov 26, 2024
1 parent a32baf2 commit 6284d59
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/DTO/MagazineDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class MagazineDto
public bool $isPostingRestrictedToMods = false;
public ?bool $isUserSubscribed = null;
public ?bool $isBlockedByUser = null;
public ?int $localSubscribers = null;
public ?array $tags = null;
public ?Collection $badges = null;
public ?Collection $moderators = null;
Expand Down
4 changes: 4 additions & 0 deletions src/DTO/MagazineResponseDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class MagazineResponseDto implements \JsonSerializable
public ?string $serverSoftware = null;
public ?string $serverSoftwareVersion = null;
public bool $isPostingRestrictedToMods = false;
public ?int $localSubscribers = null;

public static function create(
?ModeratorResponseDto $owner = null,
Expand All @@ -61,6 +62,7 @@ public static function create(
?string $serverSoftware = null,
?string $serverSoftwareVersion = null,
bool $isPostingRestrictedToMods = false,
?int $localSubscribers = null,
): self {
$dto = new MagazineResponseDto();
$dto->owner = $owner;
Expand All @@ -86,6 +88,7 @@ public static function create(
$dto->serverSoftware = $serverSoftware;
$dto->serverSoftwareVersion = $serverSoftwareVersion;
$dto->isPostingRestrictedToMods = $isPostingRestrictedToMods;
$dto->localSubscribers = $localSubscribers;

return $dto;
}
Expand Down Expand Up @@ -116,6 +119,7 @@ public function jsonSerialize(): mixed
'serverSoftware' => $this->serverSoftware,
'serverSoftwareVersion' => $this->serverSoftwareVersion,
'isPostingRestrictedToMods' => $this->isPostingRestrictedToMods,
'localSubscribers' => $this->localSubscribers,
];
}
}
6 changes: 6 additions & 0 deletions src/Factory/MagazineFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use App\Entity\User;
use App\Repository\InstanceRepository;
use App\Repository\MagazineRepository;
use App\Repository\MagazineSubscriptionRepository;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

Expand All @@ -31,6 +32,7 @@ public function __construct(
private ModeratorFactory $moderatorFactory,
private UserFactory $userFactory,
private MagazineRepository $magazineRepository,
private MagazineSubscriptionRepository $magazineSubscriptionRepository,
private Security $security,
) {
}
Expand Down Expand Up @@ -79,6 +81,9 @@ public function createDto(Magazine $magazine): MagazineDto
$dto->isUserSubscribed = $this->security->isGranted('ROLE_OAUTH2_MAGAZINE:SUBSCRIBE') ? $magazine->isSubscribed($currentUser) : null;
$dto->isBlockedByUser = $this->security->isGranted('ROLE_OAUTH2_MAGAZINE:BLOCK') ? $currentUser->isBlockedMagazine($magazine) : null;

$subs = $this->magazineSubscriptionRepository->findMagazineSubscribers(1, $magazine)->count();
$dto->localSubscribers = $subs;

$instance = $this->instanceRepository->getInstanceOfMagazine($magazine);
if ($instance) {
$dto->serverSoftware = $instance->software;
Expand Down Expand Up @@ -160,6 +165,7 @@ public function createResponseDto(MagazineDto|Magazine $magazine): MagazineRespo
$dto->serverSoftware,
$dto->serverSoftwareVersion,
$dto->isPostingRestrictedToMods,
$dto->localSubscribers,
);
}

Expand Down

0 comments on commit 6284d59

Please sign in to comment.