entertainarr-adapter-http 0.1.0

HTTP adapter for entertainarr
Documentation
use axum::Json;
use axum::extract::State;
use entertainarr_domain::podcast::prelude::PodcastService;

use crate::entity::ApiResource;
use crate::entity::podcast_episode::PodcastEpisodeProgressEntity;
use crate::server::extractor::user::CurrentUser;
use crate::server::handler::error::ApiErrorResponse;

pub async fn handle<S>(
    State(state): State<S>,
    CurrentUser(user_id): CurrentUser,
    Json(payload): Json<ApiResource<Vec<PodcastEpisodeProgressEntity>>>,
) -> Result<Json<ApiResource<()>>, ApiErrorResponse>
where
    S: crate::server::prelude::ServerState,
{
    let episode_ids = payload
        .data
        .into_iter()
        .map(|item| item.id.0)
        .collect::<Vec<_>>();
    state
        .podcast_service()
        .delete_podcast_episode_progressions(user_id, &episode_ids)
        .await
        .map_err(|err| {
            tracing::error!(error = ?err, "unable to delete podcast episode progresses");
            ApiErrorResponse::internal()
        })?;
    Ok(Json(ApiResource::new(())))
}