use actix_web::{HttpResponse, ResponseError};
use derive_more::Display;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct GetListProductsToAssignBody {
pub menu: String,
pub category: String,
pub name: Option<String>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct GetListProductsToAssignResult {
pub list: Vec<ProductToAssignAggregation>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct ProductToAssignAggregation {
pub id: Option<String>,
pub identifier: Option<String>,
pub names: Option<Vec<NameAggregation>>,
pub price: Option<ProductPriceAggregation>,
pub picture: Option<CategoryPictureUrlAggregation>,
pub main_category: Option<CategoryToAssignAggregation>,
pub current_category: Option<CategoryToAssignAggregation>,
pub is_assigned: Option<bool>,
}
#[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 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 CategoryPictureUrlAggregation {
pub id: Option<String>,
pub file_url: Option<String>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct CategoryToAssignAggregation {
pub id: Option<String>,
pub names: Option<Vec<NameAggregation>>,
pub level: Option<i32>,
}
#[derive(Debug, Display)]
pub enum GetListProductsToAssignError {
#[display(fmt = "invalid_object_id")]
InvalidObjectId,
Default(String),
}
impl ResponseError for GetListProductsToAssignError {
fn error_response(&self) -> HttpResponse {
match self {
GetListProductsToAssignError::InvalidObjectId => {
HttpResponse::NotAcceptable().body("invalid_object_id")
}
GetListProductsToAssignError::Default(error) => HttpResponse::BadRequest().body(error),
}
}
}