|
| 1 | +//! Provides access to the API endpoints for managing a specific curation set. |
| 2 | +//! |
| 3 | +//! Curation sets allow you to include or exclude specific documents for a given query. |
| 4 | +//! |
| 5 | +//! A `CurationSet` instance is created via the main `client.curation_set("curation_set_name")` method. |
| 6 | +
|
| 7 | +mod item; |
| 8 | +mod items; |
| 9 | + |
| 10 | +use crate::{Client, Error, execute_wrapper}; |
| 11 | +use item::CurationSetItem; |
| 12 | +use items::CurationSetItems; |
| 13 | +use typesense_codegen::{ |
| 14 | + apis::curation_sets_api::{self, RetrieveCurationSetParams}, |
| 15 | + models, |
| 16 | +}; |
| 17 | + |
| 18 | +/// Provides methods for managing a specific curation set. |
| 19 | +/// |
| 20 | +/// This struct is created by calling `client.curation_set("curation_set_name")`. |
| 21 | +pub struct CurationSet<'a> { |
| 22 | + pub(super) client: &'a Client, |
| 23 | + pub(super) curation_set_name: &'a str, |
| 24 | +} |
| 25 | + |
| 26 | +impl<'a> CurationSet<'a> { |
| 27 | + /// Creates a new `CurationSet` instance. |
| 28 | + #[inline] |
| 29 | + pub(super) fn new(client: &'a Client, curation_set_name: &'a str) -> Self { |
| 30 | + Self { |
| 31 | + client, |
| 32 | + curation_set_name, |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + /// Provides access to the items of this curation set. |
| 37 | + #[inline] |
| 38 | + pub fn items(&self) -> CurationSetItems<'_> { |
| 39 | + CurationSetItems::new(self.client, self.curation_set_name) |
| 40 | + } |
| 41 | + |
| 42 | + /// Provides access to this specific item of this curation set. |
| 43 | + #[inline] |
| 44 | + pub fn item(&self, item_id: &'a str) -> CurationSetItem<'a> { |
| 45 | + CurationSetItem::new(self.client, self.curation_set_name, item_id) |
| 46 | + } |
| 47 | + |
| 48 | + /// Retrieves the details of this curation set. |
| 49 | + pub async fn retrieve( |
| 50 | + &self, |
| 51 | + ) -> Result<models::CurationSetSchema, Error<curation_sets_api::RetrieveCurationSetError>> { |
| 52 | + let params = RetrieveCurationSetParams { |
| 53 | + curation_set_name: self.curation_set_name.into(), |
| 54 | + }; |
| 55 | + execute_wrapper!(self, curation_sets_api::retrieve_curation_set, params) |
| 56 | + } |
| 57 | + |
| 58 | + /// Delete this curation set. |
| 59 | + pub async fn delete( |
| 60 | + &self, |
| 61 | + ) -> Result<models::CurationSetDeleteSchema, Error<curation_sets_api::DeleteCurationSetError>> |
| 62 | + { |
| 63 | + let params = curation_sets_api::DeleteCurationSetParams { |
| 64 | + curation_set_name: self.curation_set_name.into(), |
| 65 | + }; |
| 66 | + execute_wrapper!(self, curation_sets_api::delete_curation_set, params) |
| 67 | + } |
| 68 | +} |
0 commit comments