feat: util script to generate handler
This commit is contained in:
parent
517ab10942
commit
579f482205
1 changed files with 64 additions and 0 deletions
64
utils/gen_handler.sh
Executable file
64
utils/gen_handler.sh
Executable file
|
@ -0,0 +1,64 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
help() {
|
||||||
|
echo "Usage: gen_handler.sh <handler partial name> <handler route> <payload struct partial name>"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
run() {
|
||||||
|
|
||||||
|
echo "cfg.service($1_ui_handler);"
|
||||||
|
echo "cfg.service($1_form_submission_handler);"
|
||||||
|
|
||||||
|
|
||||||
|
echo "
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
|
#[get(\"$2\")]
|
||||||
|
#[tracing::instrument(name = \"login UI handler\", skip())]
|
||||||
|
async fn login_ui_handler() -> WebJsonRepsonse<impl Responder> {
|
||||||
|
const LOGIN_PAGE: &str = include_str!(\"./owner_login.html\");
|
||||||
|
|
||||||
|
Ok(HttpResponse::Ok()
|
||||||
|
.insert_header(ContentType::html())
|
||||||
|
.body(LOGIN_PAGE))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize)]
|
||||||
|
struct $3Payload {
|
||||||
|
password: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
|
#[post(\"$2\")]
|
||||||
|
#[tracing::instrument(
|
||||||
|
name = \"Login form submission handler\"
|
||||||
|
skip(id, req, payload, identity_cqrs_exec)
|
||||||
|
)]
|
||||||
|
async fn login_form_submission_handler(
|
||||||
|
identity_cqrs_exec: types::WebIdentityCqrsExec,
|
||||||
|
req: HttpRequest,
|
||||||
|
id: Identity,
|
||||||
|
payload: web::Form<$3Payload>,
|
||||||
|
) -> WebJsonRepsonse<impl Responder> {
|
||||||
|
let store = \"\";
|
||||||
|
|
||||||
|
Ok(HttpResponse::Ok().json(store))
|
||||||
|
}
|
||||||
|
"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if [ -z $1 ]
|
||||||
|
then
|
||||||
|
help
|
||||||
|
elif [ -z $2 ]
|
||||||
|
then
|
||||||
|
help
|
||||||
|
elif [ -z $3 ]
|
||||||
|
then
|
||||||
|
help
|
||||||
|
else
|
||||||
|
run $1 $2 $3 | wl-copy
|
||||||
|
run $1 $2 $3
|
||||||
|
fi
|
Loading…
Add table
Reference in a new issue