ApiController
ApiController is a Laravel controller that handles API requests for the HRC (Horse Racing Club) module. This controller is located at VaahCms\Modules\HRC\Http\Controllers\Api\ApiController. It is responsible for generating tokens, initializing horses and training records.
Properties
ApiController has the following properties:
$api_view_path: a string that holds the path to the views directory for this controller$api_view_layout: a string that holds the name of the layout view file for this controller$api_authentication: a string that holds the content of the authorization.md file
Methods
__construct()
This method sets the values of $api_view_path, $api_view_layout, and $api_authentication properties.
getMarkdownContent($file)
Description
This Laravel controller method returns the contents of a Markdown file located at the specified path.
Request Format
The method takes a single parameter $file which is a string representing the name of the Markdown file to retrieve.
Response Format
The method returns a string containing the contents of the requested Markdown file.
getToken(Request $request)
Description
This method generates an API token for the authenticated user if the user is a super-administrator.
Request Format
{
"email": "string",
"password": "string"
}Response Format
{
"status": "success",
"data": {
"api_token": "string"
}
}Request Body Parameters
| Parameter | Type | Description |
|---|---|---|
email | string | The email address of the user |
password | string | The password of the user |
Response Parameters
| Parameter | Type | Description |
|---|---|---|
status | string | The status of the request (success or failed) |
errors | array | An array of error messages, if any |
data.api_token | string | The API token generated for the user |
initialize(Request $request)
Description
This method initializes the training process for a horse and creates a training record.
Request Format
{
"horse_rfid": "string|required",
"time": "string",
"device_time": "string"
}Response Format
{
"status": "string",
"errors": "array",
"help": "string",
"data": {
"training_record_id": "integer",
"training_center_id": "integer|null",
"training_center_name": "string|null",
"horse_id": "integer",
"horse_name": "string",
"fauna_collection_name": "string"
}
}Request Body Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
horse_rfid | string | Yes | The RFID of the horse |
time | string | No | The time of the training in the format "Y-m-d H:i:s" |
device_time | string | No | The device time of the training in the format "Y-m-d H:i:s" |
Response Parameters
| Parameter | Type | Description |
|---|---|---|
status | string | The status of the request (success or failed) |
errors | array | An array of error messages, if any |
help | string | The URL of the API help page |
data.training_record_id | integer | The ID of the created training record |
data.training_center_id | integer\null | The ID of the training center associated with the horse, if any |
data.training_center_name | string\null | The name of the training center associated with the horse, if any |
data.horse_id | integer | The ID of the horse |
data.horse_name | string | The name of the horse |
data.fauna_collection_name | string | The name of the Fauna collection associated with the training record |
Please note that the time and device_time parameters are optional, and at least one of them should be provided. If neither time nor device_time is provided, the current timestamp will be used as the training time.
syncTrainingData($training_record)
Description
This method synchronizes the training data for a training record with FaunaDB.
Request Format
{
"training_record": "object"
}Response Format
{
"status": "success",
"data": {
"fauna_collection_name": "string"
}
}Request Body Parameters
| Parameter | Type | Description |
|---|---|---|
training_record | object | The training record object |
Response Parameters
| Parameter | Type | Description |
|---|---|---|
status | string | The status of the request (success or failed) |
errors | array | An array of error messages, if any |
data.fauna_collection_name | string | The name of the Fauna collection associated with the training record |
initializeHelp(Request $request)
Description
This method returns the documentation for initializing a process.
Request Format
None
Response Format
{
"status": "success",
"data": {
"title": "string",
"endpoint": "string",
"type": "string",
"markdown": "string"
}
}Request Body Parameters
None
Response Parameters
| Parameter | Type | Description |
|---|---|---|
status | string | The status of the request (success or failed) |
errors | array | An array of error messages, if any |
data.title | string | The title of the documentation |
data.endpoint | string | The endpoint URL for initializing |
data.type | string | The HTTP method type for the request |
data.markdown | string | The Markdown content for the documentation |
getHorseByRfid($rfid)
Description
This method retrieves a horse record from the database by its RFID.
Request Format
{
"rfid": "string"
}Response Format
{
"status": "success",
"data": {
"id": "integer",
"name": "string",
"rfid": "string",
"birthdate": "date",
"gender": "string",
"breed": "string",
"color": "string",
"markings": "string",
"sire_name": "string",
"sire_rfid": "string",
"dam_name": "string",
"dam_rfid": "string",
"created_at": "datetime",
"updated_at": "datetime"
}
}Request Parameters
| Parameter | Type | Description |
|---|---|---|
rfid | string | The RFID of the horse to retrieve |
Response Parameters
| Parameter | Type | Description |
|---|---|---|
status | string | The status of the request (success or failed) |
errors | array | An array of error messages, if any |
data.id | integer | The ID of the horse record |
data.name | string | The name of the horse |
data.rfid | string | The RFID of the horse |
data.birthdate | date | The birthdate of the horse |
data.gender | string | The gender of the horse |
data.breed | string | The breed of the horse |
data.color | string | The color of the horse |
data.markings | string | Any markings on the horse |
data.sire_name | string | The name of the sire of the horse |
data.sire_rfid | string | The RFID of the sire of the horse |
data.dam_name | string | The name of the dam of the horse |
data.dam_rfid | string | The RFID of the dam of the horse |
data.created_at | datetime | The date and time the horse record was created |
data.updated_at | datetime | The date and time the horse record was last updated |
send(Request $request)
Description
This method sends data related to an EHM (Equine Health Monitoring) device to a backend controller and inserts the data into the database.
Request Format
{
"eq_training_record_id": "integer",
"ehm_id": "integer",
"horse_rfid": "string",
"horse_id": "integer",
"horse_name": "string",
"race_course_id": "integer",
"race_course_name": "string",
"heart_rate": "integer",
"step_counter": "integer",
"speed": "float",
"latitude": "float",
"longitude": "float",
"battery_voltage": "float"
}Response Format
{
"status": "success",
"data": {
"pusher": "object",
"db": "object"
}
}Request Parameters
| Parameter | Type | Description |
|---|---|---|
eq_training_record_id | integer | The ID of the EQ training record |
ehm_id | integer | The ID of the EHM device |
horse_rfid | string | The RFID of the horse |
horse_id | integer | The ID of the horse |
horse_name | string | The name of the horse |
race_course_id | integer | The ID of the race course |
race_course_name | string | The name of the race course |
heart_rate | integer | The heart rate of the horse |
step_counter | integer | The step count of the horse |
speed | float | The speed of the horse |
latitude | float | The latitude of the horse's location |
longitude | float | The longitude of the horse's location |
battery_voltage | float | The voltage of the EHM device's battery |
Response Parameters
| Parameter | Type | Description |
|---|---|---|
status | string | The status of the request (success or failed) |
errors | array | An array of error messages, if any |
data.pusher | object | The result of the Pusher API call |
data.db | object | The result of the database insertion |
insert($inputs)
Description
This method inserts data into the database using the provided inputs.
Request Format
{
"inputs": "object"
}Response Format
{
"status": "success",
"data": {
"ehm_data": "object"
}
}Request Body Parameters
| Parameter | Type | Description |
|---|---|---|
inputs | object | The input object containing data to be inserted into the database |
Response Parameters
| Parameter | Type | Description |
|---|---|---|
status | string | The status of the request (success or failed) |
errors | array | An array of error messages, if any |
data.ehm_data | object | The EHM data that was inserted into the database |
webhookSend(Request $request)
Description
This method stores the received request data from a webhook in a local JSON file.
Request Format
{
"request": "object"
}Request Parameters
| Parameter | Type | Description |
|---|---|---|
request | object | The webhook request object |
syncDataFromFauna(Request $request)
Description
This method fetches and synchronizes data from a FaunaDB collection with the training record.
Request Format
{
"training_record_id": "string",
"size": "string",
"no_of_data_to_fetch": "string"
}Response Format
{
"status": "success",
"data": {
"fauna_collection_name": "string"
}
}Request Parameters
| Parameter | Type | Description |
|---|---|---|
training_record_id | string | The ID of the training record |
size | string | The size of the data to fetch |
no_of_data_to_fetch | string | The number of data records to fetch from FaunaDB (optional) |
Response Parameters
| Parameter | Type | Description |
|---|---|---|
status | string | The status of the request (success or failed) |
errors | array | An array of error messages, if any |
data.fauna_collection_name | string | The name of the Fauna collection associated with the training record |
getMarkers(Request $request)
Description
This method retrieves the markers associated with a horse for a training centre.
Request Format
{
"eq_horse_rfid": "string"
}Response Format
{
"status": "success",
"data": {
"markers": "array",
"MAP_CONFIGS": {
"UPPER_LATITUDE": "string",
"LOWER_LATITUDE": "string"
}
}
}Request Body Parameters
| Parameter | Type | Description |
|---|---|---|
eq_horse_rfid | string | The RFID of the horse |
Response Parameters
| Parameter | Type | Description |
|---|---|---|
status | string | The status of the request (success or failed) |
errors | array | An array of error messages, if any |
data.markers | array | An array of markers associated with the horse |
data.MAP_CONFIGS.UPPER_LATITUDE | string | The upper latitude of the map |
data.MAP_CONFIGS.LOWER_LATITUDE | string | The lower latitude of the map |
Dependencies
ApiController has the following dependencies:
- Carbon
- Illuminate\Http\Request
- Illuminate\Http\Response
- Illuminate\Routing\Controller
- GuzzleHttp\Client
- Illuminate\Support\Facades\Schema
- VaahCms\Modules\HRC\Http\Controllers\Backend\BackendController
- VaahCms\Modules\HRC\Libraries\GoogleMap
- VaahCms\Modules\HRC\Libraries\HrcHelper
- VaahCms\Modules\HRC\Models\EqEhmData
- VaahCms\Modules\HRC\Models\EqHorse
- VaahCms\Modules\HRC\Models\EqMap
- VaahCms\Modules\HRC\Models\EqTrainingCentre
- VaahCms\Modules\HRC\Models\EqTrainingRecord
- VaahCms\Modules\HRC\Jobs\SyncTrainingData
- WebReinvent\VaahCms\Entities\User
Middleware
ApiController does not use any middleware.**
- Properties
- Methods
- __construct()
- getMarkdownContent($file)
- getToken(Request $request)
- initialize(Request $request)
- syncTrainingData($training_record)
- initializeHelp(Request $request)
- getHorseByRfid($rfid)
- send(Request $request)
- insert($inputs)
- webhookSend(Request $request)
- syncDataFromFauna(Request $request)
- getMarkers(Request $request)
- Dependencies
- Middleware