refactor: migrate subscriptions API to store
This commit is contained in:
parent
6bb3e8a27f
commit
dd14a2152f
5 changed files with 101 additions and 36 deletions
|
|
@ -7,7 +7,7 @@ use axum::{
|
|||
use serde::Deserialize;
|
||||
|
||||
use crate::{
|
||||
gpodder::{self, SubscriptionRepository},
|
||||
gpodder,
|
||||
server::{
|
||||
error::{AppError, AppResult},
|
||||
gpodder::{
|
||||
|
|
@ -43,14 +43,14 @@ pub async fn post_subscription_changes(
|
|||
}
|
||||
|
||||
Ok(tokio::task::spawn_blocking(move || {
|
||||
ctx.repo
|
||||
ctx.store
|
||||
.update_subscriptions_for_device(&user, &id, delta.add, delta.remove)
|
||||
})
|
||||
.await
|
||||
.unwrap()
|
||||
.map(|timestamp| {
|
||||
.map(|time_changed| {
|
||||
Json(UpdatedUrlsResponse {
|
||||
timestamp,
|
||||
timestamp: time_changed.timestamp(),
|
||||
update_urls: Vec::new(),
|
||||
})
|
||||
})?)
|
||||
|
|
@ -76,17 +76,18 @@ pub async fn get_subscription_changes(
|
|||
return Err(AppError::BadRequest);
|
||||
}
|
||||
|
||||
let since = chrono::DateTime::from_timestamp(query.since, 0).ok_or(AppError::BadRequest)?;
|
||||
|
||||
Ok(tokio::task::spawn_blocking(move || {
|
||||
ctx.repo
|
||||
.subscription_updates_for_device(&user, &id, query.since)
|
||||
ctx.store.subscription_updates_for_device(&user, &id, since)
|
||||
})
|
||||
.await
|
||||
.unwrap()
|
||||
.map(|(timestamp, add, remove)| {
|
||||
.map(|(next_time_changed, add, remove)| {
|
||||
Json(SubscriptionDeltaResponse {
|
||||
add,
|
||||
remove,
|
||||
timestamp,
|
||||
timestamp: next_time_changed.timestamp(),
|
||||
})
|
||||
})?)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use axum::{
|
|||
};
|
||||
|
||||
use crate::{
|
||||
gpodder::{self, SubscriptionRepository},
|
||||
gpodder,
|
||||
server::{
|
||||
error::{AppError, AppResult},
|
||||
gpodder::{auth_middleware, format::StringWithFormat},
|
||||
|
|
@ -34,7 +34,7 @@ pub async fn get_device_subscriptions(
|
|||
}
|
||||
|
||||
Ok(
|
||||
tokio::task::spawn_blocking(move || ctx.repo.subscriptions_for_device(&user, &id))
|
||||
tokio::task::spawn_blocking(move || ctx.store.subscriptions_for_device(&user, &id))
|
||||
.await
|
||||
.unwrap()
|
||||
.map(Json)?,
|
||||
|
|
@ -51,7 +51,7 @@ pub async fn get_user_subscriptions(
|
|||
}
|
||||
|
||||
Ok(
|
||||
tokio::task::spawn_blocking(move || ctx.repo.subscriptions_for_user(&user))
|
||||
tokio::task::spawn_blocking(move || ctx.store.subscriptions_for_user(&user))
|
||||
.await
|
||||
.unwrap()
|
||||
.map(Json)?,
|
||||
|
|
@ -68,12 +68,10 @@ pub async fn put_device_subscriptions(
|
|||
return Err(AppError::BadRequest);
|
||||
}
|
||||
|
||||
Ok(
|
||||
tokio::task::spawn_blocking(move || {
|
||||
ctx.repo.set_subscriptions_for_device(&user, &id, urls)
|
||||
})
|
||||
.await
|
||||
.unwrap()
|
||||
.map(|_| ())?,
|
||||
)
|
||||
Ok(tokio::task::spawn_blocking(move || {
|
||||
ctx.store.set_subscriptions_for_device(&user, &id, urls)
|
||||
})
|
||||
.await
|
||||
.unwrap()
|
||||
.map(|_| ())?)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue