Files
pocket-chords/crates/common/src/lib.rs

53 lines
1.4 KiB
Rust

use domain::{RepositoryError, Song, SongRepositoryPort, SongSearchPort, SongSummary, StoredSong};
use uuid::Uuid;
pub struct SongService {
repo: Box<dyn SongRepositoryPort>,
}
impl SongService {
pub fn new(repo: Box<dyn SongRepositoryPort>) -> Self {
Self { repo }
}
pub async fn save(&self, song: &Song) -> Result<StoredSong, RepositoryError> {
self.repo.save(song).await
}
pub async fn list(&self) -> Result<Vec<SongSummary>, RepositoryError> {
self.repo.list().await
}
pub async fn get(&self, id: Uuid) -> Result<Option<Song>, RepositoryError> {
self.repo.get(id).await
}
pub async fn delete(&self, id: Uuid) -> Result<(), RepositoryError> {
self.repo.delete(id).await
}
pub async fn update_meta(
&self,
id: Uuid,
title: Option<&str>,
artist: Option<&str>,
original_key: Option<&str>,
) -> Result<domain::SongSummary, domain::RepositoryError> {
self.repo.update_meta(id, title, artist, original_key).await
}
}
pub struct SongSearchService {
search: Box<dyn SongSearchPort>,
}
impl SongSearchService {
pub fn new(search: Box<dyn SongSearchPort>) -> Self {
Self { search }
}
pub async fn search(&self, query: &str) -> Result<Vec<domain::SongSummary>, domain::RepositoryError> {
self.search.search(query).await
}
}