-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enregistre une date de dernière activité de l'utilisateur (#998)
* Enregistre une date de dernière activité de l'utilisateur * Renomme
- Loading branch information
1 parent
2c68845
commit 88e8aef
Showing
9 changed files
with
125 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Application\User\Command; | ||
|
||
use App\Application\CommandInterface; | ||
use App\Domain\User\User; | ||
|
||
final class MarkUserAsActiveCommand implements CommandInterface | ||
{ | ||
public function __construct( | ||
public readonly User $user, | ||
) { | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/Application/User/Command/MarkUserAsActiveCommandHandler.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Application\User\Command; | ||
|
||
use App\Application\DateUtilsInterface; | ||
|
||
final class MarkUserAsActiveCommandHandler | ||
{ | ||
public function __construct( | ||
private DateUtilsInterface $dateUtils, | ||
) { | ||
} | ||
|
||
public function __invoke(MarkUserAsActiveCommand $command): void | ||
{ | ||
$command->user | ||
->setLastActiveAt($this->dateUtils->getNow()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/Infrastructure/Persistence/Doctrine/Migrations/Version20241008120435.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Infrastructure\Persistence\Doctrine\Migrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
final class Version20241008120435 extends AbstractMigration | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return 'Add user.last_active_at'; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
$this->addSql('ALTER TABLE "user" ADD last_active_at TIMESTAMP(0) WITH TIME ZONE DEFAULT NULL'); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
$this->addSql('ALTER TABLE "user" DROP last_active_at'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
tests/Unit/Application/User/Command/MarkUserActiveCommandHandlerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Tests\Unit\Application\User\Command; | ||
|
||
use App\Application\DateUtilsInterface; | ||
use App\Application\User\Command\MarkUserAsActiveCommand; | ||
use App\Application\User\Command\MarkUserAsActiveCommandHandler; | ||
use App\Domain\User\User; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class MarkUserActiveCommandHandlerTest extends TestCase | ||
{ | ||
public function testHandler(): void | ||
{ | ||
$user = $this->createMock(User::class); | ||
$dateUtils = $this->createMock(DateUtilsInterface::class); | ||
|
||
$now = new \DateTimeImmutable('2024-10-01'); | ||
|
||
$dateUtils | ||
->expects(self::once()) | ||
->method('getNow') | ||
->willReturn($now); | ||
|
||
$command = new MarkUserAsActiveCommand($user); | ||
$handler = new MarkUserAsActiveCommandHandler($dateUtils); | ||
$handler($command); | ||
} | ||
} |