Add date, from and till query parameters to the filter the appointments index results by date (#1134).

This commit is contained in:
Alex Tselegidis 2022-10-16 22:17:36 +03:00
parent e2c3137262
commit f389608aa1
2 changed files with 43 additions and 2 deletions

View file

@ -58,8 +58,37 @@ class Appointments_api_v1 extends EA_Controller {
$with = $this->api->request_with(); $with = $this->api->request_with();
$where = NULL;
// Date query param.
$date = request('date');
if ( ! empty($date))
{
$where['DATE(start_datetime)'] = (new DateTime($date))->format('Y-m-d');
}
// From query param.
$from = request('from');
if ( ! empty($from))
{
$where['DATE(start_datetime) >='] = (new DateTime($from))->format('Y-m-d');
}
// Till query param.
$till = request('till');
if ( ! empty($till))
{
$where['DATE(end_datetime) <='] = (new DateTime($till))->format('Y-m-d');
}
$appointments = empty($keyword) $appointments = empty($keyword)
? $this->appointments_model->get(NULL, $limit, $offset, $order_by) ? $this->appointments_model->get($where, $limit, $offset, $order_by)
: $this->appointments_model->search($keyword, $limit, $offset, $order_by); : $this->appointments_model->search($keyword, $limit, $offset, $order_by);
foreach ($appointments as &$appointment) foreach ($appointments as &$appointment)

View file

@ -100,6 +100,18 @@ paths:
schema: schema:
type: string type: string
deprecated: true deprecated: true
- name: date
in: query
schema:
type: string
- name: start
in: query
schema:
type: string
- name: end
in: query
schema:
type: string
responses: responses:
'200': '200':
description: OK description: OK