Update all libraries to the new database format

This commit is contained in:
2026-01-21 22:05:50 -07:00
parent 0e2a8e425b
commit 66168c120f
33 changed files with 1025 additions and 794 deletions
+17 -26
View File
@@ -1,25 +1,30 @@
//! Movies API
use core::time::Duration;
use std::rc::Rc;
use std::sync::RwLock;
use governor::Jitter;
use crate::Config;
use crate::api::exec_request;
use crate::model::Movie;
use crate::model::id::MovieId;
use crate::{Cache, CachePolicy, Config};
use super::{Error, make_request};
/// TMDB Movies API client
pub struct Client {
config: Rc<Config>,
cache: Rc<dyn Cache>,
policy: Rc<RwLock<CachePolicy>>,
}
impl Client {
/// Create a new client with the given configuration
pub fn new(config: Rc<Config>) -> Self {
Self { config }
pub fn new(config: Rc<Config>, cache: Rc<dyn Cache>, policy: Rc<RwLock<CachePolicy>>) -> Self {
Self {
config,
cache,
policy,
}
}
}
@@ -30,25 +35,11 @@ impl Client {
id: impl Into<MovieId>,
language: Option<&str>,
) -> Result<Movie, Error> {
self.config
.limiter
.until_ready_with_jitter(Jitter::new(
Duration::from_millis(0),
Duration::from_millis(50),
))
.await;
Ok(self
.config
.client
.execute(make_request(
&self.config,
&format!("/3/movie/{}", id.into().into_raw()),
language,
)?)
.await?
.error_for_status()?
.json()
.await?)
let request = make_request(
&self.config,
&format!("/3/movie/{}", id.into().into_raw()),
language,
)?;
exec_request(&self.config, &*self.cache, &self.policy, request).await
}
}