1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//! Provides access to the API endpoints for managing presets.
//!
//! Presets are a set of search parameters that can be applied to a search query by using the `preset` search parameter.
//!
//! A `Presets` instance is created via the main `client.presets()` method.
use crate::{Client, Error, execute_wrapper};
use ::std::borrow::Cow;
use typesense_codegen::{apis::presets_api, models};
/// Provides methods for managing all of your Typesense presets.
///
/// This struct is created by calling `client.presets()`.
pub struct Presets<'a> {
pub(super) client: &'a Client,
}
impl<'a> Presets<'a> {
/// Creates a new `Presets` instance.
#[inline]
pub(super) fn new(client: &'a Client) -> Self {
Self { client }
}
/// Retrieves the details of all presets.
pub async fn retrieve(
&self,
) -> Result<models::PresetsRetrieveSchema, Error<presets_api::RetrieveAllPresetsError>> {
execute_wrapper!(self, presets_api::retrieve_all_presets)
}
/// Creates or updates an existing preset.
///
/// # Arguments
/// * `preset_id` - The ID of the preset to create or update.
/// * `schema` - A `PresetUpsertSchema` object with the preset's value.
pub async fn upsert(
&self,
preset_id: impl Into<Cow<'_, str>>,
schema: models::PresetUpsertSchema<'_>,
) -> Result<models::PresetSchema, Error<presets_api::UpsertPresetError>> {
let params = presets_api::UpsertPresetParams {
preset_id: preset_id.into(),
preset_upsert_schema: schema,
};
execute_wrapper!(self, presets_api::upsert_preset, params)
}
}