summaryrefslogtreecommitdiff
path: root/src/lib.rs
blob: 5990c979a1bdf9ff41673a8dc0a9d289a35cd77f (plain) (blame)
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
use std::cmp::Ordering;
use std::collections::HashSet;

// As an artist, I can add artwork and attach it to a product

// As an artist, I can enter detailed information about a product

// As an artist, I can store a product for later recall by me or connoisseurs.

// As a connoisseur, I can search the gallery for artwork matching given keywords and see products
// containing that artwork

// As a connoisseur, I can select one or many products and submit them in a job to an artist

// As an artist, I can select individual products to be featured, and rank first in default fetch lists

// As an artist, I can select individual products to be featured, and rank first in search results

// As an artist, I can select entire categories to be featured, and rank first in search results

// As an artist, I can select entire categories to be featured, and rank first in default fetch
// lists

// Sellable artwork, artowrk with a price attached to it. Prices are in cents to do comparisons to
// other products without fractions. Has a quantity to indicate stock. Can be
// featured in order to appear higher in connoisseur search results.
#[derive(Debug, Clone)]
struct Product {
    artwork: Artwork,
    cents: u64,
    quantity: u64,
    featured: bool,
}

impl PartialEq for Product {
    fn eq(&self, other: &Self) -> bool {
        self.cents == other.cents
    }
}

impl PartialOrd for Product {
    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
        self.cents.partial_cmp(&other.cents)
    }
}

impl Product {
    fn dollars(&self) -> f64 {
        self.cents as f64 / 100.0
    }
}

#[derive(Debug, Clone)]
struct Artwork {
    name: String,
    description: String,
    category: Vec<String>,
    tags: HashSet<String>,
}

struct Customer {}

trait Artist {
    fn create_art<G: Gallery>(gallery: G) -> Result<(), ()>;
}

struct Sort {
    highest_price: bool,
    lowest_price: bool,
    highest_quantity: bool,
    lowest_quantity: bool,
    atoz: bool,
    ztoa: bool,
    oldest: bool,
    newest: bool,
    featured: bool,
}

struct Filter {
    search_term: HashSet<String>,
    category: Vec<String>,
    sort: Sort,
}

trait Gallery {
    fn store(artwork: Artwork) -> Result<(), ()>;
    fn search(filter: Filter, sort: Sort) -> Result<(), ()>;
}

struct MockGallery {}

impl Gallery for MockGallery {
    fn store(_artwork: Artwork) -> Result<(), ()> {
        Ok(())
    }
    fn search(_search: Filter, _sort: Sort) -> Result<(), ()> {
        Ok(())
    }
}

struct Job {}

fn add_two(a: usize, b: usize) -> usize {
    a + b
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn add() {
        assert_eq!(4, add_two(2, 2));
    }

    #[test]
    fn dollars() {
        let product = Product {
            artwork: Artwork {
                tags: HashSet::new(),
                category: vec![],
                name: "".into(),
                description: "".into(),
            },
            cents: 1000,
            quantity: 0,
            featured: false,
        };
        assert_eq!(10.00, product.dollars());
        let product = Product {
            artwork: Artwork {
                tags: HashSet::new(),
                category: vec![],
                name: "".into(),
                description: "".into(),
            },
            cents: 1234,
            quantity: 0,
            featured: false,
        };
        assert_eq!(12.34, product.dollars());
    }

    #[test]
    fn price_check() {
        let artwork = Artwork {
            tags: HashSet::new(),
            category: vec![],
            name: "".into(),
            description: "".into(),
        };
        let product1 = Product {
            artwork: artwork.clone(),
            cents: 1000,
            quantity: 0,
            featured: false,
        };
        let mut product2 = Product {
            artwork,
            cents: 1000,
            quantity: 0,
            featured: false,
        };

        assert_eq!(product1, product2);
        product2.cents = 1234;
        assert_ne!(product1, product2);
        assert!(product1 < product2);
    }
}