feat: doc pages, finished refactor of ingress

This commit is contained in:
Per Stark
2025-01-05 23:20:34 +01:00
parent 71063a18af
commit b2eb4858ad
18 changed files with 232 additions and 82 deletions

View File

@@ -1,13 +1,10 @@
use crate::{
error::{ApiError, AppError},
ingress::types::{
ingress_input::{create_ingress_objects, IngressInput},
ingress_object,
},
ingress::types::ingress_input::{create_ingress_objects, IngressInput},
server::AppState,
storage::types::{file_info::FileInfo, user::User},
};
use axum::{extract::State, http::StatusCode, response::IntoResponse, Extension, Json};
use axum::{extract::State, http::StatusCode, response::IntoResponse, Extension};
use axum_typed_multipart::{FieldData, TryFromMultipart, TypedMultipart};
use futures::{future::try_join_all, TryFutureExt};
use tempfile::NamedTempFile;
@@ -31,7 +28,7 @@ pub async fn ingress_data(
info!("Received input: {:?}", input);
let file_infos = try_join_all(input.files.into_iter().map(|file| {
FileInfo::new(file, &state.surreal_db_client, &user.id).map_err(|e| AppError::from(e))
FileInfo::new(file, &state.surreal_db_client, &user.id).map_err(AppError::from)
}))
.await?;

View File

@@ -0,0 +1,31 @@
use axum::{extract::State, response::IntoResponse};
use axum_session_auth::AuthSession;
use axum_session_surreal::SessionSurrealPool;
use surrealdb::{engine::any::Any, Surreal};
use crate::{
error::HtmlError,
page_data,
server::{routes::html::render_template, AppState},
storage::types::user::User,
};
page_data!(IndexData, "documentation/index.html", {
user: Option<User>
});
pub async fn show_documentation_index(
State(state): State<AppState>,
auth: AuthSession<User, String, SessionSurrealPool<Any>, Surreal<Any>>,
) -> Result<impl IntoResponse, HtmlError> {
let output = render_template(
IndexData::template_name(),
IndexData {
user: auth.current_user,
},
state.templates.clone(),
)
.map_err(|e| HtmlError::from_template_error(e, state.templates.clone()))?;
Ok(output.into_response())
}

View File

@@ -0,0 +1 @@
pub mod index;

View File

@@ -76,7 +76,7 @@ pub async fn process_ingress_form(
},
user.id.as_str(),
)
.map_err(|e| HtmlError::new(AppError::from(e), state.templates.clone()))?;
.map_err(|e| HtmlError::new(e, state.templates.clone()))?;
let futures: Vec<_> = ingress_objects
.into_iter()
@@ -86,9 +86,7 @@ pub async fn process_ingress_form(
try_join_all(futures)
.await
.map_err(AppError::from)
.map_err(|e| HtmlError::new(AppError::from(e), state.templates.clone()))?;
// Process the ingress (implement your logic here)
.map_err(|e| HtmlError::new(e, state.templates.clone()))?;
Ok(Html("SuccessBRO!").into_response())
// Ok((HxRedirect::from(Uri::from_static("/")), StatusCode::OK).into_response())
}

View File

@@ -4,6 +4,7 @@ use axum::response::Html;
use minijinja_autoreload::AutoReloader;
pub mod account;
pub mod documentation;
pub mod gdpr;
pub mod index;
pub mod ingress;