| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- using Astralis;
- using Invercargill;
- using Inversion;
- using Spry;
- /**
- * AuroraActionEndpoint - HTTP endpoint that triggers aurora actions
- *
- * Handles POST requests to trigger aurora actions, which then broadcast
- * updates via the AuroraSseEndpoint to all connected SSE clients.
- */
- public class AuroraActionEndpoint : Object, Endpoint {
-
- private AuroraSseEndpoint aurora_sse;
-
- public AuroraActionEndpoint(AuroraSseEndpoint aurora_sse) {
- this.aurora_sse = aurora_sse;
- }
-
- public async HttpResult handle_request(HttpContext http_context, RouteContext route_context) throws Error {
- // Get action from route parameter
- string? action = null;
- route_context.mapped_parameters.try_get("action", out action);
-
- switch (action ?? "") {
- case "boost":
- aurora_sse.boost_solar_wind.begin();
- break;
- case "calm":
- aurora_sse.calm.begin();
- break;
- case "shift":
- aurora_sse.shift_colors.begin();
- break;
- case "wave":
- aurora_sse.add_wave.begin();
- break;
- default:
- return new HttpStringResult("{\"error\":\"Unknown action\"}", StatusCode.BAD_REQUEST)
- .set_header("Content-Type", "application/json");
- }
-
- return new HttpStringResult("{\"status\":\"ok\"}")
- .set_header("Content-Type", "application/json");
- }
- }
- /**
- * CounterActionEndpoint - HTTP endpoint that triggers counter actions
- *
- * Handles POST requests to trigger counter actions, which then broadcast
- * updates via the CounterSseEndpoint to all connected SSE clients.
- */
- public class CounterActionEndpoint : Object, Endpoint {
-
- private CounterSseEndpoint counter_sse;
-
- public CounterActionEndpoint(CounterSseEndpoint counter_sse) {
- this.counter_sse = counter_sse;
- }
-
- public async HttpResult handle_request(HttpContext http_context, RouteContext route_context) throws Error {
- // Get action from route parameter
- string? action = null;
- route_context.mapped_parameters.try_get("action", out action);
-
- switch (action ?? "") {
- case "increment":
- counter_sse.increment.begin();
- break;
- case "decrement":
- counter_sse.decrement.begin();
- break;
- case "reset":
- counter_sse.reset.begin();
- break;
- default:
- return new HttpStringResult("{\"error\":\"Unknown action\"}", StatusCode.BAD_REQUEST)
- .set_header("Content-Type", "application/json");
- }
-
- return new HttpStringResult("{\"status\":\"ok\"}")
- .set_header("Content-Type", "application/json");
- }
- }
|