You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
📝 Add docstrings to feat/pricing-endpoint-cache (#617)
Docstrings generation was requested by @shayancoin.
* #616 (comment)
The following files were modified:
* `backend/api/deps.py`
* `backend/api/graphql.py`
* `backend/api/routes_pricing.py`
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Store a string value under the given key, optionally expiring after a number of seconds.
31
+
32
+
Parameters:
33
+
key (str): Key under which to store the value.
34
+
value (str): String value to store.
35
+
ex (Optional[int]): Expiration time in seconds; if provided, the key will be removed after this many seconds. Existing values for the key are overwritten.
36
+
"""
23
37
...
24
38
25
39
26
40
class_InMemoryRedis:
27
41
"""Minimal in-memory Redis replacement used when redis-py asyncio is unavailable."""
28
42
29
43
def__init__(self) ->None:
44
+
"""
45
+
Initialize internal storage for the in-memory Redis replacement.
46
+
47
+
Creates the `_store` dictionary that maps keys (str) to tuples of `(value, expires_at)`,
48
+
where `value` is the stored string and `expires_at` is a Unix timestamp (float) when the
Convert a backend PriceResponse into a GraphQL PriceQuote.
30
+
31
+
Constructs a PriceQuote with total_cents from the response and a nested PriceBreakdown populated from the response.breakdown keys: "base", "finish", "hardware", and "countertop".
32
+
33
+
Returns:
34
+
PriceQuote: GraphQL PriceQuote with mapped `total_cents` and `breakdown`.
35
+
"""
28
36
breakdown=response.breakdown
29
37
returnPriceQuote(
30
38
total_cents=response.total_cents,
@@ -47,6 +55,20 @@ async def price_quote(
47
55
hardware: str,
48
56
countertop: str,
49
57
) ->PriceQuote:
58
+
"""
59
+
Resolve a price quote for a product configuration specified by the provided attributes.
60
+
61
+
Builds a price request from the provided elevation, finish, hardware, and countertop identifiers, queries the pricing backend, and returns the result as a GraphQL PriceQuote.
62
+
63
+
Parameters:
64
+
elevation (str): Identifier for the product elevation/profile.
65
+
finish (str): Identifier for the surface finish option.
66
+
hardware (str): Identifier for the hardware option.
67
+
countertop (str): Identifier for the countertop option.
68
+
69
+
Returns:
70
+
PriceQuote: GraphQL representation of the computed price, including `total_cents` and a `breakdown` of cost components.
Compute a price quote for the given selection and use a short-lived micro-cache.
74
+
75
+
Attempts to return a cached PriceResponse keyed by the request fields. On cache read errors the function treats the cache as a miss; after computing the quote it will try to write the result to the cache but will ignore cache write failures so they do not affect the response.
76
+
77
+
Returns:
78
+
PriceResponse: The total price in cents and a breakdown of the component prices.
79
+
80
+
Raises:
81
+
HTTPException: 422 if any provided option (elevation, finish, hardware, or countertop) is not supported.
0 commit comments