feat: implement episode actions add endpoint

This commit is contained in:
Jef Roosens 2025-03-04 09:47:13 +01:00
parent 064365fb4f
commit bcfb8805eb
No known key found for this signature in database
GPG key ID: 21FD3D77D56BAF49
13 changed files with 152 additions and 63 deletions

View file

@ -6,13 +6,13 @@ use axum::{
};
use crate::{
db,
gpodder::{self, EpisodeActionRepository},
server::{
error::{AppError, AppResult},
gpodder::{
auth_middleware,
format::{Format, StringWithFormat},
models::{EpisodeAction, UpdatedUrlsResponse},
models::UpdatedUrlsResponse,
},
Context,
},
@ -27,8 +27,8 @@ pub fn router(ctx: Context) -> Router<Context> {
async fn post_episode_actions(
State(ctx): State<Context>,
Path(username): Path<StringWithFormat>,
Extension(user): Extension<db::User>,
Json(actions): Json<Vec<EpisodeAction>>,
Extension(user): Extension<gpodder::User>,
Json(actions): Json<Vec<gpodder::EpisodeAction>>,
) -> AppResult<Json<UpdatedUrlsResponse>> {
if username.format != Format::Json {
return Err(AppError::NotFound);
@ -38,7 +38,15 @@ async fn post_episode_actions(
return Err(AppError::BadRequest);
}
tracing::debug!("{:?}", actions);
todo!()
Ok(
tokio::task::spawn_blocking(move || ctx.repo.add_episode_actions(&user, actions))
.await
.unwrap()
.map(|timestamp| {
Json(UpdatedUrlsResponse {
timestamp,
update_urls: Vec::new(),
})
})?,
)
}

View file

@ -13,9 +13,7 @@ use crate::{
gpodder::{
auth_middleware,
format::{Format, StringWithFormat},
models::{
DeviceType, SubscriptionDelta, SubscriptionDeltaResponse, UpdatedUrlsResponse,
},
models::{SubscriptionDelta, SubscriptionDeltaResponse, UpdatedUrlsResponse},
},
Context,
},

View file

@ -69,30 +69,3 @@ pub struct UpdatedUrlsResponse {
pub timestamp: i64,
pub update_urls: Vec<(String, String)>,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "lowercase")]
#[serde(tag = "action")]
pub enum EpisodeActionType {
Download,
Play {
#[serde(default)]
started: Option<i32>,
position: i32,
#[serde(default)]
total: Option<i32>,
},
Delete,
New,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct EpisodeAction {
podcast: String,
episode: String,
timestamp: Option<NaiveDateTime>,
#[serde(default)]
device: Option<String>,
#[serde(flatten)]
action: EpisodeActionType,
}