refactor(database): add timestamps to ApiClient and Employee models

Updated ApiClient and Employee models to include created_at and updated_at fields for better tracking of records.
This commit is contained in:
Jérémy Munsch 2026-08-20 12:08:15 +02:00
parent f3b84c725d
commit 9c28cf2903
Signed by: forge-joniko
GPG key ID: D7EFE2F5CB6CC0E4
9 changed files with 42 additions and 35 deletions

View file

@ -15,15 +15,18 @@ final class ApiClientSeeder extends Seeder
{
/** @var array{id: string, name: string, identifier: string, secret: string} $devClient */
$devClient = Config::array('auth.hmac.dev_client');
$now = now();
ApiClient::query()->updateOrCreate(
['identifier' => $devClient['identifier']],
[
'id' => $devClient['id'],
'name' => $devClient['name'],
'slug' => Str::slug($devClient['name']),
'secret' => $devClient['secret'],
'is_active' => true,
'id' => $devClient['id'],
'name' => $devClient['name'],
'slug' => Str::slug($devClient['name']),
'secret' => $devClient['secret'],
'is_active' => true,
'created_at' => $now,
'updated_at' => $now,
]
);

View file

@ -29,6 +29,8 @@ final class ApiClientRepository implements ClientDirectory, ClientRepository
'identifier' => $client->identifier,
'secret' => $client->secret,
'is_active' => $client->isActive,
'created_at' => $client->createdAt,
'updated_at' => $client->updatedAt,
]
);
}

View file

@ -18,9 +18,9 @@ use Infra\Casts\UuidCast;
* @property \Ramsey\Uuid\UuidInterface $id
* @property \Application\Security\Models\ValueObjects\ClientName $name
* @property string $slug
* @property \Application\Security\Models\ValueObjects\ClientIdentifier $identifier
* @property \Application\Security\Models\ValueObjects\ClientSecret $secret
* @property bool $is_active
* @property \Application\Security\Models\ValueObjects\ClientIdentifier $identifier ENCRYPTED, Unique identifier that should not change
* @property \Application\Security\Models\ValueObjects\ClientSecret $secret ENCRYPTED, api secret that can be regenerated
* @property bool $is_active Defines if the client can be used in order to gain access to the system
* @property \Illuminate\Support\Carbon $created_at
* @property \Illuminate\Support\Carbon $updated_at
* @property-read \Illuminate\Notifications\DatabaseNotificationCollection<int, \Illuminate\Notifications\DatabaseNotification> $notifications
@ -44,7 +44,7 @@ final class ApiClient extends Authenticatable
protected $table = 'api_clients';
public $timestamps = true;
public $timestamps = false;
/** @var list<string> */
protected $fillable = [

View file

@ -62,6 +62,8 @@ final class Employee extends Model
'establishment',
'site',
'service',
'created_at',
'updated_at',
];
/** @return array<string, string> */

View file

