36 lines
859 B
Rust
36 lines
859 B
Rust
use askama::Template;
|
|
use askama_axum::IntoResponse;
|
|
use axum::{extract::State, response::Redirect, Form};
|
|
use serde::Deserialize;
|
|
|
|
use crate::{
|
|
http::error::AppError,
|
|
node::stack::{compose, operation},
|
|
AppState,
|
|
};
|
|
|
|
#[derive(Template)]
|
|
#[template(path = "stack/new-form.html")]
|
|
struct CreateTemplate {}
|
|
|
|
#[derive(Deserialize)]
|
|
pub(super) struct CreateStackForm {
|
|
source: String,
|
|
}
|
|
|
|
pub(super) async fn create_stack(
|
|
State(state): State<AppState>,
|
|
Form(form): Form<CreateStackForm>,
|
|
) -> Result<Redirect, AppError> {
|
|
// Make sure body is is ok
|
|
let name = compose::check(&state.arion_bin, &form.source).await?;
|
|
|
|
operation::create(state.repository, &name, &form.source).await?;
|
|
|
|
Ok(Redirect::to(format!("/stack/{}/", name).as_str()))
|
|
}
|
|
|
|
pub(super) async fn new_stack_page() -> impl IntoResponse {
|
|
CreateTemplate {}
|
|
}
|