use crate::api::{api_delete, api_get, api_post, api_put};
use crate::{
api::{ApiClient, ApiError},
models::{Story, StoryCreateRequest, StoryListParams, StoryUpdateRequest},
};
use futures_util::{StreamExt, pin_mut};
pub async fn list_stories(
client: &ApiClient,
params: StoryListParams,
) -> Result<Vec<Story>, ApiError> {
let endpoint = format!("/tasks/{}/stories", params.task_gid);
let stream = client.paginate_with_limit::<Story>(&endpoint, vec![], params.limit);
pin_mut!(stream);
let mut stories = Vec::new();
while let Some(page) = stream.next().await {
let mut page = page?;
stories.append(&mut page);
}
Ok(stories)
}
pub async fn get_story(client: &ApiClient, gid: &str) -> Result<Story, ApiError> {
api_get(client, &format!("/stories/{gid}")).await
}
pub async fn create_story(
client: &ApiClient,
task_gid: &str,
request: StoryCreateRequest,
) -> Result<Story, ApiError> {
api_post(client, &format!("/tasks/{task_gid}/stories"), &request).await
}
pub async fn update_story(
client: &ApiClient,
gid: &str,
request: StoryUpdateRequest,
) -> Result<Story, ApiError> {
api_put(client, &format!("/stories/{gid}"), &request).await
}
pub async fn delete_story(client: &ApiClient, gid: &str) -> Result<(), ApiError> {
api_delete(client, &format!("/stories/{gid}")).await
}