@ -192,7 +192,7 @@ describe('VerifyHmacSignature Middleware Feature Tests', function (): void {
$identifier = 'arcadia_id_' . str_repeat('a', 32);
$secret = 'arcadia_sec_' . str_repeat('b', 86);
ApiClient::query()->create([
ApiClient::factory()->create([
'id' => Uuid::uuid7()->toString(),
'name' => 'Inactive Client',
'slug' => 'test-' . uniqid(),
@ -228,7 +228,7 @@ describe('VerifyHmacSignature Middleware Feature Tests', function (): void {
$identifier = 'arcadia_id_' . str_repeat('a', 32);
$secret = 'arcadia_sec_' . str_repeat('b', 86);
ApiClient::query()->create([
ApiClient::factory()->create([
'id' => Uuid::uuid7()->toString(),
'name' => 'Active Client',
'slug' => 'test-' . uniqid(),
@ -266,7 +266,7 @@ describe('VerifyHmacSignature Middleware Feature Tests', function (): void {
$identifier = 'arcadia_id_' . str_repeat('a', 32);
$secret = 'arcadia_sec_' . str_repeat('b', 86);
ApiClient::query()->create([
ApiClient::factory()->create([
'id' => Uuid::uuid7()->toString(),
'name' => 'Active Client',
'slug' => 'test-' . uniqid(),
@ -303,7 +303,7 @@ describe('VerifyHmacSignature Middleware Feature Tests', function (): void {
$identifier = 'arcadia_id_' . str_repeat('a', 32);
$secret = 'arcadia_sec_' . str_repeat('b', 86);
ApiClient::query()->create([
ApiClient::factory()->create([
'id' => Uuid::uuid7()->toString(),
'name' => 'Valid API Client',
'slug' => 'test-' . uniqid(),
@ -337,7 +337,7 @@ describe('VerifyHmacSignature Middleware Feature Tests', function (): void {
$identifier = 'arcadia_id_' . str_repeat('a', 32);
$secret = 'arcadia_sec_' . str_repeat('b', 86);
ApiClient::query()->create([
ApiClient::factory()->create([
'id' => Uuid::uuid7()->toString(),
'name' => 'Valid API Client',
'slug' => 'test-' . uniqid(),

View file

@ -28,7 +28,7 @@ describe('ListClientsCommand', function (): void {
/** @var \Tests\TestCase $this */
ApiClient::query()->delete();
$client1 = ApiClient::query()->create([
$client1 = ApiClient::factory()->create([
'id' => (string) Uuid::uuid7(),
'name' => 'Production Gateway',
'slug' => 'test-' . uniqid(),
@ -37,7 +37,7 @@ describe('ListClientsCommand', function (): void {
'is_active' => true,
]);
$client2 = ApiClient::query()->create([
$client2 = ApiClient::factory()->create([
'id' => (string) Uuid::uuid7(),
'name' => 'Backup Gateway',
'slug' => 'test-' . uniqid(),
@ -78,7 +78,7 @@ describe('ListClientsCommand', function (): void {
ApiClient::query()->delete();
for ($i = 1; $i <= 3; $i++) {
ApiClient::query()->create([
ApiClient::factory()->create([
'id' => (string) Uuid::uuid7(),
'name' => "Client {$i}",
'slug' => 'test-' . uniqid(),

View file

@ -42,7 +42,7 @@ describe('RegenerateClientSecretCommand', function (): void {
$identifier = 'arcadia_id_' . str_repeat('a', 32);
$oldSecret = 'arcadia_sec_' . str_repeat('1', 86);
$client = ApiClient::query()->create([
$client = ApiClient::factory()->create([
'id' => (string) Uuid::uuid7(),
'name' => 'Production Gateway',
'slug' => 'production-gateway',
@ -70,7 +70,7 @@ describe('RegenerateClientSecretCommand', function (): void {
$identifier = 'arcadia_id_' . str_repeat('b', 32);
$oldSecret = 'arcadia_sec_' . str_repeat('2', 86);
$client = ApiClient::query()->create([
$client = ApiClient::factory()->create([
'id' => (string) Uuid::uuid7(),
'name' => 'Staging Gateway',
'slug' => 'staging-gateway',
@ -96,7 +96,7 @@ describe('RegenerateClientSecretCommand', function (): void {
$identifier = 'arcadia_id_' . str_repeat('d', 32);
$oldSecret = 'arcadia_sec_' . str_repeat('3', 86);
$client = ApiClient::query()->create([
$client = ApiClient::factory()->create([
'id' => (string) Uuid::uuid7(),
'name' => 'Searchable Client',
'slug' => 'searchable-client',
@ -125,7 +125,7 @@ describe('RegenerateClientSecretCommand', function (): void {
/** @var \Tests\TestCase $this */
ApiClient::query()->delete();
ApiClient::query()->create([
ApiClient::factory()->create([
'id' => (string) Uuid::uuid7(),
'name' => 'Alpha Client',
'slug' => 'alpha-client',
@ -134,7 +134,7 @@ describe('RegenerateClientSecretCommand', function (): void {
'is_active' => true,
]);
ApiClient::query()->create([
ApiClient::factory()->create([
'id' => (string) Uuid::uuid7(),
'name' => 'Beta Client',
'slug' => 'beta-client',

View file

@ -39,7 +39,7 @@ describe('ToggleClientStatusCommand', function (): void {
it('toggles an active client to inactive when no status argument is passed', function (): void {
// GIVEN
/** @var \Tests\TestCase $this */
$client = ApiClient::query()->create([
$client = ApiClient::factory()->create([
'id' => (string) Uuid::uuid7(),
'name' => 'Production Gateway',
'slug' => 'test-' . uniqid(),
@ -61,7 +61,7 @@ describe('ToggleClientStatusCommand', function (): void {
it('toggles an inactive client to active when no status argument is passed', function (): void {
// GIVEN
/** @var \Tests\TestCase $this */
$client = ApiClient::query()->create([
$client = ApiClient::factory()->create([
'id' => (string) Uuid::uuid7(),
'name' => 'Backup Gateway',
'slug' => 'test-' . uniqid(),
@ -83,7 +83,7 @@ describe('ToggleClientStatusCommand', function (): void {
it('activates an inactive client when activate status is passed', function (): void {
// GIVEN
/** @var \Tests\TestCase $this */
$client = ApiClient::query()->create([
$client = ApiClient::factory()->create([
'id' => (string) Uuid::uuid7(),
'name' => 'Special Gateway',
'slug' => 'test-' . uniqid(),
@ -105,7 +105,7 @@ describe('ToggleClientStatusCommand', function (): void {
it('deactivates an active client when deactivate status is passed', function (): void {
// GIVEN
/** @var \Tests\TestCase $this */
$client = ApiClient::query()->create([
$client = ApiClient::factory()->create([
'id' => (string) Uuid::uuid7(),
'name' => 'Special Gateway',
'slug' => 'test-' . uniqid(),
@ -128,7 +128,7 @@ describe('ToggleClientStatusCommand', function (): void {
// GIVEN
/** @var \Tests\TestCase $this */
$identifier = 'arcadia_id_' . str_repeat('z', 32);
ApiClient::query()->create([
ApiClient::factory()->create([
'id' => (string) Uuid::uuid7(),
'name' => 'Some Gateway',
'slug' => 'test-' . uniqid(),
@ -148,7 +148,7 @@ describe('ToggleClientStatusCommand', function (): void {
// GIVEN
/** @var \Tests\TestCase $this */
$identifier = 'arcadia_id_' . str_repeat('k', 32);
$client = ApiClient::query()->create([
$client = ApiClient::factory()->create([
'id' => (string) Uuid::uuid7(),
'name' => 'Interactive Gateway',
'slug' => 'interactive-gateway',
@ -176,7 +176,7 @@ describe('ToggleClientStatusCommand', function (): void {
/** @var \Tests\TestCase $this */
ApiClient::query()->delete();
ApiClient::query()->create([
ApiClient::factory()->create([
'id' => (string) Uuid::uuid7(),
'name' => 'Production Gateway',
'slug' => 'test-' . uniqid(),
@ -185,7 +185,7 @@ describe('ToggleClientStatusCommand', function (): void {
'is_active' => true,
]);
ApiClient::query()->create([
ApiClient::factory()->create([
'id' => (string) Uuid::uuid7(),
'name' => 'Backup Gateway',
'slug' => 'test-' . uniqid(),

View file

@ -64,7 +64,7 @@ describe('ApiClientRepository Integration Tests', function (): void {
$oldSecret = 'arcadia_sec_' . str_repeat('1', 86);
$newSecret = 'arcadia_sec_' . str_repeat('2', 86);
ApiClient::query()->create([
ApiClient::factory()->create([
'id' => $rawId,
'name' => 'Initial Client',
'slug' => 'initial-client',
@ -102,7 +102,7 @@ describe('ApiClientRepository Integration Tests', function (): void {
$identifier = 'arcadia_id_' . str_repeat('a', 32);
$secret = 'arcadia_sec_' . str_repeat('b', 86);
ApiClient::query()->create([
ApiClient::factory()->create([
'id' => $rawId,
'name' => 'Existing Client',
'slug' => 'existing-client',
@ -130,7 +130,7 @@ describe('ApiClientRepository Integration Tests', function (): void {
$identifier = 'arcadia_id_' . str_repeat('a', 32);
$secret = 'arcadia_sec_' . str_repeat('b', 86);
ApiClient::query()->create([
ApiClient::factory()->create([
'id' => $rawId,
'name' => 'Searchable Client',
'slug' => 'searchable-client',
@ -158,7 +158,7 @@ describe('ApiClientRepository Integration Tests', function (): void {
$identifier = 'arcadia_id_' . str_repeat('a', 32);
$secret = 'arcadia_sec_' . str_repeat('b', 86);
ApiClient::query()->create([
ApiClient::factory()->create([
'id' => $rawId,
'name' => 'Client to Delete',
'slug' => 'client-to-delete',
@ -209,7 +209,7 @@ describe('ApiClientRepository Integration Tests', function (): void {
$repository = new ApiClientRepository();
for ($i = 1; $i <= 5; $i++) {
ApiClient::query()->create([
ApiClient::factory()->create([
'id' => Uuid::uuid7()->toString(),
'name' => "Client $i",
'slug' => "client-$i",