1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//! Wishlist operations for managing customer wishlists
//!
//! # Example
//!
//! ```rust,ignore
//! use stateset_embedded::{Commerce, CreateWishlist, CustomerId};
//!
//! let commerce = Commerce::new("./store.db")?;
//!
//! let wishlist = commerce.wishlists().create(CreateWishlist {
//! customer_id: CustomerId::new(),
//! name: Some("Birthday Wishes".into()),
//! ..Default::default()
//! })?;
//!
//! println!("Wishlist created: {:?}", wishlist.name);
//! # Ok::<(), stateset_embedded::CommerceError>(())
//! ```
use stateset_core::{
AddWishlistItem, CreateWishlist, ProductId, Result, UpdateWishlist, Wishlist, WishlistFilter,
WishlistId, WishlistItem,
};
use stateset_db::Database;
use std::sync::Arc;
/// Wishlist operations for managing customer wishlists.
pub struct Wishlists {
db: Arc<dyn Database>,
}
impl std::fmt::Debug for Wishlists {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Wishlists").finish_non_exhaustive()
}
}
impl Wishlists {
pub(crate) fn new(db: Arc<dyn Database>) -> Self {
Self { db }
}
/// Create a new wishlist.
///
/// # Example
///
/// ```rust,ignore
/// use stateset_embedded::{Commerce, CreateWishlist, CustomerId};
///
/// let commerce = Commerce::new("./store.db")?;
///
/// let wishlist = commerce.wishlists().create(CreateWishlist {
/// customer_id: CustomerId::new(),
/// name: Some("Holiday Gift Ideas".into()),
/// ..Default::default()
/// })?;
/// # Ok::<(), stateset_embedded::CommerceError>(())
/// ```
pub fn create(&self, input: CreateWishlist) -> Result<Wishlist> {
self.db.wishlists().create(input)
}
/// Get a wishlist by ID.
pub fn get(&self, id: WishlistId) -> Result<Option<Wishlist>> {
self.db.wishlists().get(id)
}
/// Update wishlist metadata.
pub fn update(&self, id: WishlistId, input: UpdateWishlist) -> Result<Wishlist> {
self.db.wishlists().update(id, input)
}
/// List wishlists with optional filtering.
pub fn list(&self, filter: WishlistFilter) -> Result<Vec<Wishlist>> {
self.db.wishlists().list(filter)
}
/// Delete a wishlist and all its items.
pub fn delete(&self, id: WishlistId) -> Result<()> {
self.db.wishlists().delete(id)
}
/// Add an item to a wishlist.
pub fn add_item(&self, wishlist_id: WishlistId, item: AddWishlistItem) -> Result<WishlistItem> {
self.db.wishlists().add_item(wishlist_id, item)
}
/// Remove an item from a wishlist by product ID.
pub fn remove_item(&self, wishlist_id: WishlistId, product_id: ProductId) -> Result<()> {
self.db.wishlists().remove_item(wishlist_id, product_id)
}
}