using Invercargill; using Invercargill.DataStructures; using Inversion; using Astralis; namespace Statum { /** * `/_statum/action/{guid}` — the single endpoint that dispatches every * Statum action. * * The GUID is resolved by {@link ActionRegistry} to the action's type; the * scoped {@link StatumAction} instance is then resolved and its * {@link StatumAction.handle_request} does the per-request work (resolve held * slots, decrypt `X-Statum-Private`, parse the form, run {@link * StatumAction.handle}, render directives). Registered for all common verbs * so an action may be authored with whichever HTTP method suits it. * * This mirrored Spry 0.1's single `ComponentEndpoint`/`PathProvider` * model; both classes were removed in Spry 0.2. */ public class ActionEndpoint : Object, Endpoint { private ActionRegistry action_registry = inject(); private Inversion.Scope scope = inject(); public async HttpResult handle_request(HttpContext http_context, RouteContext route_context) throws GLib.Error { var guid = route_context.mapped_parameters.get_or_default("guid"); if (guid == null) { return new HttpStringResult("Missing action id", StatusCode.BAD_REQUEST); } var type = action_registry.resolve((!)guid); if (type == null || !((!)type).is_a(typeof(StatumAction))) { return new HttpStringResult("No such action", StatusCode.NOT_FOUND); } var action = scope.resolve_type((!)type); return yield ((StatumAction) action).handle_request(http_context, route_context); } } }