Medical Appointments API

ScheduleController extends BaseController
in package

Controller class for managing schedules.

Tags
OA\Tag

( name="Schedule", description="API Endpoints of Schedules" )

author

Luis Graciano contacto@luisgraciano.dev

Table of Contents

$path  : string
$routes  : array<string|int, mixed>
$path  : string
$routes  : array<string|int, mixed>
$scheduleService  : ScheduleService
__construct()  : mixed
ScheduleController constructor.
addApiRoutes()  : void
Create a RouteGroup for the controller and add the routes to it.
delete()  : ResponseInterface
Delete a schedule by id.
findByMedicalCenterId()  : ResponseInterface
Get a schedule by medical center id.
save()  : ResponseInterface
Save a schedule.
update()  : ResponseInterface
Update a schedule.
checkParams()  : void
Check the given parameters against the given schema.
makeJsonResponse()  : ResponseInterface
Create a JSON response with the given result and status code.
addRoutes()  : void
Add routes to the given group.

Properties

$path

public string $path

The path of the controller (e.g. /appointment).

$routes

public array<string|int, mixed> $routes

The routes for the controller. The routes should be an array of arrays with the following keys: method, path, handler.

$routes

protected array<string|int, mixed> $routes = [['method' => 'GET', 'path' => '/find-by-medical-center/{medical_center_id}', 'handler' => 'findByMedicalCenterId'], ['method' => 'POST', 'path' => '', 'handler' => 'save'], ['method' => 'PUT', 'path' => '', 'handler' => 'update'], ['method' => 'DELETE', 'path' => '/{id}', 'handler' => 'delete']]

The routes for the controller.

Methods

addApiRoutes()

Create a RouteGroup for the controller and add the routes to it.

public addApiRoutes(RouteCollectorProxy $group) : void
Parameters
$group : RouteCollectorProxy

The route group.

Tags
throws
Exception

If the controller does not have a path or routes property.

Return values
void

delete()

Delete a schedule by id.

public delete(ServerRequestInterface $request, ResponseInterface $response, array<string|int, mixed> $args) : ResponseInterface
Parameters
$request : ServerRequestInterface

The request object.

$response : ResponseInterface

The response object.

$args : array<string|int, mixed>

The arguments for the request.

Tags
OA\Delete

( path="/schedule/{id}", tags={"Schedule"}, summary="Delete a schedule", @OA\Parameter( name="id", in="path", description="Schedule id", required=true, @OA\Schema(type="integer") ), @OA\Response( response=200, description="Success", @OA\JsonContent( type="object", @OA\Property(property="success", type="boolean"), @OA\Property(property="message", type="string") ), ), @OA\Response(response=400, ref="#/components/responses/400"), @OA\Response(response=500, ref="#/components/responses/500") )

throws
BusinessValidationException

If the arguments are invalid.

throws
UnhandledException

If an error occurs while deleting the schedule.

Return values
ResponseInterface

The response object.

findByMedicalCenterId()

Get a schedule by medical center id.

public findByMedicalCenterId(ServerRequestInterface $request, ResponseInterface $response, array<string|int, mixed> $args) : ResponseInterface
Parameters
$request : ServerRequestInterface

The request object.

$response : ResponseInterface

The response object.

$args : array<string|int, mixed>

The arguments for the request.

Tags
OA\Get

( path="/schedule/find-by-medical-center/{medical_center_id}", tags={"Schedule"}, summary="Get a schedule by medical center id", @OA\Parameter( name="medical_center_id", in="path", description="Medical center id", required=true, @OA\Schema(type="integer") ), @OA\Response( response=200, description="Success", @OA\JsonContent(type="array", @OA\Items(ref="#/components/schemas/Schedule")) ), @OA\Response(response=400, ref="#/components/responses/400"), @OA\Response(response=404, ref="#/components/responses/404"), @OA\Response(response=500, ref="#/components/responses/500") )

throws
NotFoundException

If the schedule is not found.

throws
BusinessValidationException

If the arguments are invalid.

throws
UnhandledException

If an error occurs while finding the schedule.

Return values
ResponseInterface

The response object.

save()

Save a schedule.

public save(ServerRequestInterface $request, ResponseInterface $response, array<string|int, mixed> $args) : ResponseInterface
Parameters
$request : ServerRequestInterface

The request object.

$response : ResponseInterface

The response object.

$args : array<string|int, mixed>

The arguments for the request.

Tags
OA\Post

( path="/schedule", tags={"Schedule"}, summary="Create a schedule", @OA\RequestBody( required=true, description="Schedule object that needs to be added to the medical center", @OA\JsonContent(ref="#/components/schemas/Schedule") ), @OA\Response( response=200, description="Success", @OA\JsonContent(ref="#/components/schemas/Schedule") ), @OA\Response(response=400, ref="#/components/responses/400"), @OA\Response(response=500, ref="#/components/responses/500") )

throws
UnhandledException
throws
BusinessValidationException
throws
Exception
Return values
ResponseInterface

The response object.

update()

Update a schedule.

public update(ServerRequestInterface $request, ResponseInterface $response, array<string|int, mixed> $args) : ResponseInterface
Parameters
$request : ServerRequestInterface

The request object.

$response : ResponseInterface

The response object.

$args : array<string|int, mixed>

The arguments for the request.

Tags
OA\Put

( path="/schedule", tags={"Schedule"}, summary="Update a schedule", @OA\RequestBody( required=true, description="Schedule object that needs to be updated", @OA\JsonContent(ref="#/components/schemas/Schedule") ), @OA\Response( response=200, description="Success", @OA\JsonContent(ref="#/components/schemas/Schedule") ), @OA\Response(response=400, ref="#/components/responses/400"), @OA\Response(response=500, ref="#/components/responses/500") )

throws
BusinessValidationException

If the arguments are invalid.

throws
Exception

If an error occurs while updating the schedule.

Return values
ResponseInterface

The response object.

checkParams()

Check the given parameters against the given schema.

protected checkParams(array<string|int, mixed> $params, array<string|int, mixed> $schema) : void
Parameters
$params : array<string|int, mixed>

The parameters to check.

$schema : array<string|int, mixed>

The schema to check against. The schema should be an array of arrays with the following keys: type, required, not_blank, min_number, max_number, min_length, max_length, regex, properties, items. The type can be one of the following: integer, string, boolean, object, array.

Tags
throws
BusinessValidationException

If a validation error occurs.

Return values
void

makeJsonResponse()

Create a JSON response with the given result and status code.

protected makeJsonResponse(ResponseInterface $response[, mixed $result = null ][, int $status_code = 200 ]) : ResponseInterface
Parameters
$response : ResponseInterface

The PSR-7 response.

$result : mixed = null

The data to be included in the JSON response.

$status_code : int = 200

The HTTP status code for the response (default is 200).

Return values
ResponseInterface

The PSR-7 response with JSON data and appropriate headers.

addRoutes()

Add routes to the given group.

private addRoutes(RouteCollectorProxy $newGroup) : void
Parameters
$newGroup : RouteCollectorProxy

The route group.

Tags
throws
Exception

If the controller does not have a routes property or if a route is missing a method, path, or handler.

Return values
void

Search results