// This file is auto-generated by oagen. Do not edit.
use crate::client::Client;
#[allow(unused_imports)]
use crate::enums::*;
use crate::error::Error;
#[allow(unused_imports)]
use crate::models::*;
#[allow(unused_imports)]
use serde::Serialize;
pub struct GroupsProductsApi<'a> {
pub(crate) client: &'a Client,
}
#[derive(Debug, Clone, Serialize)]
pub struct AddParams {
/// Store slug. Required for OAuth access tokens. API keys may omit it to use their current store, or the first accessible store when no current store is selected.
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "X-STORE")]
pub x_store: Option<String>,
/// Request body sent with this call.
///
/// Required.
#[serde(skip)]
pub body: SdkAddProductsToGroupRequestApplicationJson,
}
impl AddParams {
/// Construct a new `AddParams` with the required fields set.
#[allow(deprecated)]
pub fn new(body: SdkAddProductsToGroupRequestApplicationJson) -> Self {
Self {
x_store: Default::default(),
body,
}
}
}
#[derive(Debug, Clone, Serialize)]
pub struct RemoveParams {
/// Store slug. Required for OAuth access tokens. API keys may omit it to use their current store, or the first accessible store when no current store is selected.
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "X-STORE")]
pub x_store: Option<String>,
/// Request body sent with this call.
///
/// Required.
#[serde(skip)]
pub body: SdkRemoveProductsFromGroupRequestApplicationJson,
}
impl RemoveParams {
/// Construct a new `RemoveParams` with the required fields set.
#[allow(deprecated)]
pub fn new(body: SdkRemoveProductsFromGroupRequestApplicationJson) -> Self {
Self {
x_store: Default::default(),
body,
}
}
}
#[derive(Debug, Clone, Serialize)]
pub struct ListParams {
/// Number of items to return per page.
///
/// Defaults to `15`.
#[serde(skip_serializing_if = "Option::is_none")]
pub limit: Option<i64>,
/// Page number to return.
///
/// Defaults to `1`.
#[serde(skip_serializing_if = "Option::is_none")]
pub page: Option<i64>,
/// Store slug. Required for OAuth access tokens. API keys may omit it to use their current store, or the first accessible store when no current store is selected.
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "X-STORE")]
pub x_store: Option<String>,
}
impl Default for ListParams {
#[allow(deprecated)]
fn default() -> Self {
Self {
limit: Some(15),
page: Some(1),
x_store: Default::default(),
}
}
}
#[derive(Debug, Clone, Serialize)]
pub struct ReplaceParams {
/// Store slug. Required for OAuth access tokens. API keys may omit it to use their current store, or the first accessible store when no current store is selected.
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "X-STORE")]
pub x_store: Option<String>,
/// Request body sent with this call.
///
/// Required.
#[serde(skip)]
pub body: SdkSyncGroupProductsRequestApplicationJson,
}
impl ReplaceParams {
/// Construct a new `ReplaceParams` with the required fields set.
#[allow(deprecated)]
pub fn new(body: SdkSyncGroupProductsRequestApplicationJson) -> Self {
Self {
x_store: Default::default(),
body,
}
}
}
#[derive(Debug, Clone, Default, Serialize)]
pub struct GetParams {
/// Store slug. Required for OAuth access tokens. API keys may omit it to use their current store, or the first accessible store when no current store is selected.
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "X-STORE")]
pub x_store: Option<String>,
}
#[derive(Debug, Clone, Serialize)]
pub struct SearchParams {
/// Store slug. Required for OAuth access tokens. API keys may omit it to use their current store, or the first accessible store when no current store is selected.
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "X-STORE")]
pub x_store: Option<String>,
/// Request body sent with this call.
///
/// Required.
#[serde(skip)]
pub body: SdkSearchProductsWithinGroupRequestApplicationJson,
}
impl SearchParams {
/// Construct a new `SearchParams` with the required fields set.
#[allow(deprecated)]
pub fn new(body: SdkSearchProductsWithinGroupRequestApplicationJson) -> Self {
Self {
x_store: Default::default(),
body,
}
}
}
impl<'a> GroupsProductsApi<'a> {
/// Add products to group
///
/// Add existing products to a group. OAuth callers use the admin grant and select a store with X-STORE. Current membership and role permissions apply to every request.
pub async fn add(
&self,
group: &str,
params: AddParams,
) -> Result<SdkAddProductsToGroupResponseValue200ApplicationJson, Error> {
self.add_with_options(group, params, None).await
}
/// Variant of [`Self::add`] that accepts per-request [`crate::RequestOptions`].
pub async fn add_with_options(
&self,
group: &str,
params: AddParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkAddProductsToGroupResponseValue200ApplicationJson, Error> {
self.add_raw(group, params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn add_raw(
&self,
group: &str,
params: AddParams,
options: Option<&crate::RequestOptions>,
) -> Result<crate::RawResponse<SdkAddProductsToGroupResponseValue200ApplicationJson>, Error>
{
let group = crate::client::path_segment(group);
let path = format!("/v2/groups/{group}/products/attach");
let method = http::Method::POST;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = false;
merged.operation_id = Some("addProductsToGroup".to_string());
let options = Some(&merged);
self.client
.request_with_body_schema_opts_raw(
method,
&path,
¶ms,
Some(¶ms.body),
options,
"POST /v2/groups/{group}/products/attach",
)
.await
}
/// Remove products from group
///
/// Remove products from a group without deleting the products. OAuth callers use the admin grant and select a store with X-STORE. Current membership and role permissions apply to every request.
pub async fn remove(
&self,
group: &str,
params: RemoveParams,
) -> Result<SdkRemoveProductsFromGroupResponseValue200ApplicationJson, Error> {
self.remove_with_options(group, params, None).await
}
/// Variant of [`Self::remove`] that accepts per-request [`crate::RequestOptions`].
pub async fn remove_with_options(
&self,
group: &str,
params: RemoveParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkRemoveProductsFromGroupResponseValue200ApplicationJson, Error> {
self.remove_raw(group, params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn remove_raw(
&self,
group: &str,
params: RemoveParams,
options: Option<&crate::RequestOptions>,
) -> Result<crate::RawResponse<SdkRemoveProductsFromGroupResponseValue200ApplicationJson>, Error>
{
let group = crate::client::path_segment(group);
let path = format!("/v2/groups/{group}/products/detach");
let method = http::Method::DELETE;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = false;
merged.operation_id = Some("removeProductsFromGroup".to_string());
let options = Some(&merged);
self.client
.request_with_body_schema_opts_raw(
method,
&path,
¶ms,
Some(¶ms.body),
options,
"DELETE /v2/groups/{group}/products/detach",
)
.await
}
/// List all products within group
///
/// List the products in a group, 15 per page by default. OAuth callers use the admin grant and select a store with X-STORE. Current membership and role permissions apply to every request.
pub async fn list(
&self,
group: &str,
params: ListParams,
) -> Result<SdkListProductsWithinGroupResponseValue200ApplicationJson, Error> {
self.list_with_options(group, params, None).await
}
/// Variant of [`Self::list`] that accepts per-request [`crate::RequestOptions`].
pub async fn list_with_options(
&self,
group: &str,
params: ListParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkListProductsWithinGroupResponseValue200ApplicationJson, Error> {
self.list_raw(group, params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn list_raw(
&self,
group: &str,
params: ListParams,
options: Option<&crate::RequestOptions>,
) -> Result<crate::RawResponse<SdkListProductsWithinGroupResponseValue200ApplicationJson>, Error>
{
let group = crate::client::path_segment(group);
let path = format!("/v2/groups/{group}/products");
let method = http::Method::GET;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = false;
merged.operation_id = Some("listProductsWithinGroup".to_string());
let options = Some(&merged);
self.client
.request_with_query_schema_opts_raw(
method,
&path,
¶ms,
options,
"GET /v2/groups/{group}/products",
)
.await
}
/// Replace ordered group products
///
/// Replace a group's complete product membership in one transaction. Requires the group API-key ability and store group permission. The order of product_ids becomes display order. An empty array clears the group. Missing or draft products return 422; products from another store are rejected. Retrying the same list has the same result. Private products remain assigned but are omitted from the returned group summary. OAuth callers use the admin grant and select a store with X-STORE. Current membership and role permissions apply to every request.
pub async fn replace(
&self,
group: &str,
params: ReplaceParams,
) -> Result<SdkSyncGroupProductsResponseValue200ApplicationJson, Error> {
self.replace_with_options(group, params, None).await
}
/// Variant of [`Self::replace`] that accepts per-request [`crate::RequestOptions`].
pub async fn replace_with_options(
&self,
group: &str,
params: ReplaceParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkSyncGroupProductsResponseValue200ApplicationJson, Error> {
self.replace_raw(group, params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn replace_raw(
&self,
group: &str,
params: ReplaceParams,
options: Option<&crate::RequestOptions>,
) -> Result<crate::RawResponse<SdkSyncGroupProductsResponseValue200ApplicationJson>, Error>
{
let group = crate::client::path_segment(group);
let path = format!("/v2/groups/{group}/products");
let method = http::Method::PUT;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = false;
merged.operation_id = Some("syncGroupProducts".to_string());
let options = Some(&merged);
self.client
.request_with_body_schema_opts_raw(
method,
&path,
¶ms,
Some(¶ms.body),
options,
"PUT /v2/groups/{group}/products",
)
.await
}
/// List specific product within group
///
/// Retrieve one product from a group. OAuth callers use the admin grant and select a store with X-STORE. Current membership and role permissions apply to every request.
pub async fn get(
&self,
group: &str,
product: &str,
params: GetParams,
) -> Result<SdkGetProductWithinGroupResponseValue200ApplicationJson, Error> {
self.get_with_options(group, product, params, None).await
}
/// Variant of [`Self::get`] that accepts per-request [`crate::RequestOptions`].
pub async fn get_with_options(
&self,
group: &str,
product: &str,
params: GetParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkGetProductWithinGroupResponseValue200ApplicationJson, Error> {
self.get_raw(group, product, params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn get_raw(
&self,
group: &str,
product: &str,
params: GetParams,
options: Option<&crate::RequestOptions>,
) -> Result<crate::RawResponse<SdkGetProductWithinGroupResponseValue200ApplicationJson>, Error>
{
let group = crate::client::path_segment(group);
let product = crate::client::path_segment(product);
let path = format!("/v2/groups/{group}/products/{product}");
let method = http::Method::GET;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = false;
merged.operation_id = Some("getProductWithinGroup".to_string());
let options = Some(&merged);
self.client
.request_with_query_schema_opts_raw(
method,
&path,
¶ms,
options,
"GET /v2/groups/{group}/products/{product}",
)
.await
}
/// Search products within group
///
/// Search the products in a group using JSON body filters, search terms, includes, and sort instructions. OAuth callers use the admin grant and select a store with X-STORE. Current membership and role permissions apply to every request.
pub async fn search(
&self,
group: &str,
params: SearchParams,
) -> Result<SdkSearchProductsWithinGroupResponseValue200ApplicationJson, Error> {
self.search_with_options(group, params, None).await
}
/// Variant of [`Self::search`] that accepts per-request [`crate::RequestOptions`].
pub async fn search_with_options(
&self,
group: &str,
params: SearchParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkSearchProductsWithinGroupResponseValue200ApplicationJson, Error> {
self.search_raw(group, params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn search_raw(
&self,
group: &str,
params: SearchParams,
options: Option<&crate::RequestOptions>,
) -> Result<
crate::RawResponse<SdkSearchProductsWithinGroupResponseValue200ApplicationJson>,
Error,
> {
let group = crate::client::path_segment(group);
let path = format!("/v2/groups/{group}/products/search");
let method = http::Method::POST;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = false;
merged.operation_id = Some("searchProductsWithinGroup".to_string());
let options = Some(&merged);
self.client
.request_with_body_schema_opts_raw(
method,
&path,
¶ms,
Some(¶ms.body),
options,
"POST /v2/groups/{group}/products/search",
)
.await
}
}