Files
lucent-laravel/src/Account/AccountService.php
T

60 lines
1.1 KiB
PHP
Raw Normal View History

2023-10-02 23:10:49 +03:00
<?php
namespace Lucent\Account;
2023-10-17 22:57:25 +03:00
use Lucent\Channel\ChannelService;
2023-10-02 23:10:49 +03:00
use Lucent\Primitive\Collection;
readonly class AccountService
{
public function __construct(
2023-10-17 22:57:25 +03:00
private AuthService $authService,
private ChannelService $channelService,
private UserRepo $userRepo,
2023-10-02 23:10:49 +03:00
)
{
}
/**
* @return Collection<User>
*/
public function all(): Collection
{
return $this->userRepo->all();
}
2023-10-04 13:32:30 +03:00
public function countUsers(): int
{
return $this->userRepo->count();
}
2023-10-02 23:10:49 +03:00
/**
* @return Collection<UserProfile>
*/
public function allProfiles(): Collection
{
return $this->all()->map(fn($user) => $user->safe());
}
2023-10-17 22:57:25 +03:00
/**
* @return array<string>
*/
public function currentReadableSchemas(): array
{
$roles = $this->authService->currentUserRoles();
return $this->channelService->schemasReadableByRoles($roles);
}
public function currentWritableSchemas(): array
{
$roles = $this->authService->currentUserRoles();
return $this->channelService->schemasWritableByRoles($roles);
}
2023-10-02 23:10:49 +03:00
}