Replace web product store with detailed product

This commit is contained in:
eraden 2022-11-28 08:26:47 +01:00
parent ee5bc43962
commit 2316426a13
2 changed files with 28 additions and 35 deletions

View File

@ -290,30 +290,11 @@ pub struct Product {
pub photos: Vec<Photo>,
}
pub mod v2 {
use crate::api::{Category, Photo};
#[derive(Debug, Hash, serde::Serialize, serde::Deserialize)]
pub struct ProductVariant {
pub id: crate::ProductVariantId,
pub product_id: crate::ProductId,
pub name: crate::ProductName,
pub short_description: crate::ProductShortDesc,
pub long_description: crate::ProductLongDesc,
pub category: Option<Category>,
pub price: crate::Price,
pub available: bool,
pub quantity_unit: crate::QuantityUnit,
pub deliver_days_flag: crate::Days,
pub photos: Vec<Photo>,
}
}
impl<'path>
From<(
crate::Product,
&mut Vec<ProductLinkedPhoto>,
&mut Vec<crate::Stock>,
&mut Vec<Stock>,
&'path str,
)> for Product
{
@ -392,7 +373,7 @@ impl
From<(
Vec<crate::Product>,
Vec<ProductLinkedPhoto>,
Vec<crate::Stock>,
Vec<Stock>,
String,
)> for Products
{
@ -566,3 +547,22 @@ pub mod admin {
#[derive(Serialize, Deserialize, Debug)]
pub struct LogoutResponse {}
}
pub mod v2 {
use crate::api::{Category, Photo};
#[derive(Debug, Hash, serde::Serialize, serde::Deserialize)]
pub struct ProductVariant {
pub id: crate::ProductVariantId,
pub product_id: crate::ProductId,
pub name: crate::ProductName,
pub short_description: crate::ProductShortDesc,
pub long_description: crate::ProductLongDesc,
pub category: Option<Category>,
pub price: crate::Price,
pub available: bool,
pub quantity_unit: crate::QuantityUnit,
pub deliver_days_flag: crate::Days,
pub photos: Vec<Photo>,
}
}

View File

@ -1,6 +1,6 @@
use std::collections::{HashMap, HashSet};
use model::v2::ProductVariantId;
use model::v2::{DetailedProduct, ProductVariantId};
use model::ProductId;
use seed::Url;
@ -75,13 +75,11 @@ impl From<::model::api::Config> for Config {
pub struct Products {
pub categories: Vec<model::api::Category>,
pub product_ids: Vec<ProductId>,
pub products: HashMap<ProductId, model::api::Product>,
pub product_variant_ids: Vec<ProductVariantId>,
pub product_variants: HashMap<ProductVariantId, model::api::v2::ProductVariant>,
pub products: HashMap<ProductId, DetailedProduct>,
}
impl Products {
pub fn update(&mut self, products: Vec<model::api::Product>) {
pub fn update(&mut self, products: Vec<DetailedProduct>) {
let len = products.len();
self.categories = products
.iter()
@ -106,18 +104,13 @@ impl Products {
};
}
pub fn filter_product_variant_ids<F>(&self, filter: F) -> Vec<ProductVariantId>
pub fn filter_product_ids<F>(&self, filter: F) -> Vec<DetailedProduct>
where
F: Fn(&model::api::v2::ProductVariant) -> bool,
F: Fn(&DetailedProduct) -> bool,
{
self.product_variant_ids
self.product_ids
.iter()
.filter_map(|id| {
self.product_variants
.get(id)
.filter(|&p| filter(p))
.map(|p| p.id)
})
.filter_map(|id| self.products.get(id).filter(|&p| filter(p)).map(|p| p.id))
.collect()
}
}