-
Notifications
You must be signed in to change notification settings - Fork 2
feat: publish media file type lifecycle events to sponsor services #492
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| <?php namespace App\Events\SponsorServices; | ||
|
|
||
| /* | ||
| * Copyright 2026 OpenStack Foundation | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| **/ | ||
|
|
||
| class SummitMediaFileTypeCreatedEventDTO | ||
| { | ||
| private int $id; | ||
| private string $name; | ||
| private string $description; | ||
| private string $allowed_extensions; | ||
|
|
||
| public function __construct( | ||
| int $id, | ||
| string $name, | ||
| string $description, | ||
| string $allowed_extensions | ||
| ) | ||
| { | ||
| $this->id = $id; | ||
| $this->name = $name; | ||
| $this->description = $description; | ||
| $this->allowed_extensions = $allowed_extensions; | ||
| } | ||
|
|
||
| public static function fromSummitMediaFileType($summit_media_file_type): self | ||
| { | ||
| return new self( | ||
| $summit_media_file_type->getId(), | ||
| $summit_media_file_type->getName(), | ||
| $summit_media_file_type->getDescription(), | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| $summit_media_file_type->getAllowedExtensions(), | ||
| ); | ||
| } | ||
|
|
||
| public function serialize(): array | ||
| { | ||
| return [ | ||
| 'id' => $this->id, | ||
| 'name' => $this->name, | ||
| 'description' => $this->description, | ||
| 'allowed_extensions' => $this->allowed_extensions | ||
| ]; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| <?php namespace App\Events\SponsorServices; | ||
|
|
||
| /* | ||
| * Copyright 2026 OpenStack Foundation | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| **/ | ||
|
|
||
| class SummitMediaFileTypeDomainEvents | ||
| { | ||
| const string SummitMediaFileTypeCreated = 'summit_media_file_type_created'; | ||
| const string SummitMediaFileTypeUpdated = 'summit_media_file_type_updated'; | ||
| const string SummitMediaFileTypeDeleted = 'summit_media_file_type_deleted'; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,10 @@ | |
| * limitations under the License. | ||
| **/ | ||
|
|
||
| use App\Events\SponsorServices\DeletedEventDTO; | ||
| use App\Events\SponsorServices\SummitMediaFileTypeCreatedEventDTO; | ||
| use App\Events\SponsorServices\SummitMediaFileTypeDomainEvents; | ||
| use App\Jobs\SponsorServices\PublishSponsorServiceDomainEventsJob; | ||
| use App\Models\Foundation\Summit\Factories\SummitMediaFileTypeFactory; | ||
| use App\Models\Foundation\Summit\Repositories\ISummitMediaFileTypeRepository; | ||
| use App\Services\Model\ISummitMediaFileTypeService; | ||
|
|
@@ -49,14 +53,20 @@ public function __construct | |
| */ | ||
| public function add(array $payload): SummitMediaFileType | ||
| { | ||
| return $this->tx_service->transaction(function() use($payload){ | ||
| $media_file_type = $this->tx_service->transaction(function() use($payload){ | ||
| $type = $this->repository->getByName(trim($payload['name'])); | ||
| if(!is_null($type)) | ||
| throw new ValidationException(sprintf("Name %s already exists.", $payload['name'])); | ||
| $type = SummitMediaFileTypeFactory::build($payload); | ||
| $this->repository->add($type); | ||
| return $type; | ||
| }); | ||
|
|
||
| PublishSponsorServiceDomainEventsJob::dispatch( | ||
| SummitMediaFileTypeCreatedEventDTO::fromSummitMediaFileType($media_file_type)->serialize(), | ||
| SummitMediaFileTypeDomainEvents::SummitMediaFileTypeCreated); | ||
|
|
||
| return $media_file_type; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -77,7 +87,13 @@ public function update(int $id, array $payload): SummitMediaFileType | |
| throw new ValidationException(sprintf("Name %s already exists.", $payload['name'])); | ||
| } | ||
|
|
||
| return SummitMediaFileTypeFactory::populate($type, $payload); | ||
| $media_file_type = SummitMediaFileTypeFactory::populate($type, $payload); | ||
|
|
||
| PublishSponsorServiceDomainEventsJob::dispatch( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @romanetar @romanetar Update event dispatched inside transaction ( fires even on rollback) move out side ( same pattern as add ) |
||
| SummitMediaFileTypeCreatedEventDTO::fromSummitMediaFileType($media_file_type)->serialize(), | ||
| SummitMediaFileTypeDomainEvents::SummitMediaFileTypeUpdated); | ||
|
|
||
| return $media_file_type; | ||
| }); | ||
| } | ||
|
|
||
|
|
@@ -94,6 +110,10 @@ public function delete(int $id): void | |
| throw new ValidationException("You can not delete a system defined type."); | ||
|
|
||
| $this->repository->delete($type); | ||
|
|
||
| PublishSponsorServiceDomainEventsJob::dispatch( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| DeletedEventDTO::fromEntity($type)->serialize(), | ||
| SummitMediaFileTypeDomainEvents::SummitMediaFileTypeDeleted); | ||
| }); | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@romanetar
@romanetar Nullable fields passed to non-nullable DTO constructor ( runtime TypeError )
SummitMediaFileType::getDescription() returns ?string and getAllowedExtensions() returns ?string, but SummitMediaFileTypeCreatedEventDTO::__construct declares both as string.