refactor: migrated episode actions API to store
This commit is contained in:
parent
dd14a2152f
commit
465612eec7
7 changed files with 97 additions and 53 deletions
|
|
@ -4,10 +4,11 @@ use axum::{
|
|||
routing::post,
|
||||
Extension, Json, Router,
|
||||
};
|
||||
use chrono::DateTime;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
gpodder::{self, EpisodeActionRepository},
|
||||
gpodder,
|
||||
server::{
|
||||
error::{AppError, AppResult},
|
||||
gpodder::{
|
||||
|
|
@ -43,12 +44,12 @@ async fn post_episode_actions(
|
|||
}
|
||||
|
||||
Ok(
|
||||
tokio::task::spawn_blocking(move || ctx.repo.add_episode_actions(&user, actions))
|
||||
tokio::task::spawn_blocking(move || ctx.store.add_episode_actions(&user, actions))
|
||||
.await
|
||||
.unwrap()
|
||||
.map(|timestamp| {
|
||||
.map(|time_changed| {
|
||||
Json(UpdatedUrlsResponse {
|
||||
timestamp,
|
||||
timestamp: time_changed.timestamp(),
|
||||
update_urls: Vec::new(),
|
||||
})
|
||||
})?,
|
||||
|
|
@ -84,10 +85,15 @@ async fn get_episode_actions(
|
|||
return Err(AppError::BadRequest);
|
||||
}
|
||||
|
||||
let since = filter
|
||||
.since
|
||||
.map(|ts| DateTime::from_timestamp(ts, 0))
|
||||
.flatten();
|
||||
|
||||
Ok(tokio::task::spawn_blocking(move || {
|
||||
ctx.repo.episode_actions_for_user(
|
||||
ctx.store.episode_actions_for_user(
|
||||
&user,
|
||||
filter.since,
|
||||
since,
|
||||
filter.podcast,
|
||||
filter.device,
|
||||
filter.aggregated,
|
||||
|
|
@ -95,5 +101,10 @@ async fn get_episode_actions(
|
|||
})
|
||||
.await
|
||||
.unwrap()
|
||||
.map(|(timestamp, actions)| Json(EpisodeActionsResponse { timestamp, actions }))?)
|
||||
.map(|(ts, actions)| {
|
||||
Json(EpisodeActionsResponse {
|
||||
timestamp: ts.timestamp(),
|
||||
actions,
|
||||
})
|
||||
})?)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ use tower_http::trace::TraceLayer;
|
|||
|
||||
#[derive(Clone)]
|
||||
pub struct Context {
|
||||
pub repo: crate::db::SqliteRepository,
|
||||
pub store: crate::gpodder::GpodderRepository,
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue