Skip to content

Commit 9b2533e

Browse files
authored
Fix a bug where the API returns the wrong resource (#239)
1 parent 7cf94e1 commit 9b2533e

8 files changed

+18
-16
lines changed

src/Http/Controllers/Api/ComponentController.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Cachet\Enums\ComponentStatusEnum;
1212
use Cachet\Http\Resources\Component as ComponentResource;
1313
use Cachet\Models\Component;
14+
use Cachet\Models\Incident;
1415
use Dedoc\Scramble\Attributes\Group;
1516
use Dedoc\Scramble\Attributes\QueryParameter;
1617
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
@@ -77,9 +78,9 @@ public function store(CreateComponentRequestData $data, CreateComponent $createC
7778
*/
7879
public function show(Component $component)
7980
{
80-
$componentQuery = QueryBuilder::for($component)
81+
$componentQuery = QueryBuilder::for(Component::class)
8182
->allowedIncludes(self::ALLOWED_INCLUDES)
82-
->first();
83+
->find($component->id);
8384

8485
return ComponentResource::make($componentQuery)
8586
->response()

src/Http/Controllers/Api/ComponentGroupController.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Cachet\Concerns\GuardsApiAbilities;
99
use Cachet\Data\Requests\ComponentGroup\CreateComponentGroupRequestData;
1010
use Cachet\Data\Requests\ComponentGroup\UpdateComponentGroupRequestData;
11+
use Cachet\Http\Resources\Component;
1112
use Cachet\Http\Resources\ComponentGroup as ComponentGroupResource;
1213
use Cachet\Models\ComponentGroup;
1314
use Dedoc\Scramble\Attributes\Group;
@@ -57,9 +58,9 @@ public function store(CreateComponentGroupRequestData $data, CreateComponentGrou
5758
*/
5859
public function show(ComponentGroup $componentGroup)
5960
{
60-
$componentQuery = QueryBuilder::for($componentGroup)
61+
$componentQuery = QueryBuilder::for(ComponentGroup::class)
6162
->allowedIncludes(['components'])
62-
->first();
63+
->find($componentGroup->id);
6364

6465
return ComponentGroupResource::make($componentQuery)
6566
->response()

src/Http/Controllers/Api/IncidentController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ public function store(CreateIncidentRequestData $data, CreateIncident $createInc
7878
*/
7979
public function show(Incident $incident)
8080
{
81-
$incidentQuery = QueryBuilder::for($incident)
81+
$incidentQuery = QueryBuilder::for(Incident::class)
8282
->allowedIncludes(self::ALLOWED_INCLUDES)
83-
->first();
83+
->find($incident->id);
8484

8585
return IncidentResource::make($incidentQuery)
8686
->response()

src/Http/Controllers/Api/IncidentUpdateController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ public function store(CreateIncidentUpdateRequestData $data, Incident $incident,
6565
*/
6666
public function show(Incident $incident, Update $update)
6767
{
68-
$updateQuery = QueryBuilder::for($update)
68+
$updateQuery = QueryBuilder::for(Update::class)
6969
->allowedIncludes([
7070
AllowedInclude::relationship('incident', 'updateable'),
7171
])
72-
->first();
72+
->find($update->id);
7373

7474
return UpdateResource::make($updateQuery)
7575
->response()

src/Http/Controllers/Api/MetricController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ public function store(CreateMetricRequestData $data, CreateMetric $createMetricA
6767
*/
6868
public function show(Metric $metric)
6969
{
70-
$metricQuery = QueryBuilder::for($metric)
70+
$metricQuery = QueryBuilder::for(Metric::class)
7171
->allowedIncludes(['points'])
72-
->first();
72+
->find($metric->id);
7373

7474
return MetricResource::make($metricQuery)
7575
->response()

src/Http/Controllers/Api/MetricPointController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ public function store(CreateMetricPointRequestData $data, Metric $metric, Create
6161
*/
6262
public function show(Metric $metric, MetricPoint $metricPoint)
6363
{
64-
$metricPointQuery = QueryBuilder::for($metricPoint)
64+
$metricPointQuery = QueryBuilder::for(MetricPoint::class)
6565
->allowedIncludes(['metric'])
66-
->first();
66+
->find($metricPoint->id);
6767

6868
return MetricPointResource::make($metricPointQuery)
6969
->response()

src/Http/Controllers/Api/ScheduleController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ public function store(CreateScheduleRequestData $data, CreateSchedule $createSch
6161
*/
6262
public function show(Schedule $schedule)
6363
{
64-
$scheduleQuery = QueryBuilder::for($schedule)
64+
$scheduleQuery = QueryBuilder::for(Schedule::class)
6565
->allowedIncludes(['components', 'updates', 'user'])
66-
->first();
66+
->find($schedule->id);
6767

6868
return ScheduleResource::make($scheduleQuery)
6969
->response()

src/Http/Controllers/Api/ScheduleUpdateController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ public function store(CreateScheduleUpdateRequestData $data, Schedule $schedule,
6464
*/
6565
public function show(Schedule $schedule, Update $update)
6666
{
67-
$updateQuery = QueryBuilder::for($update)
67+
$updateQuery = QueryBuilder::for(Update::class)
6868
->allowedIncludes([
6969
AllowedInclude::relationship('schedule', 'updateable'),
7070
])
71-
->first();
71+
->find($update->id);
7272

7373
return UpdateResource::make($updateQuery)
7474
->response()

0 commit comments

Comments
 (0)