use serde::Serialize; #[derive(Serialize, Debug)] #[serde(transparent)] pub struct AccountOrders(pub Vec); impl From<(Vec, Vec)> for AccountOrders { fn from((orders, mut items): (Vec, Vec)) -> Self { Self( orders .into_iter() .map( |crate::AccountOrder { id, buyer_id, status, order_id, order_ext_id: _, service_order_id: _, }| { AccountOrder { id, buyer_id, status, order_id, items: items.drain_filter(|item| item.order_id == id).collect(), } }, ) .collect(), ) } } impl From<(crate::AccountOrder, Vec)> for AccountOrder { fn from( ( crate::AccountOrder { id, buyer_id, status, order_id, order_ext_id: _, service_order_id: _, }, mut items, ): (crate::AccountOrder, Vec), ) -> Self { AccountOrder { id, buyer_id, status, order_id, items: items.drain_filter(|item| item.order_id == id).collect(), } } } #[derive(Serialize, Debug)] pub struct AccountOrder { pub id: crate::AccountOrderId, pub buyer_id: crate::AccountId, pub status: crate::OrderStatus, pub order_id: Option, pub items: Vec, } #[derive(Serialize, Debug)] pub struct ShoppingCartItem { pub id: crate::ShoppingCartId, pub product_id: crate::ProductId, pub shopping_cart_id: crate::ShoppingCartId, pub quantity: crate::Quantity, pub quantity_unit: crate::QuantityUnit, } #[derive(Serialize, Debug)] pub struct ShoppingCart { pub id: crate::ShoppingCartId, pub buyer_id: crate::AccountId, pub payment_method: crate::PaymentMethod, pub state: crate::ShoppingCartState, pub items: Vec, } impl From<(crate::ShoppingCart, Vec)> for ShoppingCart { fn from( ( crate::ShoppingCart { id, buyer_id, payment_method, state, }, items, ): (crate::ShoppingCart, Vec), ) -> Self { Self { id, buyer_id, payment_method, state, items: items .into_iter() .map( |crate::ShoppingCartItem { id, product_id, shopping_cart_id, quantity, quantity_unit, }| ShoppingCartItem { id, product_id, shopping_cart_id, quantity, quantity_unit, }, ) .collect(), } } }