feat(common): add SongService application layer
This commit is contained in:
17
crates/common/Cargo.toml
Normal file
17
crates/common/Cargo.toml
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
[package]
|
||||||
|
name = "common"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
anyhow = { workspace = true }
|
||||||
|
reqwest = { workspace = true }
|
||||||
|
serde = { workspace = true }
|
||||||
|
serde_json = { workspace = true }
|
||||||
|
thiserror = { workspace = true }
|
||||||
|
tokio = { workspace = true }
|
||||||
|
tracing = { workspace = true }
|
||||||
|
uuid = { workspace = true }
|
||||||
|
rand = { workspace = true }
|
||||||
|
async-trait = { workspace = true }
|
||||||
|
domain = { path = "../domain" }
|
||||||
28
crates/common/src/lib.rs
Normal file
28
crates/common/src/lib.rs
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
use domain::{RepositoryError, Song, SongRepositoryPort, 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
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user