refactor: moved routes

This commit is contained in:
Per Stark
2024-11-23 12:19:45 +01:00
parent bd99b11e1a
commit 8df899dfdf
7 changed files with 31 additions and 6 deletions

View File

@@ -2,6 +2,6 @@ pub mod error;
pub mod ingress;
pub mod rabbitmq;
pub mod retrieval;
pub mod routes;
pub mod server;
pub mod storage;
pub mod utils;

1
src/server/mod.rs Normal file
View File

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

View File

@@ -1,3 +1,4 @@
pub mod file;
pub mod ingress;
pub mod query;
pub mod queue_length;

View File

@@ -0,0 +1,17 @@
use crate::storage::db::SurrealDbClient;
use axum::{http::StatusCode, response::IntoResponse, Extension, Json};
use serde::Deserialize;
use std::sync::Arc;
use tracing::{error, info};
#[derive(Debug, Deserialize)]
pub struct QueryInput {
query: String,
}
pub async fn query_handler(
Extension(db_client): Extension<Arc<SurrealDbClient>>,
Json(query): Json<QueryInput>,
) -> impl IntoResponse {
info!("Received input: {:?}", query);
}

View File

@@ -1,11 +1,14 @@
use axum::{http::StatusCode, response::{IntoResponse, Response}};
use axum::{
http::StatusCode,
response::{IntoResponse, Response},
};
use tracing::{error, info};
use crate::rabbitmq::{consumer::RabbitMQConsumer, RabbitMQConfig};
pub async fn queue_length_handler() -> Response {
info!("Getting queue length");
// Set up RabbitMQ config
let config = RabbitMQConfig {
amqp_addr: "amqp://localhost".to_string(),
@@ -26,11 +29,14 @@ pub async fn queue_length_handler() -> Response {
// Return the queue length with a 200 OK status
(StatusCode::OK, queue_length.to_string()).into_response()
},
}
Err(e) => {
error!("Failed to create consumer: {:?}", e);
(StatusCode::INTERNAL_SERVER_ERROR, "Failed to connect to RabbitMQ".to_string()).into_response()
(
StatusCode::INTERNAL_SERVER_ERROR,
"Failed to connect to RabbitMQ".to_string(),
)
.into_response()
}
}
}