Skip to content
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
31 changes: 22 additions & 9 deletions application/controllers/api/v1/Availabilities_api_v1.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ public function __construct()
}

/**
* Generate the available hours based on the selected date, service and provider.
* Generate the available dates and hours based on the selected date, service and provider.
*
* This resource requires the following query parameters:
*
* - serviceId
* - providerI
* - providerId
* - date
*
* Based on those values it will generate the available hours, just like how the booking page works.
Expand All @@ -58,19 +58,32 @@ public function get()
$service_id = request('serviceId');

$date = request('date');

if ( ! $date)
{
$date = date('Y-m-d');
}
if(substr_count($date, '-') == 1)
$date .= '-01';
$date = new DateTime($date);

$provider = $this->providers_model->find($provider_id);

$service = $this->services_model->find($service_id);

$available_hours = $this->availability->get_available_hours($date, $service, $provider);
$number_of_days_in_month = (int)$date->format('t');
$available_dates = [];

for ($i = 1; $i <= $number_of_days_in_month; $i++)
{
$current_date = new DateTime($date->format('Y-m') . '-' . $i);

$available_hours = $this->availability->get_available_hours(
$current_date->format('Y-m-d'),
$service,
$provider
);

if ( !empty($available_hours) )
$available_dates[$current_date->format('Y-m-d')] = $available_hours;
}

json_response($available_hours);
json_response($available_dates);
}
catch (Throwable $e)
{
Expand Down
6 changes: 4 additions & 2 deletions openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,18 @@ paths:
get:
tags:
- availabilities
summary: Gets availability
summary: Gets availability dates
parameters:
- name: providerId
in: query
schema:
type: integer
required: true
- name: serviceId
in: query
schema:
type: integer
required: true
- name: date
in: query
schema:
Expand Down Expand Up @@ -1721,7 +1723,7 @@ components:
Availabilities:
type: array
items:
type: string
type: object
AppointmentRecord:
type: object
properties:
Expand Down