mirror of
https://github.com/perstarkse/minne.git
synced 2026-03-31 14:43:20 +02:00
email wip
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
use crate::rabbitmq::consumer::RabbitMQConsumer;
|
||||
use crate::rabbitmq::publisher::RabbitMQProducer;
|
||||
use crate::storage::db::SurrealDbClient;
|
||||
use crate::utils::mailer::Mailer;
|
||||
use minijinja_autoreload::AutoReloader;
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -14,4 +15,5 @@ pub struct AppState {
|
||||
pub surreal_db_client: Arc<SurrealDbClient>,
|
||||
pub openai_client: Arc<async_openai::Client<async_openai::config::OpenAIConfig>>,
|
||||
pub templates: Arc<AutoReloader>,
|
||||
pub mailer: Arc<Mailer>,
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use axum::{extract::State, http::StatusCode, response::IntoResponse};
|
||||
use tracing::info;
|
||||
use minijinja::context;
|
||||
use tracing::{info, Instrument};
|
||||
|
||||
use crate::{error::ApiError, server::AppState};
|
||||
|
||||
@@ -12,6 +13,10 @@ pub async fn queue_length_handler(
|
||||
|
||||
info!("Queue length: {}", queue_length);
|
||||
|
||||
state
|
||||
.mailer
|
||||
.send_email_verification("per@starks.cloud", "1001010", &state.templates)?;
|
||||
|
||||
// Return the queue length with a 200 OK status
|
||||
Ok((StatusCode::OK, queue_length.to_string()))
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ use crate::{
|
||||
storage::types::user::User,
|
||||
};
|
||||
|
||||
page_data!(IndexData, {
|
||||
page_data!(IndexData, "index.html", {
|
||||
queue_length: u32,
|
||||
});
|
||||
|
||||
@@ -25,7 +25,9 @@ pub async fn index_handler(
|
||||
|
||||
let queue_length = state.rabbitmq_consumer.get_queue_length().await?;
|
||||
|
||||
let output = render_template("index.html", IndexData { queue_length }, state.templates)?;
|
||||
let data = IndexData { queue_length };
|
||||
|
||||
let output = render_template(IndexData::template_name(), data, state.templates)?;
|
||||
|
||||
Ok(output)
|
||||
}
|
||||
|
||||
@@ -7,6 +7,10 @@ pub mod auth;
|
||||
pub mod index;
|
||||
pub mod search_result;
|
||||
|
||||
pub trait PageData {
|
||||
fn template_name() -> &'static str;
|
||||
}
|
||||
|
||||
pub fn render_template<T>(
|
||||
template_name: &str,
|
||||
context: T,
|
||||
@@ -44,12 +48,19 @@ where
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! page_data {
|
||||
($name:ident, {$($(#[$attr:meta])* $field:ident: $ty:ty),*$(,)?}) => {
|
||||
($name:ident, $template_name:expr, {$($(#[$attr:meta])* $field:ident: $ty:ty),*$(,)?}) => {
|
||||
use serde::{Serialize, Deserialize};
|
||||
use $crate::server::routes::html::PageData;
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct $name {
|
||||
$($(#[$attr])* pub $field: $ty),*
|
||||
}
|
||||
|
||||
impl PageData for $name {
|
||||
fn template_name() -> &'static str {
|
||||
$template_name
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user