Skip to content

Commit a05022f

Browse files
committed
feat: publish media file type lifecycle events to sponsor services
Signed-off-by: romanetar <roman_ag@hotmail.com>
1 parent 2404a30 commit a05022f

4 files changed

Lines changed: 102 additions & 3 deletions

File tree

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php namespace App\Events\SponsorServices;
2+
3+
/*
4+
* Copyright 2026 OpenStack Foundation
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
**/
15+
16+
class SummitMediaFileTypeCreatedEventDTO
17+
{
18+
private int $id;
19+
private string $name;
20+
private string $description;
21+
private string $allowed_extensions;
22+
23+
public function __construct(
24+
int $id,
25+
string $name,
26+
string $description,
27+
string $allowed_extensions
28+
)
29+
{
30+
$this->id = $id;
31+
$this->name = $name;
32+
$this->description = $description;
33+
$this->allowed_extensions = $allowed_extensions;
34+
}
35+
36+
public static function fromSummitMediaFileType($summit_media_file_type): self
37+
{
38+
return new self(
39+
$summit_media_file_type->getId(),
40+
$summit_media_file_type->getName(),
41+
$summit_media_file_type->getDescription(),
42+
$summit_media_file_type->getAllowedExtensions(),
43+
);
44+
}
45+
46+
public function serialize(): array
47+
{
48+
return [
49+
'id' => $this->id,
50+
'name' => $this->name,
51+
'description' => $this->description,
52+
'allowed_extensions' => $this->allowed_extensions
53+
];
54+
}
55+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php namespace App\Events\SponsorServices;
2+
3+
/*
4+
* Copyright 2026 OpenStack Foundation
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
**/
15+
16+
class SummitMediaFileTypeDomainEvents
17+
{
18+
const string SummitMediaFileTypeCreated = 'summit_media_file_type_created';
19+
const string SummitMediaFileTypeUpdated = 'summit_media_file_type_updated';
20+
const string SummitMediaFileTypeDeleted = 'summit_media_file_type_deleted';
21+
}

app/Services/Model/Imp/SummitMediaFileTypeService.php

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
* limitations under the License.
1313
**/
1414

15+
use App\Events\SponsorServices\DeletedEventDTO;
16+
use App\Events\SponsorServices\SummitMediaFileTypeCreatedEventDTO;
17+
use App\Events\SponsorServices\SummitMediaFileTypeDomainEvents;
18+
use App\Jobs\SponsorServices\PublishSponsorServiceDomainEventsJob;
1519
use App\Models\Foundation\Summit\Factories\SummitMediaFileTypeFactory;
1620
use App\Models\Foundation\Summit\Repositories\ISummitMediaFileTypeRepository;
1721
use App\Services\Model\ISummitMediaFileTypeService;
@@ -49,14 +53,20 @@ public function __construct
4953
*/
5054
public function add(array $payload): SummitMediaFileType
5155
{
52-
return $this->tx_service->transaction(function() use($payload){
56+
$media_file_type = $this->tx_service->transaction(function() use($payload){
5357
$type = $this->repository->getByName(trim($payload['name']));
5458
if(!is_null($type))
5559
throw new ValidationException(sprintf("Name %s already exists.", $payload['name']));
5660
$type = SummitMediaFileTypeFactory::build($payload);
5761
$this->repository->add($type);
5862
return $type;
5963
});
64+
65+
PublishSponsorServiceDomainEventsJob::dispatch(
66+
SummitMediaFileTypeCreatedEventDTO::fromSummitMediaFileType($media_file_type)->serialize(),
67+
SummitMediaFileTypeDomainEvents::SummitMediaFileTypeCreated);
68+
69+
return $media_file_type;
6070
}
6171

6272
/**
@@ -77,7 +87,13 @@ public function update(int $id, array $payload): SummitMediaFileType
7787
throw new ValidationException(sprintf("Name %s already exists.", $payload['name']));
7888
}
7989

80-
return SummitMediaFileTypeFactory::populate($type, $payload);
90+
$media_file_type = SummitMediaFileTypeFactory::populate($type, $payload);
91+
92+
PublishSponsorServiceDomainEventsJob::dispatch(
93+
SummitMediaFileTypeCreatedEventDTO::fromSummitMediaFileType($media_file_type)->serialize(),
94+
SummitMediaFileTypeDomainEvents::SummitMediaFileTypeUpdated);
95+
96+
return $media_file_type;
8197
});
8298
}
8399

@@ -94,6 +110,10 @@ public function delete(int $id): void
94110
throw new ValidationException("You can not delete a system defined type.");
95111

96112
$this->repository->delete($type);
113+
114+
PublishSponsorServiceDomainEventsJob::dispatch(
115+
DeletedEventDTO::fromEntity($type)->serialize(),
116+
SummitMediaFileTypeDomainEvents::SummitMediaFileTypeDeleted);
97117
});
98118
}
99-
}
119+
}

config/queue.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@
184184
* - summit_created ( see app/Events/SponsorServices/SummitDomainEvents.php )
185185
* - summit_updated
186186
* - summit_deleted
187+
* - summit_media_file_type_created ( see app/Events/SponsorServices/SummitMediaFileTypeDomainEvents.php )
188+
* - summit_media_file_type_updated
189+
* - summit_media_file_type_deleted
187190
*/
188191
'domain_events_message_broker' => [
189192
'driver' => 'rabbitmq',

0 commit comments

Comments
 (0)