83 lines
1.5 KiB
Bash
83 lines
1.5 KiB
Bash
|
#!/bin/bash
|
||
|
|
||
|
help() {
|
||
|
echo "Usage: generate_actix_handler.sh
|
||
|
<domain name in Sentence case>
|
||
|
<function name>
|
||
|
<route path>
|
||
|
<template struct name>
|
||
|
<function name in camelCase for payload struct>"
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
# $1: domain in sentence case
|
||
|
# $2: function_name
|
||
|
# $3: route
|
||
|
# $4: template struct name
|
||
|
# $5: function name in camelcase for payload stroct
|
||
|
run() {
|
||
|
echo "
|
||
|
// service config
|
||
|
|
||
|
cfg.service(${2}_ui_handler);
|
||
|
cfg.service(${2}_form_submission_handler);
|
||
|
|
||
|
// $2 handlers
|
||
|
|
||
|
#[allow(clippy::too_many_arguments)]
|
||
|
#[get(\"$3\")]
|
||
|
#[tracing::instrument(name = \"$2 UI handler\", skip())]
|
||
|
async fn ${2}_ui_handler() -> WebJsonRepsonse<impl Responder> {
|
||
|
use web_ui::${1,,}::$2::*;
|
||
|
|
||
|
let page = $4::page();
|
||
|
|
||
|
Ok(HttpResponse::Ok()
|
||
|
.insert_header(ContentType::html())
|
||
|
.body(page))
|
||
|
}
|
||
|
|
||
|
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize)]
|
||
|
struct ${5}Payload {
|
||
|
password: String,
|
||
|
}
|
||
|
|
||
|
#[allow(clippy::too_many_arguments)]
|
||
|
#[post(\"$3\")]
|
||
|
#[tracing::instrument(
|
||
|
name = \"$2 form submission handler\"
|
||
|
skip(id, req, payload, ${1,,}_cqrs_exec)
|
||
|
)]
|
||
|
async fn ${2}_form_submission_handler(
|
||
|
${1,,}_cqrs_exec: types::Web${1}CqrsExec,
|
||
|
req: HttpRequest,
|
||
|
id: Identity,
|
||
|
payload: web::Form<$5Payload>,
|
||
|
) -> 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
|
||
|
elif [ -z $4 ]
|
||
|
then
|
||
|
help
|
||
|
elif [ -z $5 ]
|
||
|
then
|
||
|
help
|
||
|
else
|
||
|
run $1 $2 $3 $4 $5 | wl-copy
|
||
|
run $1 $2 $3 $4 $5
|
||
|
fi
|