feat: expand workspace to include libertas_infra and libertas_worker
feat(libertas_api): add dependency on libertas_infra and async-nats refactor(libertas_api): consolidate config loading and add broker_url refactor(libertas_api): integrate NATS client into app state and services feat(libertas_core): introduce config module for database and server settings fix(libertas_core): enhance error handling with detailed messages feat(libertas_infra): create infrastructure layer with database repositories feat(libertas_infra): implement Postgres repositories for media and albums feat(libertas_worker): add worker service to process media jobs via NATS
This commit is contained in:
37
libertas_core/src/config.rs
Normal file
37
libertas_core/src/config.rs
Normal file
@@ -0,0 +1,37 @@
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::error::CoreResult;
|
||||
|
||||
#[derive(Deserialize, Clone)]
|
||||
pub enum DatabaseType {
|
||||
Postgres,
|
||||
Sqlite,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Clone)]
|
||||
pub struct DatabaseConfig {
|
||||
pub db_type: DatabaseType,
|
||||
pub url: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Clone)]
|
||||
pub struct Config {
|
||||
pub database: DatabaseConfig,
|
||||
pub server_address: String,
|
||||
pub jwt_secret: String,
|
||||
pub media_library_path: String,
|
||||
pub broker_url: String,
|
||||
}
|
||||
|
||||
pub fn load_config() -> CoreResult<Config> {
|
||||
Ok(Config {
|
||||
database: DatabaseConfig {
|
||||
db_type: DatabaseType::Postgres,
|
||||
url: "postgres://postgres:postgres@localhost:5432/libertas_db".to_string(),
|
||||
},
|
||||
server_address: "127.0.0.1:8080".to_string(),
|
||||
jwt_secret: "super_secret_jwt_key".to_string(),
|
||||
media_library_path: "media_library".to_string(),
|
||||
broker_url: "amqp://guest:guest@localhost:5672/".to_string(),
|
||||
})
|
||||
}
|
||||
@@ -23,8 +23,8 @@ pub enum CoreError {
|
||||
#[error("Authentication failed: {0}")]
|
||||
Auth(String),
|
||||
|
||||
#[error("An unknown error occurred")]
|
||||
Unknown,
|
||||
#[error("An unknown error occurred: {0}")]
|
||||
Unknown(String),
|
||||
}
|
||||
|
||||
pub type CoreResult<T> = Result<T, CoreError>;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
pub mod config;
|
||||
pub mod error;
|
||||
pub mod models;
|
||||
pub mod plugins;
|
||||
pub mod repositories;
|
||||
pub mod schema;
|
||||
pub mod services;
|
||||
|
||||
26
libertas_core/src/plugins.rs
Normal file
26
libertas_core/src/plugins.rs
Normal file
@@ -0,0 +1,26 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
error::CoreResult,
|
||||
models::Media,
|
||||
repositories::{AlbumRepository, MediaRepository, UserRepository},
|
||||
};
|
||||
|
||||
pub struct PluginData {
|
||||
pub message: String,
|
||||
}
|
||||
|
||||
pub struct PluginContext {
|
||||
pub media_repo: Arc<dyn MediaRepository>,
|
||||
pub album_repo: Arc<dyn AlbumRepository>,
|
||||
pub user_repo: Arc<dyn UserRepository>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait MediaProcessorPlugin: Send + Sync {
|
||||
fn name(&self) -> &'static str;
|
||||
|
||||
async fn process(&self, media: &Media, context: &PluginContext) -> CoreResult<PluginData>;
|
||||
}
|
||||
Reference in New Issue
Block a user