diff --git a/src/Http/Controllers/Api/ComponentController.php b/src/Http/Controllers/Api/ComponentController.php index 3d99758b..1a2f721a 100644 --- a/src/Http/Controllers/Api/ComponentController.php +++ b/src/Http/Controllers/Api/ComponentController.php @@ -12,6 +12,7 @@ use Cachet\Models\Component; use Illuminate\Http\Response; use Illuminate\Routing\Controller; +use Spatie\QueryBuilder\AllowedFilter; use Spatie\QueryBuilder\QueryBuilder; /** @@ -48,7 +49,11 @@ public function index() { $components = QueryBuilder::for(Component::class) ->allowedIncludes(self::ALLOWED_INCLUDES) - ->allowedFilters(['name', 'status', 'enabled']) + ->allowedFilters([ + 'name', + AllowedFilter::exact('status'), + AllowedFilter::exact('enabled'), + ]) ->allowedSorts(['name', 'order', 'id']) ->simplePaginate(request('per_page', 15)); diff --git a/src/Http/Controllers/Api/IncidentController.php b/src/Http/Controllers/Api/IncidentController.php index d363d3f2..1ed2a9c2 100644 --- a/src/Http/Controllers/Api/IncidentController.php +++ b/src/Http/Controllers/Api/IncidentController.php @@ -13,6 +13,7 @@ use Illuminate\Database\Eloquent\Builder; use Illuminate\Http\Response; use Illuminate\Routing\Controller; +use Spatie\QueryBuilder\AllowedFilter; use Spatie\QueryBuilder\QueryBuilder; /** @@ -52,7 +53,11 @@ public function index() $incidents = QueryBuilder::for($query) ->allowedIncludes(self::ALLOWED_INCLUDES) - ->allowedFilters(['name', 'status', 'occurred_at']) + ->allowedFilters([ + 'name', + AllowedFilter::exact('status'), + 'occurred_at' + ]) ->allowedSorts(['name', 'status', 'id']) ->simplePaginate(request('per_page', 15)); diff --git a/src/Http/Controllers/Api/IncidentUpdateController.php b/src/Http/Controllers/Api/IncidentUpdateController.php index 9843aae3..e6eb7b88 100644 --- a/src/Http/Controllers/Api/IncidentUpdateController.php +++ b/src/Http/Controllers/Api/IncidentUpdateController.php @@ -13,6 +13,7 @@ use Cachet\Models\Update; use Illuminate\Http\Response; use Illuminate\Routing\Controller; +use Spatie\QueryBuilder\AllowedFilter; use Spatie\QueryBuilder\AllowedInclude; use Spatie\QueryBuilder\QueryBuilder; @@ -42,7 +43,7 @@ public function index(Incident $incident) ->where('updateable_type', 'incident'); $updates = QueryBuilder::for($query) - ->allowedFilters(['status']) + ->allowedFilters([AllowedFilter::exact('status'),]) ->allowedIncludes(['incident']) ->allowedSorts(['status', 'created_at']) ->simplePaginate(request('per_page', 15)); diff --git a/src/Http/Controllers/Api/ScheduleController.php b/src/Http/Controllers/Api/ScheduleController.php index 19f14a69..92961c23 100644 --- a/src/Http/Controllers/Api/ScheduleController.php +++ b/src/Http/Controllers/Api/ScheduleController.php @@ -12,6 +12,7 @@ use Cachet\Models\Schedule; use Illuminate\Http\Response; use Illuminate\Routing\Controller; +use Spatie\QueryBuilder\AllowedFilter; use Spatie\QueryBuilder\QueryBuilder; /** @@ -32,13 +33,14 @@ class ScheduleController extends Controller * @queryParam page int Which page to show. Example: 2 * @queryParam sort Field to sort by. Enum: name, id, scheduled_at, completed_at, enabled. Example: name * @queryParam include Include related resources. Enum: components, updates, user. Example: components - * @queryParam filters[name] string Filter the resources. Example: name=api + * @queryParam filters[name] string Filter the resources by name. Example: api + * @queryParam filters[status] string Filter the resources by status. Example: 1 */ public function index() { $schedules = QueryBuilder::for(Schedule::class) ->allowedIncludes(['components', 'updates', 'user']) - ->allowedFilters(['name']) + ->allowedFilters(['name', AllowedFilter::exact('status'),]) ->allowedSorts(['name', 'id', 'scheduled_at', 'completed_at']) ->simplePaginate(request('per_page', 15)); diff --git a/src/Http/Resources/Component.php b/src/Http/Resources/Component.php index 1a1ba9f3..628964b0 100644 --- a/src/Http/Resources/Component.php +++ b/src/Http/Resources/Component.php @@ -16,7 +16,10 @@ public function toAttributes(Request $request): array 'description' => $this->description, 'link' => $this->link, 'order' => $this->order, - 'status' => $this->status, + 'status' => [ + 'human' => $this->status?->getLabel(), + 'value' => $this->status?->value, + ], 'enabled' => $this->enabled, 'meta' => $this->meta, 'created' => [ diff --git a/src/Http/Resources/Incident.php b/src/Http/Resources/Incident.php index 3ebc8b3d..777f1bda 100644 --- a/src/Http/Resources/Incident.php +++ b/src/Http/Resources/Incident.php @@ -22,8 +22,8 @@ public function toAttributes(Request $request): array 'stickied' => $this->stickied, 'notifications' => $this->notifications, 'status' => [ - 'human' => $this->latestStatus->getLabel(), - 'value' => $this->latestStatus->value, + 'human' => $this->latestStatus?->getLabel(), + 'value' => $this->latestStatus?->value, ], 'occurred' => [ 'human' => $this->occurred_at?->diffForHumans(),