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
ParameterTypeDescription
emailstringThe email address of the user
passwordstringThe password of the user
Response Parameters
ParameterTypeDescription
statusstringThe status of the request (success or failed)
errorsarrayAn array of error messages, if any
data.api_tokenstringThe 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
ParameterTypeRequiredDescription
horse_rfidstringYesThe RFID of the horse
timestringNoThe time of the training in the format "Y-m-d H:i:s"
device_timestringNoThe device time of the training in the format "Y-m-d H:i:s"
Response Parameters
ParameterTypeDescription
statusstringThe status of the request (success or failed)
errorsarrayAn array of error messages, if any
helpstringThe URL of the API help page
data.training_record_idintegerThe ID of the created training record
data.training_center_idinteger\nullThe ID of the training center associated with the horse, if any
data.training_center_namestring\nullThe name of the training center associated with the horse, if any
data.horse_idintegerThe ID of the horse
data.horse_namestringThe name of the horse
data.fauna_collection_namestringThe 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
ParameterTypeDescription
training_recordobjectThe training record object
Response Parameters
ParameterTypeDescription
statusstringThe status of the request (success or failed)
errorsarrayAn array of error messages, if any
data.fauna_collection_namestringThe 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
ParameterTypeDescription
statusstringThe status of the request (success or failed)
errorsarrayAn array of error messages, if any
data.title stringThe title of the documentation
data.endpointstringThe endpoint URL for initializing
data.typestringThe HTTP method type for the request
data.markdownstringThe 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
ParameterTypeDescription
rfidstringThe RFID of the horse to retrieve
Response Parameters
ParameterTypeDescription
statusstringThe status of the request (success or failed)
errorsarrayAn array of error messages, if any
data.idintegerThe ID of the horse record
data.namestringThe name of the horse
data.rfidstringThe RFID of the horse
data.birthdatedateThe birthdate of the horse
data.genderstringThe gender of the horse
data.breedstringThe breed of the horse
data.colorstringThe color of the horse
data.markingsstringAny markings on the horse
data.sire_namestringThe name of the sire of the horse
data.sire_rfidstringThe RFID of the sire of the horse
data.dam_namestringThe name of the dam of the horse
data.dam_rfidstringThe RFID of the dam of the horse
data.created_atdatetimeThe date and time the horse record was created
data.updated_atdatetimeThe 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
ParameterTypeDescription
eq_training_record_idintegerThe ID of the EQ training record
ehm_idintegerThe ID of the EHM device
horse_rfidstringThe RFID of the horse
horse_idintegerThe ID of the horse
horse_namestringThe name of the horse
race_course_idintegerThe ID of the race course
race_course_namestringThe name of the race course
heart_rateintegerThe heart rate of the horse
step_counterintegerThe step count of the horse
speedfloatThe speed of the horse
latitudefloatThe latitude of the horse's location
longitudefloatThe longitude of the horse's location
battery_voltagefloatThe voltage of the EHM device's battery
Response Parameters
ParameterTypeDescription
statusstringThe status of the request (success or failed)
errorsarrayAn array of error messages, if any
data.pusherobjectThe result of the Pusher API call
data.dbobjectThe 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
ParameterTypeDescription
inputsobjectThe input object containing data to be inserted into the database
Response Parameters
ParameterTypeDescription
statusstringThe status of the request (success or failed)
errorsarrayAn array of error messages, if any
data.ehm_dataobjectThe 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
ParameterTypeDescription
requestobjectThe 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
ParameterTypeDescription
training_record_idstringThe ID of the training record
sizestringThe size of the data to fetch
no_of_data_to_fetchstringThe number of data records to fetch from FaunaDB (optional)
Response Parameters
ParameterTypeDescription
statusstringThe status of the request (success or failed)
errorsarrayAn array of error messages, if any
data.fauna_collection_namestringThe 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
ParameterTypeDescription
eq_horse_rfidstringThe RFID of the horse
Response Parameters
ParameterTypeDescription
statusstringThe status of the request (success or failed)
errorsarrayAn array of error messages, if any
data.markersarrayAn array of markers associated with the horse
data.MAP_CONFIGS.UPPER_LATITUDEstringThe upper latitude of the map
data.MAP_CONFIGS.LOWER_LATITUDEstringThe 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.**