Skip to content

Commit b3c218f

Browse files
authored
fix: use interface in logic, not concrete dal type (#607)
1 parent 2e83a7e commit b3c218f

File tree

3 files changed

+60
-58
lines changed

3 files changed

+60
-58
lines changed

poetry.lock

Lines changed: 51 additions & 48 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

service/dal/dynamo_dal_handler.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import uuid
2-
2+
from functools import lru_cache
33
import boto3
44
from botocore.exceptions import ClientError
55
from cachetools import TTLCache, cached
@@ -40,3 +40,8 @@ def create_order_in_db(self, customer_name: str, order_item_count: int) -> Order
4040

4141
logger.info('finished create order', extra={'order_id': order_id, 'order_item_count': order_item_count, 'customer_name': customer_name})
4242
return entry
43+
44+
45+
@lru_cache
46+
def get_dal_handler(table_name: str) -> DalHandler:
47+
return DynamoDalHandler(table_name)

service/logic/handle_create_request.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
1-
from functools import lru_cache
2-
3-
from service.dal.dynamo_dal_handler import DynamoDalHandler
1+
from service.dal.db_handler import DalHandler
2+
from service.dal.dynamo_dal_handler import get_dal_handler
43
from service.dal.schemas.db import OrderEntry
54
from service.handlers.schemas.dynamic_configuration import FeatureFlagsNames
65
from service.handlers.utils.dynamic_configuration import get_dynamic_configuration_store
76
from service.handlers.utils.observability import logger, tracer
87
from service.schemas.output import CreateOrderOutput
98

109

11-
@lru_cache
12-
def get_dynamodb_dal_handler(table_name: str) -> DynamoDalHandler:
13-
return DynamoDalHandler(table_name)
14-
15-
1610
@tracer.capture_method(capture_response=False)
1711
def handle_create_request(customer_name: str, order_item_count: int, table_name: str) -> CreateOrderOutput:
1812
logger.info('starting to handle create request', extra={'order_item_count': order_item_count, 'customer_name': customer_name})
@@ -31,7 +25,7 @@ def handle_create_request(customer_name: str, order_item_count: int, table_name:
3125
default=False,
3226
)
3327
logger.debug('premium feature flag value', extra={'premium': premium})
34-
dal_handler: DynamoDalHandler = get_dynamodb_dal_handler(table_name)
28+
dal_handler: DalHandler = get_dal_handler(table_name)
3529
order: OrderEntry = dal_handler.create_order_in_db(customer_name, order_item_count)
3630
# convert from db entry to output, they won't always be the same
3731
return CreateOrderOutput(customer_name=order.customer_name, order_item_count=order.order_item_count, order_id=order.order_id)

0 commit comments

Comments
 (0)