From 88960afb8e91c9cbc21d23b9b6fd276701423c93 Mon Sep 17 00:00:00 2001 From: Joel Butcher Date: Wed, 8 Jan 2025 10:50:56 +0000 Subject: [PATCH] Add rules to requests and make naming explicit (#169) Signed-off-by: Joel Butcher Co-authored-by: James Brooks --- src/Actions/Component/CreateComponent.php | 4 +- src/Actions/Component/UpdateComponent.php | 4 +- .../ComponentGroup/CreateComponentGroup.php | 4 +- .../ComponentGroup/UpdateComponentGroup.php | 4 +- src/Actions/Incident/CreateIncident.php | 6 +-- src/Actions/Incident/UpdateIncident.php | 4 +- .../CreateIncidentTemplate.php | 4 +- .../UpdateIncidentTemplate.php | 4 +- src/Actions/Metric/CreateMetric.php | 4 +- src/Actions/Metric/CreateMetricPoint.php | 4 +- src/Actions/Metric/UpdateMetric.php | 4 +- src/Actions/Schedule/CreateSchedule.php | 8 ++-- src/Actions/Schedule/UpdateSchedule.php | 8 ++-- src/Actions/Update/CreateUpdate.php | 6 +-- src/Actions/Update/EditUpdate.php | 6 +-- src/Data/BaseData.php | 9 ++++ src/Data/Cachet/ThemeData.php | 2 +- .../CreateIncidentUpdateData.php | 18 -------- .../IncidentUpdate/EditIncidentUpdateData.php | 16 ------- src/Data/Metric/CreateMetricPointData.php | 16 ------- src/Data/Metric/UpdateMetricData.php | 23 ---------- .../Component/CreateComponentRequestData.php} | 23 +++++++--- .../Component/UpdateComponentRequestData.php} | 23 +++++++--- .../CreateComponentGroupRequestData.php} | 12 ++--- .../UpdateComponentGroupRequestData.php} | 11 ++--- .../Incident/CreateIncidentRequestData.php} | 23 +++++++++- .../Incident/UpdateIncidentRequestData.php} | 22 +++++++--- .../CreateIncidentTemplateRequestData.php} | 19 +++++--- .../UpdateIncidentTemplateRequestData.php} | 18 ++++++-- .../CreateIncidentUpdateRequestData.php | 26 +++++++++++ .../EditIncidentUpdateRequestData.php | 25 +++++++++++ .../Metric/CreateMetricPointRequestData.php | 21 +++++++++ .../Metric/CreateMetricRequestData.php} | 20 ++++++--- .../Metric/UpdateMetricRequestData.php | 32 ++++++++++++++ .../Schedule/CreateScheduleRequestData.php | 44 +++++++++++++++++++ .../ScheduleComponentRequestData.php} | 6 +-- .../Schedule/UpdateScheduleRequestData.php | 37 ++++++++++++++++ .../CreateScheduleUpdateRequestData.php | 18 ++++++++ .../EditScheduleUpdateRequestData.php | 18 ++++++++ src/Data/Schedule/CreateScheduleData.php | 32 -------------- src/Data/Schedule/UpdateScheduleData.php | 25 ----------- .../CreateScheduleUpdateData.php | 16 ------- .../ScheduleUpdate/EditScheduleUpdateData.php | 14 ------ src/Filament/Resources/IncidentResource.php | 4 +- src/Filament/Resources/ScheduleResource.php | 4 +- .../Controllers/Api/ComponentController.php | 8 ++-- .../Api/ComponentGroupController.php | 8 ++-- .../Controllers/Api/IncidentController.php | 8 ++-- .../Api/IncidentTemplateController.php | 8 ++-- .../Api/IncidentUpdateController.php | 8 ++-- src/Http/Controllers/Api/MetricController.php | 8 ++-- .../Controllers/Api/MetricPointController.php | 4 +- .../Controllers/Api/ScheduleController.php | 8 ++-- .../Api/ScheduleUpdateController.php | 8 ++-- tests/Architecture/DataTest.php | 29 ++++++++++++ .../Actions/Component/CreateComponentTest.php | 6 +-- .../Actions/Component/UpdateComponentTest.php | 6 +-- .../CreateComponentGroupTest.php | 6 +-- .../UpdateComponentGroupTest.php | 8 ++-- .../Actions/Incident/CreateIncidentTest.php | 10 ++--- .../Actions/Incident/UpdateIncidentTest.php | 6 +-- .../CreateIncidentTemplateTest.php | 6 +-- .../UpdateIncidentTemplateTest.php | 4 +- .../Actions/Metric/CreateMetricPointTest.php | 10 ++--- .../Unit/Actions/Metric/CreateMetricTest.php | 4 +- .../Unit/Actions/Metric/UpdateMetricTest.php | 4 +- .../Actions/Schedule/CreateScheduleTest.php | 6 +-- .../Actions/Schedule/UpdateScheduleTest.php | 6 +-- .../Unit/Actions/Update/CreateUpdateTest.php | 10 ++--- tests/Unit/Actions/Update/EditUpdateTest.php | 8 ++-- 70 files changed, 514 insertions(+), 334 deletions(-) delete mode 100644 src/Data/IncidentUpdate/CreateIncidentUpdateData.php delete mode 100644 src/Data/IncidentUpdate/EditIncidentUpdateData.php delete mode 100644 src/Data/Metric/CreateMetricPointData.php delete mode 100644 src/Data/Metric/UpdateMetricData.php rename src/Data/{Component/CreateComponentData.php => Requests/Component/CreateComponentRequestData.php} (65%) rename src/Data/{Component/UpdateComponentData.php => Requests/Component/UpdateComponentRequestData.php} (50%) rename src/Data/{ComponentGroup/CreateComponentGroupData.php => Requests/ComponentGroup/CreateComponentGroupRequestData.php} (76%) rename src/Data/{ComponentGroup/UpdateComponentGroupData.php => Requests/ComponentGroup/UpdateComponentGroupRequestData.php} (74%) rename src/Data/{Incident/CreateIncidentData.php => Requests/Incident/CreateIncidentRequestData.php} (64%) rename src/Data/{Incident/UpdateIncidentData.php => Requests/Incident/UpdateIncidentRequestData.php} (57%) rename src/Data/{IncidentTemplate/CreateIncidentTemplateData.php => Requests/IncidentTemplate/CreateIncidentTemplateRequestData.php} (60%) rename src/Data/{IncidentTemplate/UpdateIncidentTemplateData.php => Requests/IncidentTemplate/UpdateIncidentTemplateRequestData.php} (58%) create mode 100644 src/Data/Requests/IncidentUpdate/CreateIncidentUpdateRequestData.php create mode 100644 src/Data/Requests/IncidentUpdate/EditIncidentUpdateRequestData.php create mode 100644 src/Data/Requests/Metric/CreateMetricPointRequestData.php rename src/Data/{Metric/CreateMetricData.php => Requests/Metric/CreateMetricRequestData.php} (59%) create mode 100644 src/Data/Requests/Metric/UpdateMetricRequestData.php create mode 100644 src/Data/Requests/Schedule/CreateScheduleRequestData.php rename src/Data/{Schedule/ScheduleComponentData.php => Requests/Schedule/ScheduleComponentRequestData.php} (69%) create mode 100644 src/Data/Requests/Schedule/UpdateScheduleRequestData.php create mode 100644 src/Data/Requests/ScheduleUpdate/CreateScheduleUpdateRequestData.php create mode 100644 src/Data/Requests/ScheduleUpdate/EditScheduleUpdateRequestData.php delete mode 100644 src/Data/Schedule/CreateScheduleData.php delete mode 100644 src/Data/Schedule/UpdateScheduleData.php delete mode 100644 src/Data/ScheduleUpdate/CreateScheduleUpdateData.php delete mode 100644 src/Data/ScheduleUpdate/EditScheduleUpdateData.php create mode 100644 tests/Architecture/DataTest.php diff --git a/src/Actions/Component/CreateComponent.php b/src/Actions/Component/CreateComponent.php index d33bba9d..8ad0fc38 100644 --- a/src/Actions/Component/CreateComponent.php +++ b/src/Actions/Component/CreateComponent.php @@ -2,7 +2,7 @@ namespace Cachet\Actions\Component; -use Cachet\Data\Component\CreateComponentData; +use Cachet\Data\Requests\Component\CreateComponentRequestData; use Cachet\Models\Component; class CreateComponent @@ -10,7 +10,7 @@ class CreateComponent /** * Handle the action. */ - public function handle(CreateComponentData $component): Component + public function handle(CreateComponentRequestData $component): Component { return Component::create($component->toArray()); } diff --git a/src/Actions/Component/UpdateComponent.php b/src/Actions/Component/UpdateComponent.php index 10e5f52b..b82b1e41 100644 --- a/src/Actions/Component/UpdateComponent.php +++ b/src/Actions/Component/UpdateComponent.php @@ -2,7 +2,7 @@ namespace Cachet\Actions\Component; -use Cachet\Data\Component\UpdateComponentData; +use Cachet\Data\Requests\Component\UpdateComponentRequestData; use Cachet\Events\Components\ComponentStatusWasChanged; use Cachet\Models\Component; @@ -11,7 +11,7 @@ class UpdateComponent /** * Handle the action. */ - public function handle(Component $component, UpdateComponentData $data): Component + public function handle(Component $component, UpdateComponentRequestData $data): Component { $oldStatus = $component->status; diff --git a/src/Actions/ComponentGroup/CreateComponentGroup.php b/src/Actions/ComponentGroup/CreateComponentGroup.php index 33204aa6..94e2e3f5 100644 --- a/src/Actions/ComponentGroup/CreateComponentGroup.php +++ b/src/Actions/ComponentGroup/CreateComponentGroup.php @@ -2,7 +2,7 @@ namespace Cachet\Actions\ComponentGroup; -use Cachet\Data\ComponentGroup\CreateComponentGroupData; +use Cachet\Data\Requests\ComponentGroup\CreateComponentGroupRequestData; use Cachet\Models\Component; use Cachet\Models\ComponentGroup; @@ -14,7 +14,7 @@ class CreateComponentGroup /** * Handle the action. */ - public function handle(CreateComponentGroupData $data): ComponentGroup + public function handle(CreateComponentGroupRequestData $data): ComponentGroup { return tap(ComponentGroup::create( $data->except('components')->toArray(), diff --git a/src/Actions/ComponentGroup/UpdateComponentGroup.php b/src/Actions/ComponentGroup/UpdateComponentGroup.php index 1b16d9c6..d61e1ac8 100644 --- a/src/Actions/ComponentGroup/UpdateComponentGroup.php +++ b/src/Actions/ComponentGroup/UpdateComponentGroup.php @@ -2,7 +2,7 @@ namespace Cachet\Actions\ComponentGroup; -use Cachet\Data\ComponentGroup\UpdateComponentGroupData; +use Cachet\Data\Requests\ComponentGroup\UpdateComponentGroupRequestData; use Cachet\Models\Component; use Cachet\Models\ComponentGroup; @@ -11,7 +11,7 @@ class UpdateComponentGroup /** * Handle the action. */ - public function handle(ComponentGroup $componentGroup, UpdateComponentGroupData $data): ComponentGroup + public function handle(ComponentGroup $componentGroup, UpdateComponentGroupRequestData $data): ComponentGroup { $componentGroup->update($data->except('components')->toArray()); diff --git a/src/Actions/Incident/CreateIncident.php b/src/Actions/Incident/CreateIncident.php index b3b98f4e..464b5911 100644 --- a/src/Actions/Incident/CreateIncident.php +++ b/src/Actions/Incident/CreateIncident.php @@ -2,7 +2,7 @@ namespace Cachet\Actions\Incident; -use Cachet\Data\Incident\CreateIncidentData; +use Cachet\Data\Requests\Incident\CreateIncidentRequestData; use Cachet\Models\Component; use Cachet\Models\Incident; use Cachet\Models\IncidentTemplate; @@ -14,7 +14,7 @@ class CreateIncident /** * Handle the action. */ - public function handle(CreateIncidentData $data): Incident + public function handle(CreateIncidentRequestData $data): Incident { if (isset($data->template)) { $template = IncidentTemplate::query() @@ -35,7 +35,7 @@ public function handle(CreateIncidentData $data): Incident /** * Render the incident template with the given data. */ - private function parseTemplate(IncidentTemplate $template, CreateIncidentData $data): string + private function parseTemplate(IncidentTemplate $template, CreateIncidentRequestData $data): string { $vars = array_merge($data->templateVars, [ 'incident' => [ diff --git a/src/Actions/Incident/UpdateIncident.php b/src/Actions/Incident/UpdateIncident.php index bd473719..bc21dea6 100644 --- a/src/Actions/Incident/UpdateIncident.php +++ b/src/Actions/Incident/UpdateIncident.php @@ -2,7 +2,7 @@ namespace Cachet\Actions\Incident; -use Cachet\Data\Incident\UpdateIncidentData; +use Cachet\Data\Requests\Incident\UpdateIncidentRequestData; use Cachet\Events\Incidents\IncidentUpdated; use Cachet\Models\Incident; @@ -11,7 +11,7 @@ class UpdateIncident /** * Handle the action. */ - public function handle(Incident $incident, UpdateIncidentData $data): Incident + public function handle(Incident $incident, UpdateIncidentRequestData $data): Incident { $incident->update($data->toArray()); diff --git a/src/Actions/IncidentTemplate/CreateIncidentTemplate.php b/src/Actions/IncidentTemplate/CreateIncidentTemplate.php index 492e2bc8..e9db1aa2 100644 --- a/src/Actions/IncidentTemplate/CreateIncidentTemplate.php +++ b/src/Actions/IncidentTemplate/CreateIncidentTemplate.php @@ -2,7 +2,7 @@ namespace Cachet\Actions\IncidentTemplate; -use Cachet\Data\IncidentTemplate\CreateIncidentTemplateData; +use Cachet\Data\Requests\IncidentTemplate\CreateIncidentTemplateRequestData; use Cachet\Models\IncidentTemplate; class CreateIncidentTemplate @@ -10,7 +10,7 @@ class CreateIncidentTemplate /** * Handle the action. */ - public function handle(CreateIncidentTemplateData $data): IncidentTemplate + public function handle(CreateIncidentTemplateRequestData $data): IncidentTemplate { return IncidentTemplate::create($data->toArray()); } diff --git a/src/Actions/IncidentTemplate/UpdateIncidentTemplate.php b/src/Actions/IncidentTemplate/UpdateIncidentTemplate.php index dc6330a9..c5d6aea4 100644 --- a/src/Actions/IncidentTemplate/UpdateIncidentTemplate.php +++ b/src/Actions/IncidentTemplate/UpdateIncidentTemplate.php @@ -2,7 +2,7 @@ namespace Cachet\Actions\IncidentTemplate; -use Cachet\Data\IncidentTemplate\UpdateIncidentTemplateData; +use Cachet\Data\Requests\IncidentTemplate\UpdateIncidentTemplateRequestData; use Cachet\Models\IncidentTemplate; class UpdateIncidentTemplate @@ -10,7 +10,7 @@ class UpdateIncidentTemplate /** * Handle the action. */ - public function handle(IncidentTemplate $incidentTemplate, UpdateIncidentTemplateData $data): IncidentTemplate + public function handle(IncidentTemplate $incidentTemplate, UpdateIncidentTemplateRequestData $data): IncidentTemplate { $incidentTemplate->update($data->toArray()); diff --git a/src/Actions/Metric/CreateMetric.php b/src/Actions/Metric/CreateMetric.php index bf54f9bf..2e99ee17 100644 --- a/src/Actions/Metric/CreateMetric.php +++ b/src/Actions/Metric/CreateMetric.php @@ -2,7 +2,7 @@ namespace Cachet\Actions\Metric; -use Cachet\Data\Metric\CreateMetricData; +use Cachet\Data\Requests\Metric\CreateMetricRequestData; use Cachet\Models\Metric; class CreateMetric @@ -10,7 +10,7 @@ class CreateMetric /** * Handle the action. */ - public function handle(CreateMetricData $data): Metric + public function handle(CreateMetricRequestData $data): Metric { return Metric::create($data->toArray()); } diff --git a/src/Actions/Metric/CreateMetricPoint.php b/src/Actions/Metric/CreateMetricPoint.php index 2d94ff2d..0c90f51d 100644 --- a/src/Actions/Metric/CreateMetricPoint.php +++ b/src/Actions/Metric/CreateMetricPoint.php @@ -2,7 +2,7 @@ namespace Cachet\Actions\Metric; -use Cachet\Data\Metric\CreateMetricPointData; +use Cachet\Data\Requests\Metric\CreateMetricPointRequestData; use Cachet\Models\Metric; use Cachet\Models\MetricPoint; @@ -11,7 +11,7 @@ class CreateMetricPoint /** * Handle the action. */ - public function handle(Metric $metric, ?CreateMetricPointData $data = null): MetricPoint + public function handle(Metric $metric, ?CreateMetricPointRequestData $data = null): MetricPoint { $lastPoint = $metric->metricPoints()->latest()->first(); diff --git a/src/Actions/Metric/UpdateMetric.php b/src/Actions/Metric/UpdateMetric.php index a4d89527..add2f82e 100644 --- a/src/Actions/Metric/UpdateMetric.php +++ b/src/Actions/Metric/UpdateMetric.php @@ -2,7 +2,7 @@ namespace Cachet\Actions\Metric; -use Cachet\Data\Metric\UpdateMetricData; +use Cachet\Data\Requests\Metric\UpdateMetricRequestData; use Cachet\Models\Metric; class UpdateMetric @@ -10,7 +10,7 @@ class UpdateMetric /** * Handle the action. */ - public function handle(Metric $metric, UpdateMetricData $data): Metric + public function handle(Metric $metric, UpdateMetricRequestData $data): Metric { $metric->update($data->toArray()); diff --git a/src/Actions/Schedule/CreateSchedule.php b/src/Actions/Schedule/CreateSchedule.php index deeefb7e..f003d21a 100644 --- a/src/Actions/Schedule/CreateSchedule.php +++ b/src/Actions/Schedule/CreateSchedule.php @@ -2,8 +2,8 @@ namespace Cachet\Actions\Schedule; -use Cachet\Data\Schedule\CreateScheduleData; -use Cachet\Data\Schedule\ScheduleComponentData; +use Cachet\Data\Requests\Schedule\CreateScheduleRequestData; +use Cachet\Data\Requests\Schedule\ScheduleComponentRequestData; use Cachet\Models\Schedule; class CreateSchedule @@ -11,14 +11,14 @@ class CreateSchedule /** * Handle the action. */ - public function handle(CreateScheduleData $data): Schedule + public function handle(CreateScheduleRequestData $data): Schedule { return tap(Schedule::create($data->except('components')->toArray()), function (Schedule $schedule) use ($data) { if (! $data->components) { return; } - $components = collect($data->components)->map(fn (ScheduleComponentData $component) => [ + $components = collect($data->components)->map(fn (ScheduleComponentRequestData $component) => [ 'component_id' => $component->id, 'component_status' => $component->status, ])->all(); diff --git a/src/Actions/Schedule/UpdateSchedule.php b/src/Actions/Schedule/UpdateSchedule.php index f738090f..1262fbbd 100644 --- a/src/Actions/Schedule/UpdateSchedule.php +++ b/src/Actions/Schedule/UpdateSchedule.php @@ -2,8 +2,8 @@ namespace Cachet\Actions\Schedule; -use Cachet\Data\Schedule\ScheduleComponentData; -use Cachet\Data\Schedule\UpdateScheduleData; +use Cachet\Data\Requests\Schedule\ScheduleComponentRequestData; +use Cachet\Data\Requests\Schedule\UpdateScheduleRequestData; use Cachet\Models\Schedule; class UpdateSchedule @@ -11,12 +11,12 @@ class UpdateSchedule /** * Handle the action. */ - public function handle(Schedule $schedule, UpdateScheduleData $data): Schedule + public function handle(Schedule $schedule, UpdateScheduleRequestData $data): Schedule { $schedule->update($data->except('components')->toArray()); if ($data->components) { - $components = collect($data->components)->map(fn (ScheduleComponentData $component) => [ + $components = collect($data->components)->map(fn (ScheduleComponentRequestData $component) => [ 'component_id' => $component->id, 'component_status' => $component->status, ])->all(); diff --git a/src/Actions/Update/CreateUpdate.php b/src/Actions/Update/CreateUpdate.php index 1dbc7249..75f8ecd7 100644 --- a/src/Actions/Update/CreateUpdate.php +++ b/src/Actions/Update/CreateUpdate.php @@ -2,8 +2,8 @@ namespace Cachet\Actions\Update; -use Cachet\Data\IncidentUpdate\CreateIncidentUpdateData; -use Cachet\Data\ScheduleUpdate\CreateScheduleUpdateData; +use Cachet\Data\Requests\IncidentUpdate\CreateIncidentUpdateRequestData; +use Cachet\Data\Requests\ScheduleUpdate\CreateScheduleUpdateRequestData; use Cachet\Models\Incident; use Cachet\Models\Schedule; use Cachet\Models\Update; @@ -13,7 +13,7 @@ class CreateUpdate /** * Handle the action. */ - public function handle(Incident|Schedule $resource, CreateIncidentUpdateData|CreateScheduleUpdateData $data): Update + public function handle(Incident|Schedule $resource, CreateIncidentUpdateRequestData|CreateScheduleUpdateRequestData $data): Update { $update = new Update(array_merge(['user_id' => auth()->id()], $data->toArray())); diff --git a/src/Actions/Update/EditUpdate.php b/src/Actions/Update/EditUpdate.php index 7538d543..3f8ebe1c 100644 --- a/src/Actions/Update/EditUpdate.php +++ b/src/Actions/Update/EditUpdate.php @@ -2,8 +2,8 @@ namespace Cachet\Actions\Update; -use Cachet\Data\IncidentUpdate\EditIncidentUpdateData; -use Cachet\Data\ScheduleUpdate\EditScheduleUpdateData; +use Cachet\Data\Requests\IncidentUpdate\EditIncidentUpdateRequestData; +use Cachet\Data\Requests\ScheduleUpdate\EditScheduleUpdateRequestData; use Cachet\Models\Update; class EditUpdate @@ -11,7 +11,7 @@ class EditUpdate /** * Handle the action. */ - public function handle(Update $update, EditIncidentUpdateData|EditScheduleUpdateData $data): Update + public function handle(Update $update, EditIncidentUpdateRequestData|EditScheduleUpdateRequestData $data): Update { return tap($update, function (Update $update) use ($data) { $update->update($data->toArray()); diff --git a/src/Data/BaseData.php b/src/Data/BaseData.php index 40cea16f..a3732162 100644 --- a/src/Data/BaseData.php +++ b/src/Data/BaseData.php @@ -4,8 +4,17 @@ use Spatie\LaravelData\Data; +/** + * @template TKey of array-key + * @template TValue + */ abstract class BaseData extends Data { + /** + * Get the instance as an array. + * + * @return array + */ public function toArray(): array { return array_filter( diff --git a/src/Data/Cachet/ThemeData.php b/src/Data/Cachet/ThemeData.php index e7a33594..8a0d0568 100644 --- a/src/Data/Cachet/ThemeData.php +++ b/src/Data/Cachet/ThemeData.php @@ -9,7 +9,7 @@ use Spatie\LaravelData\Attributes\Computed; use Spatie\LaravelData\Attributes\Validation\Required; -class ThemeData extends BaseData +final class ThemeData extends BaseData { public const GRAYS = ['slate', 'gray', 'zinc', 'neutral', 'stone']; diff --git a/src/Data/IncidentUpdate/CreateIncidentUpdateData.php b/src/Data/IncidentUpdate/CreateIncidentUpdateData.php deleted file mode 100644 index d3836f7d..00000000 --- a/src/Data/IncidentUpdate/CreateIncidentUpdateData.php +++ /dev/null @@ -1,18 +0,0 @@ - ['string', 'required', 'max:255'], + 'description' => ['string'], + 'status' => [Rule::enum(ComponentStatusEnum::class)], + 'link' => ['string'], + 'order' => ['int', 'min:0'], + 'enabled' => ['boolean'], + 'component_group_id' => ['int', 'min:0', Rule::exists('component_groups', 'id')], + ]; + } + /** * Specify body parameter documentation for Scribe. */ diff --git a/src/Data/Component/UpdateComponentData.php b/src/Data/Requests/Component/UpdateComponentRequestData.php similarity index 50% rename from src/Data/Component/UpdateComponentData.php rename to src/Data/Requests/Component/UpdateComponentRequestData.php index d25ed4ca..72976f6f 100644 --- a/src/Data/Component/UpdateComponentData.php +++ b/src/Data/Requests/Component/UpdateComponentRequestData.php @@ -1,27 +1,38 @@ ['string', 'max:255'], + 'description' => ['string'], + 'status' => [Rule::enum(ComponentStatusEnum::class)], + 'link' => ['string'], + 'order' => ['int', 'min:0'], + 'component_group_id' => ['int', 'min:0', Rule::exists('component_groups', 'id')], + 'enabled' => ['boolean'], + ]; + } } diff --git a/src/Data/ComponentGroup/CreateComponentGroupData.php b/src/Data/Requests/ComponentGroup/CreateComponentGroupRequestData.php similarity index 76% rename from src/Data/ComponentGroup/CreateComponentGroupData.php rename to src/Data/Requests/ComponentGroup/CreateComponentGroupRequestData.php index 2db1a0e5..6ae858f3 100644 --- a/src/Data/ComponentGroup/CreateComponentGroupData.php +++ b/src/Data/Requests/ComponentGroup/CreateComponentGroupRequestData.php @@ -1,6 +1,6 @@ ['required', 'string', 'max:255'], + 'order' => ['int', 'min:0'], + 'visible' => ['bool'], + 'components' => ['array'], 'components.*' => ['int', 'min:0', Rule::exists('components', 'id')], ]; } diff --git a/src/Data/ComponentGroup/UpdateComponentGroupData.php b/src/Data/Requests/ComponentGroup/UpdateComponentGroupRequestData.php similarity index 74% rename from src/Data/ComponentGroup/UpdateComponentGroupData.php rename to src/Data/Requests/ComponentGroup/UpdateComponentGroupRequestData.php index 5d3b3643..50488cd7 100644 --- a/src/Data/ComponentGroup/UpdateComponentGroupData.php +++ b/src/Data/Requests/ComponentGroup/UpdateComponentGroupRequestData.php @@ -1,6 +1,6 @@ ['string', 'max:255'], + 'order' => ['int', 'min:0'], + 'visible' => ['bool'], + 'components' => ['array'], 'components.*' => ['int', 'min:0', Rule::exists('components', 'id')], ]; } diff --git a/src/Data/Incident/CreateIncidentData.php b/src/Data/Requests/Incident/CreateIncidentRequestData.php similarity index 64% rename from src/Data/Incident/CreateIncidentData.php rename to src/Data/Requests/Incident/CreateIncidentRequestData.php index 39d5803f..38df9993 100644 --- a/src/Data/Incident/CreateIncidentData.php +++ b/src/Data/Requests/Incident/CreateIncidentRequestData.php @@ -1,17 +1,19 @@ ['required', 'string', 'max:255'], + 'message' => ['required_without:template', 'string'], + 'template' => ['required_without:message', 'string'], + 'status' => ['required', Rule::enum(IncidentStatusEnum::class)], + 'visible' => ['boolean'], + 'stickied' => ['boolean'], + 'notifications' => ['boolean'], + 'occurred_at' => ['nullable', 'string'], + 'template_vars' => ['array'], + 'component_id' => [Rule::exists('components', 'id')], + 'component_status' => ['nullable', Rule::enum(ComponentStatusEnum::class), 'required_with:component_id'], + ]; + } + public function withMessage(string $message): self { return new self( diff --git a/src/Data/Incident/UpdateIncidentData.php b/src/Data/Requests/Incident/UpdateIncidentRequestData.php similarity index 57% rename from src/Data/Incident/UpdateIncidentData.php rename to src/Data/Requests/Incident/UpdateIncidentRequestData.php index e347f5ea..1e3fc58c 100644 --- a/src/Data/Incident/UpdateIncidentData.php +++ b/src/Data/Requests/Incident/UpdateIncidentRequestData.php @@ -1,23 +1,22 @@ ['string', 'max:255'], + 'message' => ['string'], + 'status' => [Rule::enum(IncidentStatusEnum::class)], + 'visible' => ['boolean'], + 'stickied' => ['boolean'], + 'notifications' => ['boolean'], + 'occurred_at' => ['nullable', 'string'], + ]; + } + public function toArray(): array { return parent::toArray(); // TODO: Change the autogenerated stub diff --git a/src/Data/IncidentTemplate/CreateIncidentTemplateData.php b/src/Data/Requests/IncidentTemplate/CreateIncidentTemplateRequestData.php similarity index 60% rename from src/Data/IncidentTemplate/CreateIncidentTemplateData.php rename to src/Data/Requests/IncidentTemplate/CreateIncidentTemplateRequestData.php index e72002f1..48acbc91 100644 --- a/src/Data/IncidentTemplate/CreateIncidentTemplateData.php +++ b/src/Data/Requests/IncidentTemplate/CreateIncidentTemplateRequestData.php @@ -1,30 +1,39 @@ slug = $slug; } + public static function rules(ValidationContext $context): array + { + return [ + 'name' => ['required', 'string', 'max:255'], + 'slug' => ['string'], + 'template' => ['required', 'string'], + 'engine' => [Rule::enum(IncidentTemplateEngineEnum::class)], + ]; + } + public function slug(): string { return $this->slug ?? Str::slug($this->name); diff --git a/src/Data/IncidentTemplate/UpdateIncidentTemplateData.php b/src/Data/Requests/IncidentTemplate/UpdateIncidentTemplateRequestData.php similarity index 58% rename from src/Data/IncidentTemplate/UpdateIncidentTemplateData.php rename to src/Data/Requests/IncidentTemplate/UpdateIncidentTemplateRequestData.php index 7455483d..e21d526d 100644 --- a/src/Data/IncidentTemplate/UpdateIncidentTemplateData.php +++ b/src/Data/Requests/IncidentTemplate/UpdateIncidentTemplateRequestData.php @@ -1,24 +1,34 @@ ['string', 'max:255'], + 'slug' => ['string'], + 'template' => ['string'], + 'engine' => [Rule::enum(IncidentTemplateEngineEnum::class)], + ]; + } + public function slug(): string { return $this->slug ?? Str::slug($this->name); diff --git a/src/Data/Requests/IncidentUpdate/CreateIncidentUpdateRequestData.php b/src/Data/Requests/IncidentUpdate/CreateIncidentUpdateRequestData.php new file mode 100644 index 00000000..fe50321b --- /dev/null +++ b/src/Data/Requests/IncidentUpdate/CreateIncidentUpdateRequestData.php @@ -0,0 +1,26 @@ + ['required', Rule::enum(IncidentStatusEnum::class)], + 'message' => ['required', 'string'], + ]; + } +} diff --git a/src/Data/Requests/IncidentUpdate/EditIncidentUpdateRequestData.php b/src/Data/Requests/IncidentUpdate/EditIncidentUpdateRequestData.php new file mode 100644 index 00000000..8b24cd91 --- /dev/null +++ b/src/Data/Requests/IncidentUpdate/EditIncidentUpdateRequestData.php @@ -0,0 +1,25 @@ + [Rule::enum(IncidentStatusEnum::class)], + 'message' => ['string'], + ]; + } +} diff --git a/src/Data/Requests/Metric/CreateMetricPointRequestData.php b/src/Data/Requests/Metric/CreateMetricPointRequestData.php new file mode 100644 index 00000000..a592016d --- /dev/null +++ b/src/Data/Requests/Metric/CreateMetricPointRequestData.php @@ -0,0 +1,21 @@ + ['required', 'numeric']]; + } +} diff --git a/src/Data/Metric/CreateMetricData.php b/src/Data/Requests/Metric/CreateMetricRequestData.php similarity index 59% rename from src/Data/Metric/CreateMetricData.php rename to src/Data/Requests/Metric/CreateMetricRequestData.php index 4cf023b5..1de96a23 100644 --- a/src/Data/Metric/CreateMetricData.php +++ b/src/Data/Requests/Metric/CreateMetricRequestData.php @@ -1,6 +1,6 @@ ['required', 'string', 'max:255'], + 'suffix' => ['required', 'string', 'max:255'], + 'description' => ['string'], + 'default_value' => ['decimal:1,2'], + 'threshold' => ['int', 'min:0', 'max:60', new FactorOfSixty], + ]; + } } diff --git a/src/Data/Requests/Metric/UpdateMetricRequestData.php b/src/Data/Requests/Metric/UpdateMetricRequestData.php new file mode 100644 index 00000000..f4ea346c --- /dev/null +++ b/src/Data/Requests/Metric/UpdateMetricRequestData.php @@ -0,0 +1,32 @@ + ['string', 'max:255'], + 'suffix' => ['string', 'max:255'], + 'description' => ['string'], + 'default_value' => ['decimal:1,2'], + 'threshold' => ['int', 'min:0', 'max:60', new FactorOfSixty], + ]; + } +} diff --git a/src/Data/Requests/Schedule/CreateScheduleRequestData.php b/src/Data/Requests/Schedule/CreateScheduleRequestData.php new file mode 100644 index 00000000..1e8836f3 --- /dev/null +++ b/src/Data/Requests/Schedule/CreateScheduleRequestData.php @@ -0,0 +1,44 @@ + ['required', 'string', 'max:255'], + 'message' => ['required', 'string'], + 'scheduled_at' => ['required', 'date'], + 'components' => ['array'], + 'components.*.id' => ['required_with:components', 'int', 'exists:components,id'], + 'components.*.status' => ['required_with:components', 'int', Rule::enum(ComponentStatusEnum::class)], + ]; + } +} diff --git a/src/Data/Schedule/ScheduleComponentData.php b/src/Data/Requests/Schedule/ScheduleComponentRequestData.php similarity index 69% rename from src/Data/Schedule/ScheduleComponentData.php rename to src/Data/Requests/Schedule/ScheduleComponentRequestData.php index ef386655..6003ef55 100644 --- a/src/Data/Schedule/ScheduleComponentData.php +++ b/src/Data/Requests/Schedule/ScheduleComponentRequestData.php @@ -1,13 +1,13 @@ ['string', 'max:255'], + 'message' => ['string'], + 'scheduled_at' => ['nullable', 'date'], + 'components' => ['array'], + 'components.*.id' => ['required_with:components', 'int', 'exists:components,id'], + 'components.*.status' => ['required_with:components', Rule::enum(ComponentStatusEnum::class)], + ]; + } +} diff --git a/src/Data/Requests/ScheduleUpdate/CreateScheduleUpdateRequestData.php b/src/Data/Requests/ScheduleUpdate/CreateScheduleUpdateRequestData.php new file mode 100644 index 00000000..4b08b16a --- /dev/null +++ b/src/Data/Requests/ScheduleUpdate/CreateScheduleUpdateRequestData.php @@ -0,0 +1,18 @@ + ['required', 'string']]; + } +} diff --git a/src/Data/Requests/ScheduleUpdate/EditScheduleUpdateRequestData.php b/src/Data/Requests/ScheduleUpdate/EditScheduleUpdateRequestData.php new file mode 100644 index 00000000..8720dc56 --- /dev/null +++ b/src/Data/Requests/ScheduleUpdate/EditScheduleUpdateRequestData.php @@ -0,0 +1,18 @@ + ['string']]; + } +} diff --git a/src/Data/Schedule/CreateScheduleData.php b/src/Data/Schedule/CreateScheduleData.php deleted file mode 100644 index 5093bf03..00000000 --- a/src/Data/Schedule/CreateScheduleData.php +++ /dev/null @@ -1,32 +0,0 @@ -label(__('cachet::incident.list.actions.record_update')) ->color('info') ->action(function (CreateIncidentUpdateAction $createIncidentUpdate, Incident $record, array $data) { - $createIncidentUpdate->handle($record, CreateIncidentUpdateData::from($data)); + $createIncidentUpdate->handle($record, CreateIncidentUpdateRequestData::from($data)); Notification::make() ->title(__('cachet::incident.record_update.success_title', ['name' => $record->name])) diff --git a/src/Filament/Resources/ScheduleResource.php b/src/Filament/Resources/ScheduleResource.php index cf6ddd8a..0cbfb713 100644 --- a/src/Filament/Resources/ScheduleResource.php +++ b/src/Filament/Resources/ScheduleResource.php @@ -3,7 +3,7 @@ namespace Cachet\Filament\Resources; use Cachet\Actions\Update\CreateUpdate; -use Cachet\Data\ScheduleUpdate\CreateScheduleUpdateData; +use Cachet\Data\Requests\ScheduleUpdate\CreateScheduleUpdateRequestData; use Cachet\Enums\ScheduleStatusEnum; use Cachet\Filament\Resources\ScheduleResource\Pages; use Cachet\Filament\Resources\UpdateResource\RelationManagers\UpdatesRelationManager; @@ -88,7 +88,7 @@ public static function table(Table $table): Table ->label(__('cachet::schedule.list.actions.record_update')) ->color('info') ->action(function (CreateUpdate $createUpdate, Schedule $record, array $data) { - $createUpdate->handle($record, CreateScheduleUpdateData::from($data)); + $createUpdate->handle($record, CreateScheduleUpdateRequestData::from($data)); Notification::make() ->title(__('cachet::schedule.add_update.success_title', ['name' => $record->name])) diff --git a/src/Http/Controllers/Api/ComponentController.php b/src/Http/Controllers/Api/ComponentController.php index 40026a08..2d0f5cd7 100644 --- a/src/Http/Controllers/Api/ComponentController.php +++ b/src/Http/Controllers/Api/ComponentController.php @@ -5,8 +5,8 @@ use Cachet\Actions\Component\CreateComponent; use Cachet\Actions\Component\DeleteComponent; use Cachet\Actions\Component\UpdateComponent; -use Cachet\Data\Component\CreateComponentData; -use Cachet\Data\Component\UpdateComponentData; +use Cachet\Data\Requests\Component\CreateComponentRequestData; +use Cachet\Data\Requests\Component\UpdateComponentRequestData; use Cachet\Http\Resources\Component as ComponentResource; use Cachet\Models\Component; use Illuminate\Http\Response; @@ -61,7 +61,7 @@ public function index() * * @authenticated */ - public function store(CreateComponentData $data, CreateComponent $createComponentAction) + public function store(CreateComponentRequestData $data, CreateComponent $createComponentAction) { $component = $createComponentAction->handle( $data, @@ -99,7 +99,7 @@ public function show(Component $component) * * @authenticated */ - public function update(UpdateComponentData $data, Component $component, UpdateComponent $updateComponentAction) + public function update(UpdateComponentRequestData $data, Component $component, UpdateComponent $updateComponentAction) { $updateComponentAction->handle($component, $data); diff --git a/src/Http/Controllers/Api/ComponentGroupController.php b/src/Http/Controllers/Api/ComponentGroupController.php index c98c46b0..797d9f56 100644 --- a/src/Http/Controllers/Api/ComponentGroupController.php +++ b/src/Http/Controllers/Api/ComponentGroupController.php @@ -5,8 +5,8 @@ use Cachet\Actions\ComponentGroup\CreateComponentGroup; use Cachet\Actions\ComponentGroup\DeleteComponentGroup; use Cachet\Actions\ComponentGroup\UpdateComponentGroup; -use Cachet\Data\ComponentGroup\CreateComponentGroupData; -use Cachet\Data\ComponentGroup\UpdateComponentGroupData; +use Cachet\Data\Requests\ComponentGroup\CreateComponentGroupRequestData; +use Cachet\Data\Requests\ComponentGroup\UpdateComponentGroupRequestData; use Cachet\Http\Resources\ComponentGroup as ComponentGroupResource; use Cachet\Models\ComponentGroup; use Illuminate\Http\Response; @@ -49,7 +49,7 @@ public function index() * * @authenticated */ - public function store(CreateComponentGroupData $data, CreateComponentGroup $createComponentGroupAction) + public function store(CreateComponentGroupRequestData $data, CreateComponentGroup $createComponentGroupAction) { $componentGroup = $createComponentGroupAction->handle($data); @@ -85,7 +85,7 @@ public function show(ComponentGroup $componentGroup) * * @authenticated */ - public function update(UpdateComponentGroupData $data, ComponentGroup $componentGroup, UpdateComponentGroup $updateComponentGroupAction) + public function update(UpdateComponentGroupRequestData $data, ComponentGroup $componentGroup, UpdateComponentGroup $updateComponentGroupAction) { $updateComponentGroupAction->handle($componentGroup, $data); diff --git a/src/Http/Controllers/Api/IncidentController.php b/src/Http/Controllers/Api/IncidentController.php index b46ce6e4..be034867 100644 --- a/src/Http/Controllers/Api/IncidentController.php +++ b/src/Http/Controllers/Api/IncidentController.php @@ -5,8 +5,8 @@ use Cachet\Actions\Incident\CreateIncident; use Cachet\Actions\Incident\DeleteIncident; use Cachet\Actions\Incident\UpdateIncident; -use Cachet\Data\Incident\CreateIncidentData; -use Cachet\Data\Incident\UpdateIncidentData; +use Cachet\Data\Requests\Incident\CreateIncidentRequestData; +use Cachet\Data\Requests\Incident\UpdateIncidentRequestData; use Cachet\Http\Resources\Incident as IncidentResource; use Cachet\Models\Incident; use Illuminate\Database\Eloquent\Builder; @@ -65,7 +65,7 @@ public function index() * * @authenticated */ - public function store(CreateIncidentData $data, CreateIncident $createIncidentAction) + public function store(CreateIncidentRequestData $data, CreateIncident $createIncidentAction) { $incident = $createIncidentAction->handle($data); @@ -101,7 +101,7 @@ public function show(Incident $incident) * * @authenticated */ - public function update(UpdateIncidentData $data, Incident $incident, UpdateIncident $updateIncidentAction) + public function update(UpdateIncidentRequestData $data, Incident $incident, UpdateIncident $updateIncidentAction) { $updateIncidentAction->handle($incident, $data); diff --git a/src/Http/Controllers/Api/IncidentTemplateController.php b/src/Http/Controllers/Api/IncidentTemplateController.php index c808ca0b..829864d1 100644 --- a/src/Http/Controllers/Api/IncidentTemplateController.php +++ b/src/Http/Controllers/Api/IncidentTemplateController.php @@ -5,8 +5,8 @@ use Cachet\Actions\IncidentTemplate\CreateIncidentTemplate; use Cachet\Actions\IncidentTemplate\DeleteIncidentTemplate; use Cachet\Actions\IncidentTemplate\UpdateIncidentTemplate; -use Cachet\Data\IncidentTemplate\CreateIncidentTemplateData; -use Cachet\Data\IncidentTemplate\UpdateIncidentTemplateData; +use Cachet\Data\Requests\IncidentTemplate\CreateIncidentTemplateRequestData; +use Cachet\Data\Requests\IncidentTemplate\UpdateIncidentTemplateRequestData; use Cachet\Http\Resources\IncidentTemplate as IncidentTemplateResource; use Cachet\Models\IncidentTemplate; use Illuminate\Http\Response; @@ -51,7 +51,7 @@ public function index() * * @authenticated */ - public function store(CreateIncidentTemplateData $data, CreateIncidentTemplate $createIncidentTemplateAction) + public function store(CreateIncidentTemplateRequestData $data, CreateIncidentTemplate $createIncidentTemplateAction) { $template = $createIncidentTemplateAction->handle($data); @@ -81,7 +81,7 @@ public function show(IncidentTemplate $incidentTemplate) * * @authenticated */ - public function update(UpdateIncidentTemplateData $data, IncidentTemplate $incidentTemplate, UpdateIncidentTemplate $updateIncidentTemplateAction) + public function update(UpdateIncidentTemplateRequestData $data, IncidentTemplate $incidentTemplate, UpdateIncidentTemplate $updateIncidentTemplateAction) { $template = $updateIncidentTemplateAction->handle($incidentTemplate, $data); diff --git a/src/Http/Controllers/Api/IncidentUpdateController.php b/src/Http/Controllers/Api/IncidentUpdateController.php index a1bb3ef4..4ae22c2a 100644 --- a/src/Http/Controllers/Api/IncidentUpdateController.php +++ b/src/Http/Controllers/Api/IncidentUpdateController.php @@ -5,8 +5,8 @@ use Cachet\Actions\Update\CreateUpdate; use Cachet\Actions\Update\DeleteUpdate; use Cachet\Actions\Update\EditUpdate; -use Cachet\Data\IncidentUpdate\CreateIncidentUpdateData; -use Cachet\Data\IncidentUpdate\EditIncidentUpdateData; +use Cachet\Data\Requests\IncidentUpdate\CreateIncidentUpdateRequestData; +use Cachet\Data\Requests\IncidentUpdate\EditIncidentUpdateRequestData; use Cachet\Http\Resources\Update as UpdateResource; use Cachet\Models\Incident; use Cachet\Models\Update; @@ -56,7 +56,7 @@ public function index(Incident $incident) * * @authenticated */ - public function store(CreateIncidentUpdateData $data, Incident $incident, CreateUpdate $createUpdateAction) + public function store(CreateIncidentUpdateRequestData $data, Incident $incident, CreateUpdate $createUpdateAction) { $update = $createUpdateAction->handle($incident, $data); @@ -94,7 +94,7 @@ public function show(Incident $incident, Update $update) * * @authenticated */ - public function update(EditIncidentUpdateData $data, Incident $incident, Update $update, EditUpdate $editUpdateAction) + public function update(EditIncidentUpdateRequestData $data, Incident $incident, Update $update, EditUpdate $editUpdateAction) { $editUpdateAction->handle($update, $data); diff --git a/src/Http/Controllers/Api/MetricController.php b/src/Http/Controllers/Api/MetricController.php index 1dc81f0f..573e0b6c 100644 --- a/src/Http/Controllers/Api/MetricController.php +++ b/src/Http/Controllers/Api/MetricController.php @@ -5,8 +5,8 @@ use Cachet\Actions\Metric\CreateMetric; use Cachet\Actions\Metric\DeleteMetric; use Cachet\Actions\Metric\UpdateMetric; -use Cachet\Data\Metric\CreateMetricData; -use Cachet\Data\Metric\UpdateMetricData; +use Cachet\Data\Requests\Metric\CreateMetricRequestData; +use Cachet\Data\Requests\Metric\UpdateMetricRequestData; use Cachet\Http\Resources\Metric as MetricResource; use Cachet\Models\Metric; use Illuminate\Database\Eloquent\Builder; @@ -58,7 +58,7 @@ public function index() * * @authenticated */ - public function store(CreateMetricData $data, CreateMetric $createMetricAction) + public function store(CreateMetricRequestData $data, CreateMetric $createMetricAction) { $metric = $createMetricAction->handle($data); @@ -94,7 +94,7 @@ public function show(Metric $metric) * * @authenticated */ - public function update(UpdateMetricData $data, Metric $metric, UpdateMetric $updateMetricAction) + public function update(UpdateMetricRequestData $data, Metric $metric, UpdateMetric $updateMetricAction) { $updateMetricAction->handle($metric, $data); diff --git a/src/Http/Controllers/Api/MetricPointController.php b/src/Http/Controllers/Api/MetricPointController.php index 5443d13e..a3817b6b 100644 --- a/src/Http/Controllers/Api/MetricPointController.php +++ b/src/Http/Controllers/Api/MetricPointController.php @@ -4,7 +4,7 @@ use Cachet\Actions\Metric\CreateMetricPoint; use Cachet\Actions\Metric\DeleteMetricPoint; -use Cachet\Data\Metric\CreateMetricPointData; +use Cachet\Data\Requests\Metric\CreateMetricPointRequestData; use Cachet\Http\Resources\MetricPoint as MetricPointResource; use Cachet\Models\Metric; use Cachet\Models\MetricPoint; @@ -51,7 +51,7 @@ public function index(Metric $metric) * * @authenticated */ - public function store(CreateMetricPointData $data, Metric $metric, CreateMetricPoint $createMetricPointAction) + public function store(CreateMetricPointRequestData $data, Metric $metric, CreateMetricPoint $createMetricPointAction) { $metricPoint = $createMetricPointAction->handle($metric, $data); diff --git a/src/Http/Controllers/Api/ScheduleController.php b/src/Http/Controllers/Api/ScheduleController.php index 42daf77c..505545f6 100644 --- a/src/Http/Controllers/Api/ScheduleController.php +++ b/src/Http/Controllers/Api/ScheduleController.php @@ -5,8 +5,8 @@ use Cachet\Actions\Schedule\CreateSchedule; use Cachet\Actions\Schedule\DeleteSchedule; use Cachet\Actions\Schedule\UpdateSchedule; -use Cachet\Data\Schedule\CreateScheduleData; -use Cachet\Data\Schedule\UpdateScheduleData; +use Cachet\Data\Requests\Schedule\CreateScheduleRequestData; +use Cachet\Data\Requests\Schedule\UpdateScheduleRequestData; use Cachet\Http\Resources\Schedule as ScheduleResource; use Cachet\Models\Schedule; use Illuminate\Http\Response; @@ -51,7 +51,7 @@ public function index() * * @authenticated */ - public function store(CreateScheduleData $data, CreateSchedule $createScheduleAction) + public function store(CreateScheduleRequestData $data, CreateSchedule $createScheduleAction) { $schedule = $createScheduleAction->handle($data); @@ -87,7 +87,7 @@ public function show(Schedule $schedule) * * @authenticated */ - public function update(UpdateScheduleData $data, Schedule $schedule, UpdateSchedule $updateScheduleAction) + public function update(UpdateScheduleRequestData $data, Schedule $schedule, UpdateSchedule $updateScheduleAction) { $updateScheduleAction->handle($schedule, $data); diff --git a/src/Http/Controllers/Api/ScheduleUpdateController.php b/src/Http/Controllers/Api/ScheduleUpdateController.php index 857b5ee8..57721515 100644 --- a/src/Http/Controllers/Api/ScheduleUpdateController.php +++ b/src/Http/Controllers/Api/ScheduleUpdateController.php @@ -5,8 +5,8 @@ use Cachet\Actions\Update\CreateUpdate; use Cachet\Actions\Update\DeleteUpdate; use Cachet\Actions\Update\EditUpdate; -use Cachet\Data\ScheduleUpdate\CreateScheduleUpdateData; -use Cachet\Data\ScheduleUpdate\EditScheduleUpdateData; +use Cachet\Data\Requests\ScheduleUpdate\CreateScheduleUpdateRequestData; +use Cachet\Data\Requests\ScheduleUpdate\EditScheduleUpdateRequestData; use Cachet\Http\Resources\Update as UpdateResource; use Cachet\Models\Schedule; use Cachet\Models\Update; @@ -56,7 +56,7 @@ public function index(Schedule $schedule) * * @authenticated */ - public function store(CreateScheduleUpdateData $data, Schedule $schedule, CreateUpdate $createUpdateAction) + public function store(CreateScheduleUpdateRequestData $data, Schedule $schedule, CreateUpdate $createUpdateAction) { $update = $createUpdateAction->handle($schedule, $data); @@ -94,7 +94,7 @@ public function show(Schedule $schedule, Update $update) * * @authenticated */ - public function update(EditScheduleUpdateData $data, Schedule $schedule, Update $update, EditUpdate $editUpdateAction) + public function update(EditScheduleUpdateRequestData $data, Schedule $schedule, Update $update, EditUpdate $editUpdateAction) { $editUpdateAction->handle($update, $data); diff --git a/tests/Architecture/DataTest.php b/tests/Architecture/DataTest.php new file mode 100644 index 00000000..6a73646f --- /dev/null +++ b/tests/Architecture/DataTest.php @@ -0,0 +1,29 @@ +expect('Cachet\Data') + ->toBeClasses() + ->toExtend(BaseData::class) + ->toBeFinal() + ->ignoring(BaseData::class); + +test('data requests test') + ->expect('Cachet\Data\Requests') + ->toHaveConstructor() + ->toExtend(BaseData::class) + ->toHaveSuffix('RequestData') + ->toOnlyBeUsedIn([ + 'Cachet\Actions', + 'Cachet\Data', + 'Cachet\Http\Controllers', + 'Cachet\Filament\Resources' + ]); + +test('base data test') + ->expect(BaseData::class) + ->toHaveMethodsDocumented() + ->toBeAbstract() + ->toExtend(Data::class); diff --git a/tests/Unit/Actions/Component/CreateComponentTest.php b/tests/Unit/Actions/Component/CreateComponentTest.php index 8e84a8cc..35836950 100644 --- a/tests/Unit/Actions/Component/CreateComponentTest.php +++ b/tests/Unit/Actions/Component/CreateComponentTest.php @@ -1,7 +1,7 @@ 'My Component', 'description' => 'My component description', ]); @@ -26,7 +26,7 @@ }); it('can create a component with a given status', function () { - $data = CreateComponentData::from([ + $data = CreateComponentRequestData::from([ 'name' => 'My Component', 'description' => 'My component description', 'status' => ComponentStatusEnum::performance_issues, diff --git a/tests/Unit/Actions/Component/UpdateComponentTest.php b/tests/Unit/Actions/Component/UpdateComponentTest.php index 51068078..7a1de6d4 100644 --- a/tests/Unit/Actions/Component/UpdateComponentTest.php +++ b/tests/Unit/Actions/Component/UpdateComponentTest.php @@ -1,7 +1,7 @@ 'My component description.', ]); - $data = UpdateComponentData::from([ + $data = UpdateComponentRequestData::from([ 'name' => 'My Updated Component', 'description' => 'My updated component description.', ]); @@ -43,7 +43,7 @@ 'status' => ComponentStatusEnum::operational, ]); - app(UpdateComponent::class)->handle($component, UpdateComponentData::from([ + app(UpdateComponent::class)->handle($component, UpdateComponentRequestData::from([ 'status' => ComponentStatusEnum::major_outage, ])); diff --git a/tests/Unit/Actions/ComponentGroup/CreateComponentGroupTest.php b/tests/Unit/Actions/ComponentGroup/CreateComponentGroupTest.php index 4968ea47..3c6acdb7 100644 --- a/tests/Unit/Actions/ComponentGroup/CreateComponentGroupTest.php +++ b/tests/Unit/Actions/ComponentGroup/CreateComponentGroupTest.php @@ -1,7 +1,7 @@ todo('Make visible default to non-null value?'); it('can create a component group with a name, order and visibility', function () { - $data = CreateComponentGroupData::from([ + $data = CreateComponentGroupRequestData::from([ 'name' => 'Services', 'order' => 2, 'visible' => ResourceVisibilityEnum::authenticated->value, @@ -36,7 +36,7 @@ it('can create a component group and add components', function () { $components = Component::factory()->count(3)->create(); - $data = CreateComponentGroupData::from([ + $data = CreateComponentGroupRequestData::from([ 'name' => 'Services', 'components' => $components->pluck('id')->values()->all(), ]); diff --git a/tests/Unit/Actions/ComponentGroup/UpdateComponentGroupTest.php b/tests/Unit/Actions/ComponentGroup/UpdateComponentGroupTest.php index e37900fe..c4666661 100644 --- a/tests/Unit/Actions/ComponentGroup/UpdateComponentGroupTest.php +++ b/tests/Unit/Actions/ComponentGroup/UpdateComponentGroupTest.php @@ -1,14 +1,14 @@ create(); - $data = UpdateComponentGroupData::from([ + $data = UpdateComponentGroupRequestData::from([ 'name' => 'Services', ]); @@ -22,7 +22,7 @@ Component::factory()->count(3)->create(); $componentGroup = ComponentGroup::factory()->create(); - $data = UpdateComponentGroupData::from([ + $data = UpdateComponentGroupRequestData::from([ 'name' => 'Services', ]); @@ -39,7 +39,7 @@ $components = Component::factory()->count(3)->create(); $componentGroup = ComponentGroup::factory()->create(); - $componentGroup = app(UpdateComponentGroup::class)->handle($componentGroup, UpdateComponentGroupData::from([ + $componentGroup = app(UpdateComponentGroup::class)->handle($componentGroup, UpdateComponentGroupRequestData::from([ 'components' => $components->pluck('id')->values()->all(), ])); diff --git a/tests/Unit/Actions/Incident/CreateIncidentTest.php b/tests/Unit/Actions/Incident/CreateIncidentTest.php index 3bdadfe2..25309014 100644 --- a/tests/Unit/Actions/Incident/CreateIncidentTest.php +++ b/tests/Unit/Actions/Incident/CreateIncidentTest.php @@ -1,7 +1,7 @@ 'My Incident', 'message' => 'This is an incident message.', ]); @@ -27,7 +27,7 @@ }); it('can create an incident with a given status', function () { - $data = CreateIncidentData::from([ + $data = CreateIncidentRequestData::from([ 'name' => 'My Incident', 'message' => 'This is an incident message', 'status' => IncidentStatusEnum::investigating, @@ -49,7 +49,7 @@ 'template' => 'This is a template: {{ incident.name }} foo: {{ foo }}', ]); - $data = CreateIncidentData::from([ + $data = CreateIncidentRequestData::from([ 'name' => 'My Incident', 'template' => 'my-template', 'template_vars' => [ @@ -73,7 +73,7 @@ 'template' => 'This is a template: {{ $incident[\'name\'] }} foo: {{ $foo }}', ]); - $data = CreateIncidentData::from([ + $data = CreateIncidentRequestData::from([ 'name' => 'My Incident', 'template' => 'my-template', 'template_vars' => [ diff --git a/tests/Unit/Actions/Incident/UpdateIncidentTest.php b/tests/Unit/Actions/Incident/UpdateIncidentTest.php index d2d41903..a6c00899 100644 --- a/tests/Unit/Actions/Incident/UpdateIncidentTest.php +++ b/tests/Unit/Actions/Incident/UpdateIncidentTest.php @@ -1,14 +1,14 @@ create(); - $data = UpdateIncidentData::from([ + $data = UpdateIncidentRequestData::from([ 'name' => 'Incident Updated', ]); @@ -23,7 +23,7 @@ $incident = Incident::factory()->create(); - app(UpdateIncident::class)->handle($incident, UpdateIncidentData::from([ + app(UpdateIncident::class)->handle($incident, UpdateIncidentRequestData::from([ 'name' => 'New Incident Title', ])); diff --git a/tests/Unit/Actions/IncidentTemplate/CreateIncidentTemplateTest.php b/tests/Unit/Actions/IncidentTemplate/CreateIncidentTemplateTest.php index 85f7dce7..ca0fecea 100644 --- a/tests/Unit/Actions/IncidentTemplate/CreateIncidentTemplateTest.php +++ b/tests/Unit/Actions/IncidentTemplate/CreateIncidentTemplateTest.php @@ -1,11 +1,11 @@ handle(CreateIncidentTemplateData::from([ + $incidentTemplate = app(CreateIncidentTemplate::class)->handle(CreateIncidentTemplateRequestData::from([ 'name' => 'GitHub Issues', 'template' => 'Hey there.', 'engine' => IncidentTemplateEngineEnum::twig, @@ -17,7 +17,7 @@ }); it('can use a custom slug', function () { - $incidentTemplate = app(CreateIncidentTemplate::class)->handle(CreateIncidentTemplateData::from([ + $incidentTemplate = app(CreateIncidentTemplate::class)->handle(CreateIncidentTemplateRequestData::from([ 'name' => 'GitHub Issues', 'slug' => 'custom-github-issues', 'template' => 'Hey there.', diff --git a/tests/Unit/Actions/IncidentTemplate/UpdateIncidentTemplateTest.php b/tests/Unit/Actions/IncidentTemplate/UpdateIncidentTemplateTest.php index 964805a7..936bf5ed 100644 --- a/tests/Unit/Actions/IncidentTemplate/UpdateIncidentTemplateTest.php +++ b/tests/Unit/Actions/IncidentTemplate/UpdateIncidentTemplateTest.php @@ -1,14 +1,14 @@ blade()->create(); - app(UpdateIncidentTemplate::class)->handle($incidentTemplate, UpdateIncidentTemplateData::from([ + app(UpdateIncidentTemplate::class)->handle($incidentTemplate, UpdateIncidentTemplateRequestData::from([ 'name' => 'GitHub Issues', 'template' => 'Hey there.', 'engine' => IncidentTemplateEngineEnum::twig, diff --git a/tests/Unit/Actions/Metric/CreateMetricPointTest.php b/tests/Unit/Actions/Metric/CreateMetricPointTest.php index 589db713..2e8f4eae 100644 --- a/tests/Unit/Actions/Metric/CreateMetricPointTest.php +++ b/tests/Unit/Actions/Metric/CreateMetricPointTest.php @@ -1,7 +1,7 @@ create(); - $point = app(CreateMetricPoint::class)->handle($metric, CreateMetricPointData::from([ + $point = app(CreateMetricPoint::class)->handle($metric, CreateMetricPointRequestData::from([ 'value' => 1, ])); @@ -55,7 +55,7 @@ 'threshold' => 1, ]); - $point = app(CreateMetricPoint::class)->handle($metric, CreateMetricPointData::from([ + $point = app(CreateMetricPoint::class)->handle($metric, CreateMetricPointRequestData::from([ 'value' => 1, ])); @@ -77,7 +77,7 @@ 'threshold' => 1, ]); - $point = app(CreateMetricPoint::class)->handle($metric, CreateMetricPointData::from([ + $point = app(CreateMetricPoint::class)->handle($metric, CreateMetricPointRequestData::from([ 'value' => 1, ])); @@ -99,7 +99,7 @@ 'threshold' => 1, ]); - $point = app(CreateMetricPoint::class)->handle($metric, CreateMetricPointData::from([ + $point = app(CreateMetricPoint::class)->handle($metric, CreateMetricPointRequestData::from([ 'value' => 1, 'timestamp' => $timestamp, ])); diff --git a/tests/Unit/Actions/Metric/CreateMetricTest.php b/tests/Unit/Actions/Metric/CreateMetricTest.php index 75206b89..eaef4753 100644 --- a/tests/Unit/Actions/Metric/CreateMetricTest.php +++ b/tests/Unit/Actions/Metric/CreateMetricTest.php @@ -1,14 +1,14 @@ 'Foo', 'suffix' => 'Bar', 'description' => 'Baz', diff --git a/tests/Unit/Actions/Metric/UpdateMetricTest.php b/tests/Unit/Actions/Metric/UpdateMetricTest.php index efe1902f..24ebb47f 100644 --- a/tests/Unit/Actions/Metric/UpdateMetricTest.php +++ b/tests/Unit/Actions/Metric/UpdateMetricTest.php @@ -1,7 +1,7 @@ create(); - $data = UpdateMetricData::from([ + $data = UpdateMetricRequestData::from([ 'name' => 'Updated Metric', ]); diff --git a/tests/Unit/Actions/Schedule/CreateScheduleTest.php b/tests/Unit/Actions/Schedule/CreateScheduleTest.php index 14bcd171..823dd8d3 100644 --- a/tests/Unit/Actions/Schedule/CreateScheduleTest.php +++ b/tests/Unit/Actions/Schedule/CreateScheduleTest.php @@ -1,11 +1,11 @@ 'My Scheduled Maintenance', 'message' => 'Something will go down...', 'scheduled_at' => '2023-09-01 12:00:00', @@ -23,7 +23,7 @@ it('can create a schedule with components', function () { [$componentA, $componentB] = Component::factory()->count(2)->create(); - $data = CreateScheduleData::from([ + $data = CreateScheduleRequestData::from([ 'name' => 'My Scheduled Maintenance', 'message' => 'Something will go down...', 'scheduled_at' => '2023-09-01 12:00:00', diff --git a/tests/Unit/Actions/Schedule/UpdateScheduleTest.php b/tests/Unit/Actions/Schedule/UpdateScheduleTest.php index 1c67754a..b52ce41a 100644 --- a/tests/Unit/Actions/Schedule/UpdateScheduleTest.php +++ b/tests/Unit/Actions/Schedule/UpdateScheduleTest.php @@ -1,7 +1,7 @@ create(); - $data = UpdateScheduleData::from([ + $data = UpdateScheduleRequestData::from([ 'name' => 'Schedule Updated', ]); @@ -23,7 +23,7 @@ $schedule = Schedule::factory()->create(); [$componentA, $componentB] = Component::factory()->count(2)->create(); - $data = UpdateScheduleData::from([ + $data = UpdateScheduleRequestData::from([ 'components' => [ ['id' => $componentA->id, 'status' => ComponentStatusEnum::performance_issues], ['id' => $componentB->id, 'status' => ComponentStatusEnum::major_outage], diff --git a/tests/Unit/Actions/Update/CreateUpdateTest.php b/tests/Unit/Actions/Update/CreateUpdateTest.php index 121fc4ad..2b334273 100644 --- a/tests/Unit/Actions/Update/CreateUpdateTest.php +++ b/tests/Unit/Actions/Update/CreateUpdateTest.php @@ -1,8 +1,8 @@ create(); - $data = CreateIncidentUpdateData::from([ + $data = CreateIncidentUpdateRequestData::from([ 'message' => 'This is an update message.', 'status' => IncidentStatusEnum::investigating, ]); @@ -26,7 +26,7 @@ 'status' => IncidentStatusEnum::investigating, ]); - $data = CreateIncidentUpdateData::from([ + $data = CreateIncidentUpdateRequestData::from([ 'message' => 'This is an update message.', 'status' => IncidentStatusEnum::identified, ]); @@ -42,7 +42,7 @@ it('can create a schedule update', function () { $schedule = Schedule::factory()->create(); - $data = CreateScheduleUpdateData::from([ + $data = CreateScheduleUpdateRequestData::from([ 'message' => 'This is an update message for a schedule.', 'status' => IncidentStatusEnum::investigating, ]); diff --git a/tests/Unit/Actions/Update/EditUpdateTest.php b/tests/Unit/Actions/Update/EditUpdateTest.php index d233761b..8ed95f28 100644 --- a/tests/Unit/Actions/Update/EditUpdateTest.php +++ b/tests/Unit/Actions/Update/EditUpdateTest.php @@ -1,14 +1,14 @@ forIncident()->create(); - $data = EditIncidentUpdateData::from([ + $data = EditIncidentUpdateRequestData::from([ 'message' => 'Incident Updated', ]); @@ -22,7 +22,7 @@ it('can update a schedule update', function () { $update = Update::factory()->forSchedule()->create(); - $data = EditScheduleUpdateData::from([ + $data = EditScheduleUpdateRequestData::from([ 'message' => 'Schedule Updated', ]);