Class RelayController
- Namespace
- adas_core.Controllers
- Assembly
- adas-core.dll
[ApiController]
[Route("Relay")]
public class RelayController : ControllerBase
- Inheritance
-
RelayController
- Inherited Members
- Extension Methods
Constructors
RelayController(IOptions<RecordingSettings>, IRelayService, ILogger<RelayController>, IPointOfCareService)
public RelayController(IOptions<RecordingSettings> recordingSettings, IRelayService relayService, ILogger<RelayController> logger, IPointOfCareService pointOfCareService)
Parameters
recordingSettingsIOptions<RecordingSettings>relayServiceIRelayServiceloggerILogger<RelayController>pointOfCareServiceIPointOfCareService
Methods
CheckRelayStatus(int, string, string, int, string, int, string, string)
Checks the status of a relay device by building a relay configuration from the supplied parameters and delegating the status check to the relay service.
[HttpPost]
[AuthorizeRoles(PermissionEnum.RolesType.AuthAdmin)]
[Route("{id}/status")]
public IActionResult CheckRelayStatus(int id, string driver, string host, int port, string relayName, int total, string username, string password)
Parameters
idintThe relay number identifier used to select the specific relay.
driverstringThe driver type used to communicate with the relay.
hoststringThe host IP address of the relay device.
portintThe network port used to connect to the relay device.
relayNamestringThe name assigned to the relay configuration.
totalintThe total number of relays in the configuration.
usernamestringThe username used for relay authentication.
passwordstringThe password used for relay authentication.
Returns
- IActionResult
An IActionResult containing the relay status result returned by the relay service.
CheckSectionStatus()
Retrieves the status of point-of-care sections by querying the relay status for each configured box and its associated relays. Returns a 404 Not Found when no configurations are available, or a list containing the unit, bed, and status for each relay when configurations exist.
[HttpGet]
[AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
[Route("status")]
public Task<IActionResult> CheckSectionStatus()
Returns
- Task<IActionResult>
An IActionResult that is either a 404 Not Found when no configurations are found, or an HTTP 200 OK response containing a collection of objects with the unit name, bed, and relay status.
CreateRelay(Relay?)
Creates a new relay based on the provided request payload. Throws a bad request exception if the request body is missing required parameters.
[HttpPost]
[AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
public Task<IActionResult> CreateRelay(Relay? request)
Parameters
requestRelayThe relay data to create, supplied in the request body.
Returns
- Task<IActionResult>
An IActionResult containing the created relay.
Exceptions
- BadRequestException
Thrown when the
requestis null.
GetPaginatedUnits(PaginationFilter, bool)
Retrieves a paginated list of relays based on the provided pagination filter.
[HttpPost("paginated")]
[AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
public Task<IActionResult> GetPaginatedUnits(PaginationFilter request, bool withPoCs)
Parameters
requestPaginationFilterThe pagination filter containing the paging parameters.
withPoCsboolFlag indicating whether to include related point of contact data in the response.
Returns
- Task<IActionResult>
An IActionResult containing the paginated relays.
Exceptions
- BadRequestException
Thrown when the
requestis null.
ManualSwitch(string, string, string)
Manually switches a relay for a specific point of connection (POC) to a given status and type. Validates the input parameters and returns a bad request if the status, type, or POC identifier cannot be parsed; returns an internal server error if an unexpected exception occurs, otherwise returns a successful response.
[HttpPost]
[AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
[Route("manual/{status}")]
public IActionResult ManualSwitch(string status, string pocId, string type)
Parameters
statusstringThe desired relay status as a string, which is parsed into RelayEnum.Status.
pocIdstringThe identifier of the point of connection, which must be a valid ObjectId string.
typestringThe relay type as a string, which is parsed into RelayEnum.Type.
Returns
- IActionResult
An IActionResult indicating the outcome: BadRequestResult for invalid input, StatusCodeResult for internal server errors, or OkObjectResult with
falseon success.
PowerOff(int, string, string, int, string, int, string, string?)
Powers off a relay identified by the given id using the provided relay configuration parameters. On failure to power off the relay, returns an Internal Server Error status; otherwise returns OK with a false result.
[HttpPost]
[AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
[Route("{id}/power/off")]
public IActionResult PowerOff(int id, string driver, string host, int port, string relayName, int total, string username, string? password)
Parameters
idintThe identifier of the relay to power off.
driverstringThe relay driver type to use for the operation.
hoststringThe host address of the relay device.
portintThe port number used to communicate with the relay device.
relayNamestringThe name assigned to the relay.
totalintThe total number of relays managed by the device.
usernamestringThe username used for relay authentication.
passwordstringThe optional password used for relay authentication.
Returns
- IActionResult
An IActionResult indicating the outcome: Ok with a false value on success, or an Internal Server Error status if the power off operation fails.
PowerOffPoC(PowerActionRequest)
Powers off the relay configuration for the specified unit, point of care, and bed by delegating the operation to the relay service.
[HttpPost]
[AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
[Route("powerOff")]
public Task<IActionResult> PowerOffPoC(PowerActionRequest action)
Parameters
actionPowerActionRequestThe power action request containing the unit identifier, point of care identifier, and bed information.
Returns
- Task<IActionResult>
An IActionResult representing the result of the power off operation.
PowerOn(int, string, string, int, string, int, string, string?)
Powers on the relay identified by the specified id using the provided connection configuration. Returns HTTP 200 with a success indicator when the relay is powered on, or HTTP 500 if the relay service throws an exception.
[HttpPost]
[AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
[Route("{id}/power/on")]
public IActionResult PowerOn(int id, string driver, string host, int port, string relayName, int total, string username, string? password)
Parameters
idintThe identifier of the relay to power on.
driverstringThe relay driver to use for the connection.
hoststringThe host address of the relay device.
portintThe port number used to connect to the relay device.
relayNamestringThe name assigned to the relay.
totalintThe total number of relays managed by the device.
usernamestringThe username used to authenticate with the relay device.
passwordstringThe optional password used to authenticate with the relay device.
Returns
- IActionResult
An IActionResult containing HTTP 200 with a success value on success, or HTTP 500 if the relay service fails.
PowerOnPoC(PowerActionRequest)
Handles a power-on request for a Point of Care (PoC) device by delegating to the shared power action pipeline and turning on the configured relay for the specified unit, point of care, and bed.
[HttpPost]
[AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
[Route("powerOn")]
public Task<IActionResult> PowerOnPoC(PowerActionRequest action)
Parameters
actionPowerActionRequestThe request payload containing the identifiers of the unit, point of care, and bed to power on.
Returns
- Task<IActionResult>
An IActionResult representing the result of the power-on operation.
UpdateRelay(Relay, string)
Updates an existing relay identified by the specified id with the provided relay data.
[HttpPut("{id}")]
[AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
public Task<IActionResult> UpdateRelay(Relay relay, string id)
Parameters
relayRelayThe relay data to apply to the existing record.
idstringThe identifier of the relay to update, expected to be a valid ObjectId.
Returns
- Task<IActionResult>
An IActionResult containing the updated relay when the operation succeeds.
Exceptions
- BadRequestException
Thrown when the provided
idcannot be parsed as a valid ObjectId.