use actix_web::{HttpResponse, ResponseError};
use derive_more::Display;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct GetListProductInventoriesBody {
pub menu: String,
pub page_number: i32,
pub page_count: i32,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct GetListProductInventoriesResult {
pub list: Vec<ProductInventoryAggregation>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct ProductInventoryAggregation {
pub id: Option<String>,
pub product: Option<PartialProductAggregation>,
pub site: Option<PartialSiteAggregation>,
pub variant: Option<Vec<String>>,
pub kind: Option<String>,
pub price: Option<ProductPriceAggregation>,
pub quantity: Option<f64>,
pub picture: Option<PartialPictureAggregation>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct PartialProductAggregation {
pub id: Option<String>,
pub identifier: Option<String>,
pub names: Option<Vec<NameAggregation>>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct NameAggregation {
pub id: Option<String>,
pub language_code: Option<String>,
pub value: Option<String>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct PartialSiteAggregation {
pub id: Option<String>,
pub identifier: Option<String>,
pub names: Option<Vec<NameAggregation>>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct ProductPriceAggregation {
pub value: Option<f64>,
pub currency: Option<PriceCurrencyAggregation>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct PriceCurrencyAggregation {
pub id: Option<String>,
pub code: Option<String>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct PartialPictureAggregation {
pub id: Option<String>,
pub file_url: Option<String>,
}
#[derive(Debug, Display)]
pub enum GetListProductInventoriesError {
#[display(fmt = "invalid_object_id")]
InvalidObjectId,
Default(String),
}
impl ResponseError for GetListProductInventoriesError {
fn error_response(&self) -> HttpResponse {
match self {
GetListProductInventoriesError::InvalidObjectId => {
HttpResponse::NotAcceptable().body("invalid_object_id")
}
GetListProductInventoriesError::Default(error) => HttpResponse::BadRequest().body(error),
}
}
}