refactor: continue
This commit is contained in:
@@ -315,4 +315,24 @@ impl Model {
|
||||
)
|
||||
}))
|
||||
}
|
||||
|
||||
pub async fn get_subsribed_bangumi_list_from_subscription(
|
||||
ctx: &dyn AppContextTrait,
|
||||
subscription_id: i32,
|
||||
) -> RecorderResult<Vec<Self>> {
|
||||
let db = ctx.db();
|
||||
let bangumi_list = Entity::find()
|
||||
.filter(
|
||||
Condition::all()
|
||||
.add(subscription_bangumi::Column::SubscriptionId.eq(subscription_id)),
|
||||
)
|
||||
.join_rev(
|
||||
JoinType::InnerJoin,
|
||||
subscription_bangumi::Relation::Bangumi.def(),
|
||||
)
|
||||
.all(db)
|
||||
.await?;
|
||||
|
||||
Ok(bangumi_list)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ pub mod downloaders;
|
||||
pub mod downloads;
|
||||
pub mod episodes;
|
||||
pub mod query;
|
||||
pub mod subscriber_tasks;
|
||||
pub mod subscribers;
|
||||
pub mod subscription_bangumi;
|
||||
pub mod subscription_episode;
|
||||
|
||||
18
apps/recorder/src/models/subscriber_tasks.rs
Normal file
18
apps/recorder/src/models/subscriber_tasks.rs
Normal file
@@ -0,0 +1,18 @@
|
||||
use sea_orm::entity::prelude::*;
|
||||
|
||||
use crate::task::SubscriberTask;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
|
||||
#[sea_orm(table_name = "subscriber_tasks")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key)]
|
||||
pub id: i32,
|
||||
pub subscriber_id: i32,
|
||||
pub job: SubscriberTask,
|
||||
pub state: String,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
@@ -45,7 +45,6 @@ pub struct Model {
|
||||
pub subscriber_id: i32,
|
||||
pub category: SubscriptionCategory,
|
||||
pub source_url: String,
|
||||
pub source_urls: Option<Vec<String>>,
|
||||
pub enabled: bool,
|
||||
pub credential_id: Option<i32>,
|
||||
}
|
||||
@@ -176,14 +175,32 @@ impl Model {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn sync_feeds(&self, ctx: Arc<dyn AppContextTrait>) -> RecorderResult<()> {
|
||||
let subscription = self.try_into()?;
|
||||
match subscription {
|
||||
Subscription::MikanSubscriber(subscription) => subscription.sync_feeds(ctx).await,
|
||||
Subscription::MikanSeason(subscription) => subscription.sync_feeds(ctx).await,
|
||||
Subscription::MikanBangumi(subscription) => subscription.sync_feeds(ctx).await,
|
||||
Subscription::Manual => Ok(()),
|
||||
pub async fn find_by_id_and_subscriber_id(
|
||||
ctx: &dyn AppContextTrait,
|
||||
subscriber_id: i32,
|
||||
subscription_id: i32,
|
||||
) -> RecorderResult<Self> {
|
||||
let db = ctx.db();
|
||||
let subscription_model = Entity::find_by_id(subscription_id)
|
||||
.one(db)
|
||||
.await?
|
||||
.ok_or_else(|| RecorderError::DbError {
|
||||
source: DbErr::RecordNotFound(format!(
|
||||
"Subscription id {subscription_id} not found or not belong to subscriber \
|
||||
{subscriber_id}",
|
||||
)),
|
||||
})?;
|
||||
|
||||
if subscription_model.subscriber_id != subscriber_id {
|
||||
Err(RecorderError::DbError {
|
||||
source: DbErr::RecordNotFound(format!(
|
||||
"Subscription id {subscription_id} not found or not belong to subscriber \
|
||||
{subscriber_id}",
|
||||
)),
|
||||
})?;
|
||||
}
|
||||
|
||||
Ok(subscription_model)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,7 +210,9 @@ pub trait SubscriptionTrait: Sized + Debug {
|
||||
|
||||
fn get_subscription_id(&self) -> i32;
|
||||
|
||||
async fn sync_feeds(&self, ctx: Arc<dyn AppContextTrait>) -> RecorderResult<()>;
|
||||
async fn sync_feeds_incremental(&self, ctx: Arc<dyn AppContextTrait>) -> RecorderResult<()>;
|
||||
|
||||
async fn sync_feeds_full(&self, ctx: Arc<dyn AppContextTrait>) -> RecorderResult<()>;
|
||||
|
||||
async fn sync_sources(&self, ctx: Arc<dyn AppContextTrait>) -> RecorderResult<()>;
|
||||
|
||||
@@ -244,11 +263,20 @@ impl SubscriptionTrait for Subscription {
|
||||
}
|
||||
}
|
||||
|
||||
async fn sync_feeds(&self, ctx: Arc<dyn AppContextTrait>) -> RecorderResult<()> {
|
||||
async fn sync_feeds_incremental(&self, ctx: Arc<dyn AppContextTrait>) -> RecorderResult<()> {
|
||||
match self {
|
||||
Self::MikanSubscriber(subscription) => subscription.sync_feeds(ctx).await,
|
||||
Self::MikanSeason(subscription) => subscription.sync_feeds(ctx).await,
|
||||
Self::MikanBangumi(subscription) => subscription.sync_feeds(ctx).await,
|
||||
Self::MikanSubscriber(subscription) => subscription.sync_feeds_incremental(ctx).await,
|
||||
Self::MikanSeason(subscription) => subscription.sync_feeds_incremental(ctx).await,
|
||||
Self::MikanBangumi(subscription) => subscription.sync_feeds_incremental(ctx).await,
|
||||
Self::Manual => Ok(()),
|
||||
}
|
||||
}
|
||||
|
||||
async fn sync_feeds_full(&self, ctx: Arc<dyn AppContextTrait>) -> RecorderResult<()> {
|
||||
match self {
|
||||
Self::MikanSubscriber(subscription) => subscription.sync_feeds_full(ctx).await,
|
||||
Self::MikanSeason(subscription) => subscription.sync_feeds_full(ctx).await,
|
||||
Self::MikanBangumi(subscription) => subscription.sync_feeds_full(ctx).await,
|
||||
Self::Manual => Ok(()),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user