application: library bounded context
This commit is contained in:
33
crates/application/src/library/list_genres.rs
Normal file
33
crates/application/src/library/list_genres.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
use domain::errors::{DomainError, DomainResult};
|
||||
use domain::value_objects::ContentType;
|
||||
|
||||
use super::deps::LibraryQueryDeps;
|
||||
use super::queries::ListGenresQuery;
|
||||
|
||||
/// List genres available in the library, optionally filtered.
|
||||
pub async fn execute(deps: &LibraryQueryDeps, query: ListGenresQuery) -> DomainResult<Vec<String>> {
|
||||
let content_type = query
|
||||
.content_type
|
||||
.as_deref()
|
||||
.map(parse_content_type)
|
||||
.transpose()?;
|
||||
|
||||
deps.library_query
|
||||
.list_genres(content_type.as_ref(), query.provider_id.as_deref())
|
||||
.await
|
||||
}
|
||||
|
||||
fn parse_content_type(s: &str) -> DomainResult<ContentType> {
|
||||
match s {
|
||||
"movie" => Ok(ContentType::Movie),
|
||||
"episode" => Ok(ContentType::Episode),
|
||||
"short" => Ok(ContentType::Short),
|
||||
other => Err(DomainError::ValidationError(format!(
|
||||
"Unknown content type '{other}'. Use movie, episode, or short."
|
||||
))),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "tests/list_genres.rs"]
|
||||
mod tests;
|
||||
Reference in New Issue
Block a user