src/lightspeed@framework@controller.erl

-module(lightspeed@framework@controller).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/lightspeed/framework/controller.gleam").
-export([html/2, text/2, json/2, redirect/2, not_found/1, internal_error/2, get_session/2, put_session/3, drop_session/2, get_flash/2, put_flash/3, clear_flash/1, halt/1]).

-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.

?MODULEDOC(" Controller-style response and session/flash helpers.\n").

-file("src/lightspeed/framework/controller.gleam", 7).
?DOC(" Write an HTML 200 response.\n").
-spec html(lightspeed@framework@http:conn(), binary()) -> lightspeed@framework@http:conn().
html(Conn, Body) ->
    lightspeed@framework@http:send(
        Conn,
        200,
        <<"text/html; charset=utf-8"/utf8>>,
        Body
    ).

-file("src/lightspeed/framework/controller.gleam", 12).
?DOC(" Write a text 200 response.\n").
-spec text(lightspeed@framework@http:conn(), binary()) -> lightspeed@framework@http:conn().
text(Conn, Body) ->
    lightspeed@framework@http:send(
        Conn,
        200,
        <<"text/plain; charset=utf-8"/utf8>>,
        Body
    ).

-file("src/lightspeed/framework/controller.gleam", 17).
?DOC(" Write a JSON 200 response.\n").
-spec json(lightspeed@framework@http:conn(), binary()) -> lightspeed@framework@http:conn().
json(Conn, Body) ->
    lightspeed@framework@http:send(Conn, 200, <<"application/json"/utf8>>, Body).

-file("src/lightspeed/framework/controller.gleam", 22).
?DOC(" Write a 302 redirect response with `location`.\n").
-spec redirect(lightspeed@framework@http:conn(), binary()) -> lightspeed@framework@http:conn().
redirect(Conn, To) ->
    _pipe = Conn,
    _pipe@1 = lightspeed@framework@http:set_status(_pipe, 302),
    _pipe@2 = lightspeed@framework@http:put_header(
        _pipe@1,
        <<"location"/utf8>>,
        To
    ),
    _pipe@3 = lightspeed@framework@http:put_header(
        _pipe@2,
        <<"content-type"/utf8>>,
        <<"text/plain; charset=utf-8"/utf8>>
    ),
    lightspeed@framework@http:set_body(_pipe@3, <<"redirect"/utf8>>).

-file("src/lightspeed/framework/controller.gleam", 31).
?DOC(" Write a 404 text response.\n").
-spec not_found(lightspeed@framework@http:conn()) -> lightspeed@framework@http:conn().
not_found(Conn) ->
    lightspeed@framework@http:send(
        Conn,
        404,
        <<"text/plain; charset=utf-8"/utf8>>,
        <<"not found"/utf8>>
    ).

-file("src/lightspeed/framework/controller.gleam", 36).
?DOC(" Write a 500 text response.\n").
-spec internal_error(lightspeed@framework@http:conn(), binary()) -> lightspeed@framework@http:conn().
internal_error(Conn, Reason) ->
    lightspeed@framework@http:send(
        Conn,
        500,
        <<"text/plain; charset=utf-8"/utf8>>,
        <<"internal error: "/utf8, Reason/binary>>
    ).

-file("src/lightspeed/framework/controller.gleam", 46).
?DOC(" Read one session key.\n").
-spec get_session(lightspeed@framework@http:conn(), binary()) -> gleam@option:option(binary()).
get_session(Conn, Key) ->
    lightspeed@framework@http:session(Conn, Key).

-file("src/lightspeed/framework/controller.gleam", 51).
?DOC(" Set one session key.\n").
-spec put_session(lightspeed@framework@http:conn(), binary(), binary()) -> lightspeed@framework@http:conn().
put_session(Conn, Key, Value) ->
    lightspeed@framework@http:put_session(Conn, Key, Value).

-file("src/lightspeed/framework/controller.gleam", 56).
?DOC(" Delete one session key.\n").
-spec drop_session(lightspeed@framework@http:conn(), binary()) -> lightspeed@framework@http:conn().
drop_session(Conn, Key) ->
    lightspeed@framework@http:drop_session(Conn, Key).

-file("src/lightspeed/framework/controller.gleam", 61).
?DOC(" Read one flash key.\n").
-spec get_flash(lightspeed@framework@http:conn(), binary()) -> gleam@option:option(binary()).
get_flash(Conn, Key) ->
    lightspeed@framework@http:flash(Conn, Key).

-file("src/lightspeed/framework/controller.gleam", 66).
?DOC(" Set one flash key.\n").
-spec put_flash(lightspeed@framework@http:conn(), binary(), binary()) -> lightspeed@framework@http:conn().
put_flash(Conn, Key, Value) ->
    lightspeed@framework@http:put_flash(Conn, Key, Value).

-file("src/lightspeed/framework/controller.gleam", 71).
?DOC(" Clear all flash entries.\n").
-spec clear_flash(lightspeed@framework@http:conn()) -> lightspeed@framework@http:conn().
clear_flash(Conn) ->
    lightspeed@framework@http:clear_flash(Conn).

-file("src/lightspeed/framework/controller.gleam", 76).
?DOC(" Halt connection processing.\n").
-spec halt(lightspeed@framework@http:conn()) -> lightspeed@framework@http:conn().
halt(Conn) ->
    lightspeed@framework@http:halt(Conn).