refactor(gpodder): rename store trait
parent
fc46c4874a
commit
7de4897364
|
@ -5,5 +5,6 @@ mod store;
|
||||||
pub use models::*;
|
pub use models::*;
|
||||||
pub use repository::GpodderRepository;
|
pub use repository::GpodderRepository;
|
||||||
pub use store::{
|
pub use store::{
|
||||||
AuthErr, AuthStore, DeviceRepository, EpisodeActionRepository, Store, SubscriptionRepository,
|
AuthErr, GpodderAuthStore, GpodderDeviceStore, GpodderEpisodeActionStore, GpodderStore,
|
||||||
|
GpodderSubscriptionStore,
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,18 +6,18 @@ use rand::{Rng, rngs::OsRng};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
models,
|
models,
|
||||||
store::{AuthErr, Store},
|
store::{AuthErr, GpodderStore},
|
||||||
};
|
};
|
||||||
|
|
||||||
const MAX_SESSION_AGE: i64 = 60 * 60 * 24 * 7;
|
const MAX_SESSION_AGE: i64 = 60 * 60 * 24 * 7;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct GpodderRepository {
|
pub struct GpodderRepository {
|
||||||
store: Arc<dyn Store + Send + Sync>,
|
store: Arc<dyn GpodderStore + Send + Sync>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GpodderRepository {
|
impl GpodderRepository {
|
||||||
pub fn new(store: impl Store + Send + Sync + 'static) -> Self {
|
pub fn new(store: impl GpodderStore + Send + Sync + 'static) -> Self {
|
||||||
Self {
|
Self {
|
||||||
store: Arc::new(store),
|
store: Arc::new(store),
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,17 +24,18 @@ impl Display for AuthErr {
|
||||||
|
|
||||||
impl std::error::Error for AuthErr {}
|
impl std::error::Error for AuthErr {}
|
||||||
|
|
||||||
pub trait Store:
|
/// API abstraction providing methods for serving the Gpodder API
|
||||||
AuthStore + DeviceRepository + SubscriptionRepository + EpisodeActionRepository
|
pub trait GpodderStore:
|
||||||
|
GpodderAuthStore + GpodderDeviceStore + GpodderSubscriptionStore + GpodderEpisodeActionStore
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Store for T where
|
impl<T> GpodderStore for T where
|
||||||
T: AuthStore + DeviceRepository + SubscriptionRepository + EpisodeActionRepository
|
T: GpodderAuthStore + GpodderDeviceStore + GpodderSubscriptionStore + GpodderEpisodeActionStore
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait AuthStore {
|
pub trait GpodderAuthStore {
|
||||||
/// Retrieve the session with the given session ID
|
/// Retrieve the session with the given session ID
|
||||||
fn get_session(&self, session_id: i64) -> Result<Option<Session>, AuthErr>;
|
fn get_session(&self, session_id: i64) -> Result<Option<Session>, AuthErr>;
|
||||||
|
|
||||||
|
@ -63,7 +64,7 @@ pub trait AuthStore {
|
||||||
fn remove_old_sessions(&self, min_last_seen: DateTime<Utc>) -> Result<usize, AuthErr>;
|
fn remove_old_sessions(&self, min_last_seen: DateTime<Utc>) -> Result<usize, AuthErr>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait DeviceRepository {
|
pub trait GpodderDeviceStore {
|
||||||
/// Return all devices associated with the user
|
/// Return all devices associated with the user
|
||||||
fn devices_for_user(&self, user: &User) -> Result<Vec<Device>, AuthErr>;
|
fn devices_for_user(&self, user: &User) -> Result<Vec<Device>, AuthErr>;
|
||||||
|
|
||||||
|
@ -108,7 +109,7 @@ pub trait DeviceRepository {
|
||||||
) -> Result<(Vec<String>, Vec<Vec<String>>), AuthErr>;
|
) -> Result<(Vec<String>, Vec<Vec<String>>), AuthErr>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait SubscriptionRepository {
|
pub trait GpodderSubscriptionStore {
|
||||||
/// Return the subscriptions for the given device
|
/// Return the subscriptions for the given device
|
||||||
fn subscriptions_for_device(
|
fn subscriptions_for_device(
|
||||||
&self,
|
&self,
|
||||||
|
@ -149,7 +150,7 @@ pub trait SubscriptionRepository {
|
||||||
) -> Result<(Vec<Subscription>, Vec<Subscription>), AuthErr>;
|
) -> Result<(Vec<Subscription>, Vec<Subscription>), AuthErr>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait EpisodeActionRepository {
|
pub trait GpodderEpisodeActionStore {
|
||||||
/// Insert the given episode actions into the datastore.
|
/// Insert the given episode actions into the datastore.
|
||||||
fn add_episode_actions(
|
fn add_episode_actions(
|
||||||
&self,
|
&self,
|
||||||
|
|
|
@ -22,7 +22,7 @@ impl From<User> for gpodder::User {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl gpodder::AuthStore for SqliteRepository {
|
impl gpodder::GpodderAuthStore for SqliteRepository {
|
||||||
fn get_user(&self, username: &str) -> Result<Option<gpodder::models::User>, AuthErr> {
|
fn get_user(&self, username: &str) -> Result<Option<gpodder::models::User>, AuthErr> {
|
||||||
Ok(users::table
|
Ok(users::table
|
||||||
.select(User::as_select())
|
.select(User::as_select())
|
||||||
|
|
|
@ -38,7 +38,7 @@ impl From<gpodder::DeviceType> for DeviceType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl gpodder::DeviceRepository for SqliteRepository {
|
impl gpodder::GpodderDeviceStore for SqliteRepository {
|
||||||
fn devices_for_user(
|
fn devices_for_user(
|
||||||
&self,
|
&self,
|
||||||
user: &gpodder::User,
|
user: &gpodder::User,
|
||||||
|
|
|
@ -71,7 +71,7 @@ fn to_gpodder_action(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl gpodder::EpisodeActionRepository for SqliteRepository {
|
impl gpodder::GpodderEpisodeActionStore for SqliteRepository {
|
||||||
fn add_episode_actions(
|
fn add_episode_actions(
|
||||||
&self,
|
&self,
|
||||||
user: &gpodder::User,
|
user: &gpodder::User,
|
||||||
|
|
|
@ -172,7 +172,7 @@ pub fn update_subscriptions_for_single_device(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
impl gpodder::SubscriptionRepository for SqliteRepository {
|
impl gpodder::GpodderSubscriptionStore for SqliteRepository {
|
||||||
fn subscriptions_for_user(
|
fn subscriptions_for_user(
|
||||||
&self,
|
&self,
|
||||||
user: &gpodder::User,
|
user: &gpodder::User,
|
||||||
|
|
Loading…
Reference in New Issue