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:
@@ -4,26 +4,35 @@ use async_trait::async_trait;
|
||||
use chrono::Datelike;
|
||||
use futures::stream::StreamExt;
|
||||
use libertas_core::{
|
||||
config::Config,
|
||||
error::{CoreError, CoreResult},
|
||||
models::Media,
|
||||
repositories::MediaRepository,
|
||||
schema::UploadMediaData,
|
||||
services::MediaService,
|
||||
};
|
||||
use serde_json::json;
|
||||
use sha2::{Digest, Sha256};
|
||||
use tokio::{fs, io::AsyncWriteExt};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::config::Config;
|
||||
|
||||
pub struct MediaServiceImpl {
|
||||
repo: Arc<dyn MediaRepository>,
|
||||
config: Config,
|
||||
nats_client: async_nats::Client,
|
||||
}
|
||||
|
||||
impl MediaServiceImpl {
|
||||
pub fn new(repo: Arc<dyn MediaRepository>, config: Config) -> Self {
|
||||
Self { repo, config }
|
||||
pub fn new(
|
||||
repo: Arc<dyn MediaRepository>,
|
||||
config: Config,
|
||||
nats_client: async_nats::Client,
|
||||
) -> Self {
|
||||
Self {
|
||||
repo,
|
||||
config,
|
||||
nats_client,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,6 +98,12 @@ impl MediaService for MediaServiceImpl {
|
||||
|
||||
self.repo.create(&media_model).await?;
|
||||
|
||||
let job_payload = json!({ "media_id": media_model.id });
|
||||
self.nats_client
|
||||
.publish("media.new".to_string(), job_payload.to_string().into())
|
||||
.await
|
||||
.map_err(|e| CoreError::Unknown(format!("Failed to publish NATS job: {}", e)))?;
|
||||
|
||||
Ok(media_model)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user