Skip to main content

context69_sdk/client/library/
folders.rs

1use context69_contracts::{CreateFolderRequest, LibraryFolderResponse, MoveFolderRequest};
2use reqwest::Method;
3use uuid::Uuid;
4
5use super::Context69Client;
6use crate::Error;
7
8pub struct LibraryFoldersApi<'a> {
9    client: &'a Context69Client,
10    base_path: String,
11}
12
13impl<'a> LibraryFoldersApi<'a> {
14    pub(super) fn new(client: &'a Context69Client, base_path: String) -> Self {
15        Self { client, base_path }
16    }
17
18    pub async fn create(
19        &self,
20        request: &CreateFolderRequest,
21    ) -> Result<LibraryFolderResponse, Error> {
22        let path = format!("{}/folders", self.base_path);
23        self.client
24            .execute_json(
25                self.client
26                    .authorized_request(Method::POST, &path)
27                    .await?
28                    .json(request),
29            )
30            .await
31    }
32}
33
34pub struct LibraryFolderApi<'a> {
35    client: &'a Context69Client,
36    base_path: String,
37    folder_id: Uuid,
38}
39
40impl<'a> LibraryFolderApi<'a> {
41    pub(super) fn new(client: &'a Context69Client, base_path: String, folder_id: Uuid) -> Self {
42        Self {
43            client,
44            base_path,
45            folder_id,
46        }
47    }
48
49    pub async fn move_to(
50        &self,
51        request: &MoveFolderRequest,
52    ) -> Result<LibraryFolderResponse, Error> {
53        let path = format!("{}/folders/{}/move", self.base_path, self.folder_id);
54        self.client
55            .execute_json(
56                self.client
57                    .authorized_request(Method::POST, &path)
58                    .await?
59                    .json(request),
60            )
61            .await
62    }
63
64    pub async fn delete(&self) -> Result<(), Error> {
65        let path = format!("{}/folders/{}", self.base_path, self.folder_id);
66        self.client
67            .execute_empty(
68                self.client
69                    .authorized_request(Method::DELETE, &path)
70                    .await?,
71            )
72            .await
73    }
74}