Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend API of "services" and "unavailabilities" #1588

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion application/controllers/api/v1/Unavailabilities_api_v1.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,42 @@ public function index(): void

$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');
}

// Provider ID query param.

$provider_id = request('providerId');

if (!empty($provider_id)) {
$where['id_users_provider'] = $provider_id;
}

$unavailabilities = empty($keyword)
? $this->unavailabilities_model->get(null, $limit, $offset, $order_by)
? $this->unavailabilities_model->get($where, $limit, $offset, $order_by)
: $this->unavailabilities_model->search($keyword, $limit, $offset, $order_by);

foreach ($unavailabilities as &$unavailability) {
Expand Down
4 changes: 4 additions & 0 deletions application/models/Appointments_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,10 @@ public function api_decode(array &$appointment, array $base = null): void
$decoded_request['id_services'] = $appointment['serviceId'];
}

if (array_key_exists('color', $appointment)) {
$decoded_request['color'] = $appointment['color'];
}

if (array_key_exists('googleCalendarId', $appointment)) {
$decoded_request['id_google_calendar'] = $appointment['googleCalendarId'];
}
Expand Down
5 changes: 5 additions & 0 deletions application/models/Services_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ public function api_encode(array &$service): void
'duration' => (int) $service['duration'],
'price' => (float) $service['price'],
'currency' => $service['currency'],
'color' => $service['color'],
'description' => $service['description'],
'location' => $service['location'],
'availabilitiesType' => $service['availabilities_type'],
Expand Down Expand Up @@ -455,6 +456,10 @@ public function api_decode(array &$service, array $base = null): void
$decoded_resource['currency'] = $service['currency'];
}

if (array_key_exists('color', $service)) {
$decoded_resource['color'] = $service['color'];
}

if (array_key_exists('description', $service)) {
$decoded_resource['description'] = $service['description'];
}
Expand Down
2 changes: 1 addition & 1 deletion application/models/Unavailabilities_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @author A.Tselegidis <[email protected]>
* @copyright Copyright (c) Alex Tselegidis
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
* @link http://easyunavailabilities.org
* @link https://easyappointments.org
* @since v1.0.0
* ---------------------------------------------------------------------------- */

Expand Down
6 changes: 6 additions & 0 deletions openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2022,6 +2022,8 @@ components:
format: float
currency:
type: string
color:
type: string
location:
type: string
description:
Expand All @@ -2040,6 +2042,7 @@ components:
duration: 30
price: 10
currency: USD
color: '#123456'
location: Test Street 1A, 12345 Some State, Some Place
description: This is a test service.
availabilitiesType: flexible
Expand All @@ -2057,6 +2060,8 @@ components:
type: number
currency:
type: string
color:
type: string
location:
type: string
description:
Expand All @@ -2074,6 +2079,7 @@ components:
duration: 30
price: 10
currency: USD
color: '#123456'
location: Test Street 1A, 12345 Some State, Some Place
description: This is a test service.
availabilitiesType: flexible
Expand Down