From 50ec06b29cfdfb8458ef39b7cb182b5a0ae2f522 Mon Sep 17 00:00:00 2001 From: Alex Tselegidis Date: Sat, 14 Jan 2023 10:25:25 +0100 Subject: [PATCH] Allow API clients to filter appointments by service, provider and customer ID (#1296, #1325) --- .../api/v1/Appointments_api_v1.php | 27 +++++++++++++++++++ openapi.yml | 16 +++++++++-- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/application/controllers/api/v1/Appointments_api_v1.php b/application/controllers/api/v1/Appointments_api_v1.php index 9b433e4f..056b7143 100644 --- a/application/controllers/api/v1/Appointments_api_v1.php +++ b/application/controllers/api/v1/Appointments_api_v1.php @@ -87,6 +87,33 @@ class Appointments_api_v1 extends EA_Controller { $where['DATE(end_datetime) <='] = (new DateTime($till))->format('Y-m-d'); } + // Service ID query param. + + $service_id = request('serviceId'); + + if ( ! empty($service_id)) + { + $where['id_services'] = $service_id; + } + + // Provider ID query param. + + $provider_id = request('providerId'); + + if ( ! empty($provider_id)) + { + $where['id_users_provider'] = $provider_id; + } + + // Customer ID query param. + + $customer_id = request('customerId'); + + if ( ! empty($customer_id)) + { + $where['id_users_customer'] = $customer_id; + } + $appointments = empty($keyword) ? $this->appointments_model->get($where, $limit, $offset, $order_by) : $this->appointments_model->search($keyword, $limit, $offset, $order_by); diff --git a/openapi.yml b/openapi.yml index 74476002..b48667e2 100644 --- a/openapi.yml +++ b/openapi.yml @@ -104,14 +104,26 @@ paths: in: query schema: type: string - - name: start + - name: from in: query schema: type: string - - name: end + - name: till in: query schema: type: string + - name: serviceId + in: query + schema: + type: integer + - name: providerId + in: query + schema: + type: integer + - name: customerId + in: query + schema: + type: integer responses: '200': description: OK