Skip to content

Commit b6c9f05

Browse files
committed
Use cookie store
This lets us actually set the location of the store we want
1 parent 087cfd2 commit b6c9f05

File tree

5 files changed

+150
-23
lines changed

5 files changed

+150
-23
lines changed

ARCHITECTURE.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,33 @@ The countdown API requires an API key for all requests, which can be found in th
1111
Running a Postgres instance with the following tables:
1212

1313
```
14+
CREATE TYPE supermarket AS ENUM ('Countdown', 'New World');
15+
16+
countdown_stores
17+
----------------
18+
CREATE TABLE countdown_stores (
19+
id INTEGER PRIMARY KEY
20+
name VARCHAR(255) NOT NULL,
21+
)
22+
23+
stores
24+
----------------
25+
CREATE TABLE stores (
26+
id SERIAL PRIMARY KEY,
27+
supermarket supermarket NOT NULL,
28+
countdown_store_id INTEGER UNIQUE,
29+
30+
CONSTRAINT fk_countdown_id
31+
FOREIGN KEY(countdown_store_id)
32+
REFERENCES countdown_stores(id),
33+
34+
CONSTRAINT chk_supermarket_type
35+
CHECK (
36+
(supermarket = 'Countdown' AND countdown_store_id IS NOT NULL)
37+
-- in the future, we add an OR to this to check new world store id
38+
)
39+
)
40+
1441
countdown_products
1542
------------------
1643
CREATE TABLE countdown_products (
@@ -38,10 +65,14 @@ CREATE TABLE prices (
3865
product_id INTEGER NOT NULL,
3966
time TIMESTAMPTZ NOT NULL DEFAULT NOW(),
4067
cost_in_cents INTEGER NOT NULL,
41-
supermarket VARCHAR(255) NOT NULL,
68+
store_id INTEGER NOT NULL,
4269
4370
CONSTRAINT fk_product
4471
FOREIGN KEY(product_id)
4572
REFERENCES products(id)
73+
74+
CONSTRAINT fk_store_id
75+
FOREIGN KEY(store_id)
76+
REFERENCES stores(id)
4677
)
4778
```

Cargo.lock

Lines changed: 108 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@ name = "supermarket-tracker"
1414
path = "src/main.rs"
1515

1616
[dependencies]
17-
reqwest = { version = "0.11.22", default-features = false, features = [
18-
"gzip",
19-
"json",
20-
"native-tls",
21-
] }
17+
reqwest = { version = "0.11.22", default-features = false, features = ["gzip", "json", "native-tls", "cookies"] }
2218
serde = { version = "1.0.193", features = ["derive"] }
2319
serde_json = "1.0.108"
2420
tokio = { version = "1.34.0", features = ["full"] }

src/countdown/get_products.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -132,22 +132,14 @@ pub async fn get_products(
132132
price,
133133
sku,
134134
..
135-
} => {
136-
if &sku == "133211" {
137-
tracing::warn!(
138-
"Found {name} with price {} and barcode {barcode}",
139-
price.sale_price
140-
);
141-
}
142-
Some(Product {
143-
name,
144-
barcode,
145-
sku,
146-
// convert to cents from dollars
147-
#[allow(clippy::cast_possible_truncation)]
148-
per_unit_price: (price.sale_price * 100.0).round() as i32,
149-
})
150-
}
135+
} => Some(Product {
136+
name,
137+
barcode,
138+
sku,
139+
// convert to cents from dollars
140+
#[allow(clippy::cast_possible_truncation)]
141+
per_unit_price: (price.sale_price * 100.0).round() as i32,
142+
}),
151143
_ => None,
152144
})
153145
.collect::<HashSet<Product>>();

src/countdown/run.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pub async fn run(connection: PgPool, should_insert: bool) -> Result<(), Report<A
3939
reqwest::Client::builder()
4040
.user_agent(DEFAULT_USER_AGENT)
4141
.default_headers(default_headers)
42+
.cookie_store(true)
4243
.build()
4344
.change_context(ApplicationError::HttpError)
4445
}?;

0 commit comments

Comments
 (0)