refactoring to surrealdb

This commit is contained in:
Per Stark
2024-10-15 13:29:57 +02:00
parent dd703c0bc5
commit 2ceb721329
5 changed files with 31 additions and 109 deletions

View File

@@ -60,11 +60,11 @@ pub async fn get_file_handler(
// Parse UUID
let uuid = Uuid::parse_str(&uuid_str).map_err(|_| FileError::InvalidUuid(uuid_str.clone()))?;
// Initialize RedisClient
let redis_client = RedisClient::new("redis://127.0.0.1/");
// Initialize the database client
let db_client = SurrealDbClient::new().await.map_err(|e| FileError::PersistError(e.to_string())).unwrap();
// Retrieve FileInfo
let file_info = FileInfo::get(uuid, &redis_client).await?;
let file_info = FileInfo::get_by_uuid(uuid, &db_client).await?;
// Prepare the response JSON
let response = json!({

View File

@@ -1,7 +1,7 @@
use std::sync::Arc;
use axum::{http::StatusCode, response::IntoResponse, Extension, Json};
use tracing::{error, info};
use crate::{models::ingress_content::{create_ingress_objects, IngressInput}, rabbitmq::publisher::RabbitMQProducer, redis::client::RedisClient};
use crate::{models::{file_info::FileError, ingress_content::{create_ingress_objects, IngressInput}}, rabbitmq::publisher::RabbitMQProducer, redis::client::RedisClient, surrealdb::SurrealDbClient};
pub async fn ingress_handler(
Extension(producer): Extension<Arc<RabbitMQProducer>>,
@@ -9,9 +9,10 @@ pub async fn ingress_handler(
) -> impl IntoResponse {
info!("Received input: {:?}", input);
let db_client = SurrealDbClient::new().await.map_err(|e| FileError::PersistError(e.to_string())).unwrap();
let redis_client = RedisClient::new("redis://127.0.0.1/");
match create_ingress_objects(input, &redis_client).await {
match create_ingress_objects(input, &db_client).await {
Ok(objects) => {
for object in objects {
match producer.publish(&object).await {