Syncer for user absence, from the msgraph reader

This commit is contained in:
2023-07-06 17:29:10 +02:00
parent 5b42b85b50
commit 2861945a52
5 changed files with 136 additions and 3 deletions

View File

@@ -21,7 +21,7 @@ use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
readonly class MSUserAbsenceReader
final readonly class MSUserAbsenceReader implements MSUserAbsenceReaderInterface
{
public function __construct(
private HttpClientInterface $machineHttpClient,

View File

@@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\CalendarBundle\RemoteCalendar\Connector\MSGraph;
use Chill\MainBundle\Entity\User;
interface MSUserAbsenceReaderInterface
{
/**
* @throw UserAbsenceSyncException when the data cannot be reached or is not valid from microsoft
*/
public function isUserAbsent(User $user): bool|null;
}

View File

@@ -0,0 +1,44 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\CalendarBundle\RemoteCalendar\Connector\MSGraph;
use Chill\MainBundle\Entity\User;
use Symfony\Component\Clock\ClockInterface;
readonly class MSUserAbsenceSync
{
public function __construct(
private MSUserAbsenceReaderInterface $absenceReader,
private ClockInterface $clock,
) {
}
public function syncUserAbsence(User $user): void
{
$absence = $this->absenceReader->isUserAbsent($user);
if (null === $absence) {
return;
}
if ($absence === $user->isAbsent()) {
// nothing to do
return;
}
if ($absence) {
$user->setAbsenceStart($this->clock->now());
} else {
$user->setAbsenceStart(null);
}
}
}